Linux – Routing tun0 traffic through tun1 (double-hop VPN)

linuxroutingtunnelingvpn

Goal: route all internet traffic from eth0 -> tun0 -> tun1 for double-hop VPN. Is the following routing table correct for that goal?

$ ip route show:

0.0.0.0/1 via 10.8.1.1 dev tun1 
default via 10.8.3.1 dev tun0 proto static metric 50 
10.8.1.0/24 dev tun1 proto kernel scope link src 10.8.1.6 
10.8.3.0/24 dev tun0 proto kernel scope link src 10.8.3.4 metric 50 
101.133.213.73 via 10.8.3.1 dev tun0 
127.0.0.0/8 dev lo scope link 
128.0.0.0/1 via 10.8.1.1 dev tun1 
191.72.65.45 via 182.160.0.1 dev eth0 proto static metric 100 
182.160.0.0/24 dev eth0 proto kernel scope link src 182.160.0.19 metric 100 
182.160.0.0/24 dev eth0 proto dhcp scope link src 182.160.0.19 metric 208 
182.160.0.1 dev eth0 proto static scope link metric 100

Best Answer

eth0 : 182.160.0.19/24 (GW: 182.160.0.1)
tun0 : 10.8.3.4/24 (GW: 10.8.3.1 / VPN endpoint : 191.72.65.45 via eth0)
tun1 : 10.8.1.6/24 (GW: 10.8.1.1 / VPN endpoint : 101.133.213.73 via tun0)

This way all traffic (including incomming from tun0) will be routed via tun1 except local traffic on ethernet (182.160.0.0/24) and local traffic on tun0 / "VPN1" (10.8.3.0/24).

With this routing table also all traffic comming from eth0 will be routed via tun1 which is not mentioned / requested in the question... Is this situation OK for you? In case the answer is yes then you can keep this setting.

In case this is not willing situation (you don't want to route traffic from eth0 to tun1 / tun0) you have (at least) two options how to deal it.

  • "custom" routing table

There can be more than just one routing table and based on the rule / policy you can manage which traffic would be handled by the other than default one. This way you can set custom routing table where the default GW would be tun1 and only traffic comming from tun0 would be pointed to this custom routing table.

  • Network namespace

This way you can isolate whole tun interfaces from eth0 (with internal routing between namespaces) so you can have simple (default) routing table set up in the namespace so only traffic from tun0 can reach tun1.

Related Topic