I am trying to figure out how linuxMint (and probably others) achieve routing tun1 traffic through tun0 when new instance of openvpn is created. So far i hit a brick wall. Maybe someone with more knowledge would find this easy enough and could point me to the right direction?
Main question i sided with is this: how i could make second instance of openvpn do
ip route add openvpn_server_ip via tun0_gateway instead of
ip route add openvpn_server_ip via eth0_gateway?
Now goes the details:
The way it works on linuxMInt (and friends):
1. Connect tun0 via network manager that spawns openvpn instance with following command line (parameters are obtained by importing pretty standard config_for_tun0.ovpn):
openvpn --remote myvpnserver.net --comp-lzo --nobind --dev tun --proto udp --port 2049 --cipher AES-256-CBC --auth-nocache --tls-auth /home/user/openvpn/ta.key 1 --syslog nm-openvpn --script-security 2 --up /usr/lib/NetworkManager/nm-openvpn-service-openvpn-helper --up-restart --persist-key --persist-tun --management 127.0.0.1 1194 --management-query-passwords --route-noexec --ifconfig-noexec --client --ca /home/user/openvpn/ca.crt --cert /home/user/openvpn/client1.crt --key /home/user/openvpn/client1.key --auth-user-pass
2. Run openvpn instance from terminal with pretty standard config:
openvpn --config config_for_tun1.ovpn
Result it yelds is this:
ROUTE_GATEWAY [b]10.9.0.89[/b]
TUN/TAP device tun1 opened
TUN/TAP TX queue length set to 100
do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
/sbin/ip link set dev tun1 up mtu 1500
/sbin/ip addr add dev tun1 local 10.15.0.70 peer 10.15.0.69
/sbin/ip route add 114.205.50.66/32 via 10.9.0.89
10.9.0.89 being gateway of tun0 and 114.205.50.66 being ip of second openvpn server.
Now traffic is routed like this: localhost -> tun0 -> tun1-> internet
I want to replicate that, however if i run two openvpn instances in terminal both of them yield this:
ROUTE_GATEWAY 192.168.0.1/255.255.255.0 IFACE=eth0
TUN/TAP device tun1 opened
TUN/TAP TX queue length set to 100
do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
/sbin/ip link set dev tun1 up mtu 1500
/sbin/ip addr add dev tun1 local 10.15.0.58 peer 10.15.0.57
/sbin/ip route add 114.205.50.66/32 via 192.168.0.1
They both get routed through eth0 - main connection (192.168.0.1 is default gw of eth0).
It is not entirely clear to me how this kind of behavior could be achieved. I tried to experiment with --route and --route-gateway params but they just yelded errors when adding routes and not much else.