0

I would like for a program that binded to network interface that is not eth0 to use other default gateway when making connections.

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
...

When I bind program to interface tun0 it does not transmit antything to gateway 10.3.33.20

3
  • 1
    If the application is bound to specific if, then hopefully you can have a IP rule on the source IP. ip rule add from $ip table 11
    – NiKiZe
    Aug 8, 2021 at 14:09
  • Thanks. Yes, ip rule add from <tun0-interface-ip> table 11 works while ip rule add oif tun0 table 11 for some reason wont.
    – ndd
    Aug 8, 2021 at 14:39
  • If I remember correctly, interface has not yet been determined, it is only decided after routing, oif probably works on things like modifying src ip in the route.
    – NiKiZe
    Aug 8, 2021 at 15:00

1 Answer 1

0

works:

ip rule add from <tun0-interface-ip> table 11 
ip route add default via 10.3.33.20 table 11
ip route flush cache

for some reason won't work:

ip rule add oif tun0 table 11
ip route add default via 10.3.33.20 table 11
ip route flush cache

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .