I have two internet connections. Default eth0 and a vpn tunnel on tun0.

my ip show route shows:

default via 149.202.xxx.xxx dev eth0 dev tun0  proto kernel  scope link  src
149.202.xxx.0/24 dev eth0  proto kernel  scope link  src 149.202.xxx.yy

Gateway for tun0 is although I dont want to set it up as default. What I would like to do is for example use ping -I tun0, or curl --interface tun0 http://somewebsite.com and in this particular situation I would like to use tun0 as my outgoing connection.

Is it possible?


This is what worked for me:

echo "10 vpn" >> /etc/iproute2/rt_tables
ip route add default via dev tun0 table vpn
ip rule add from table vpn
ip rule add to table vpn
ip route flush cache

And proof:

$ curl ifconfig.co

$ curl --interface tun0 ifconfig.co

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.