Openvpn – How to automatically add a local route after OpenVPN start

openvpn

I have a container which routes all its traffic via OpenVPN. This is done by OpenVPN via a combo of

0.0.0.0/1 via 10.8.8.17 dev tun0 
128.0.0.0/1 via 10.8.8.17 dev tun0 

which masks the default route (which is still there when OpenVPN shuts down)

I need to explicitly add a route for a local network which would direct packets via eth0 and not tun0.

This is manually done via

ip route add 10.10.10.0/24 via 10.10.11.254 dev eth0

after OpenVPN has started.

How can I do that automatically upon OpenVPN start?

I tried to add

route 10.10.10.0 255.255.255.0

to mu .ovpn config file, but this leads to a new route via tun0 (which is quite understandable as there was no specific information about the NIC to route through – but I did not see anything available in the doc either)

# ip route
(...)
10.10.10.0/24 via 10.8.8.17 dev tun0 

Is what I want to achieve doable though OpenVPN configuration or do I need to do it somehow outside the OpenVPN startup process?

Best Answer

If it is a locally reachable network, then you can just have a persistent local route to it irrespective of openvpn and should work as expected. Depending on your system, you can configure the route so that it will be loaded when the relevant interface is up.