다른 네트워크 인터페이스에 바인딩된 프로그램이 기본값이 아닌 다른 게이트웨이를 사용하도록 합니다.

다른 네트워크 인터페이스에 바인딩된 프로그램이 기본값이 아닌 다른 게이트웨이를 사용하도록 합니다.

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

관련 정보