- Mac as LAN device, connectted to network 10.13.1.0/24, gateway 10.13.1.1.
- Run:
sudo route add -host proxy-node-ip 10.13.1.1
to avoid routing loop.
- Run:
- Ubuntu VM runs in VMWare Fusion as gateway(running clash).
- Bridge interface as default gateway for vm.
- An NAT devices with subnet
192.168.107.0/24
to connect Host(Mac).Assign192.168.107.128
to vm.
- Install clash binary to
/usr/local/bin/clash
. - Run
useradd -M clash
- Run
sudo setcap CAP_NET_ADMIN,CAP_NET_BIND_SERVICE+eip /usr/local/bin/clash
. - Save config.yaml to
/usr/local/etc/clash/config.yaml
, change proxy nodes, rules to your own config.- allow-lan should be set to
true
. - redir-port, dns.listen port should be same as in iptables.
- change
log-level
to info/warning after testing.
- allow-lan should be set to
- Save clash.service to
/etc/systemd/system/clash.service
. - Run
systemctl daemon-reload
systemctl start clash
to start clash. - Run
journalctl -u clash -f
to view log.
Assume enp0s1
is the network interface which the gateway ip address(e.g.: 192.168.107.128) for other devices is assigned to.
Run:
sysctl -w net.ipv4.conf.enp0s1.forwarding=1
sysctl -w net.ipv4.ip_forward=1
- In new terminal panel, save rules.v4 to
/etc/iptables/rules.v4
. - Change
192.168.107.0/24
to your subnet. - Change
--uid-owner 1001
to--uid-owner {{ the actual uid of user clash }}
- Run
iptables-restore < /etc/iptables.v4
.
Run dig www.baidu.com @114.114.114.114
, should return 198.18.x.x
due to fake-ip
mode enabled.
Run curl www.google.com -v > /dev/null
, should return 200 ok.
Set gateway to 192.168.107.128
(as example above), and rerun the commands.
- No UDP packets other than DNS queries to dst port 53 would be proxied.
- No EDNS-Client-Subnet support.
In my experience, with clash 1.10,
setcap CAP_NET_ADMIN,CAP_NET_BIND_SERVICE+eip
will result in "All DNS requests failed" due to "operation not permitted".Replace it with
setcap CAP_NET_RAW,CAP_NET_BIND_SERVICE+ep
fixed the problem.