我希望綁定到不是 eth0 的網路介面的程式在建立連接時使用其他預設閘道。
ip rule add oif tun0 table 11
ip route add default via 10.3.33.20 table 11
ip route flush cache
ip rule list
0: from all lookup local
32764: from all iif tun0 lookup 11
32765: from all oif tun0 lookup 11
32766: from all lookup main
32767: from all lookup default
ip route list table all
default via 10.3.33.20 dev tun0 table 11
default via 172.104.159.1 dev eth0 proto static metric 100
10.3.0.0/16 dev tun0 proto kernel scope link src 10.3.33.21
172.104.159.0/24 dev eth0 proto kernel scope link src 172.104.159.249 metric 100
...
當我將程式綁定到介面 tun0 時,它不會向網關 10.3.33.20 傳輸任何內容
答案1
作品:
ip rule add from <tun0-interface-ip> table 11
ip route add default via 10.3.33.20 table 11
ip route flush cache
由於某種原因不起作用:
ip rule add oif tun0 table 11
ip route add default via 10.3.33.20 table 11
ip route flush cache