1
2
3
4
5
6
iptables -t mangle -N DIVERT
iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT
iptables -t mangle -A DIVERT -j MARK --set-mark 1
iptables -t mangle -A DIVERT -j ACCEPT
ip rule add fwmark 1 lookup 100
ip route add local 0.0.0.0/0 dev lo table 100
但是,由于我们的流量来自本地主机,并且可以通过源地址轻松识别,因此我们可以放弃整个iptables匹配和基于标记的路由规则,将其替换为基于源的简单路由规则。
1
2
ip rule add from 192.168.127.0/24 lookup 100
ip route add local 0.0.0.0/0 dev lo table 100
debian系可以用以下持久化方法
1
2
3
4
5
6
iface lo:10 inet static
address 192.168.127.40
netmask 255.255.255.0
network 192.168.127.0
up ip rule add from 192.168.127.0/24 lookup 100 #新增这两条1
up ip route add local 0.0.0.0/0 dev lo table 100 #新增这两条2
然后可以nginx/trojan服务器行以连接到在此新地址范围上侦听的本地服务。
必须注意将环回接口用于透明代理连接,否则数据包将无法传递。 这是通过使用新的本地地址做为监听地址而不是*或者0.0.0.0来完成的。