I need to start multiple vpnc tunnels and define a different static route for each of individually after setup.
To do so I created a script that will run after each connection (tunX) goes up.
However if one or more tunnels goes down and I need to restart those particular connection I’ll lose the correct attribution order for each client and my script won’t work as intended, effectively locking me out of the box.
Example: I need to delete and add the following routes for client_b in tun1 because injected routes override my internal networks.
ip route del 0.0.0.0/0 dev tun1 # this route must be deleted because it overrides my GW. ip route del 192.168.0.0/16 dev tun1 # this route must be deleted because it overrides internal net. ip route add 192.168.88.0/24 via 18.104.22.168 dev tun1 # Manually added subnet that I need to have access to ip route add 0.0.0.0/0 via 192.168.40.1 dev eth0 # My internal network is 192.168.40.0/24
As such, whenever I start a new vpnc connection I’ll get a tunnel number starting with tun0, then tun1, tun2 and so on.
If however one tunnel goes down and I need to restart it, I’ll get a tunX where X is not in order anymore.
Example: Initially when I connect these clients sequentially I’ll get a sequential tunX number for each client.
sudo vpnc client_a --local-port 0 # It will be available on tun0 sudo vpnc client_b --local-port 0 # It will be available on tun1 sudo vpnc client_c --local-port 0 # It will be available on tun2 sudo vpnc client_d --local-port 0 # It will be available on tun3
Please note: I need to delete undesired routes in each tunnel and define personalized routes for each one individually because each one has its own route and corresponding endpoint.
Killing all connections at once and start them all sequentially is not an option.
So my question is: How can I statically define client_a to always make use tun0, client_b to always use tun1 and so on?