How to add route to local network in Linux even if VPN is active
If you route all your traffic via a VPN on Linux, you will typically not be able to access local networks except for the network which you are directly connected to via L2.
In order to fix this, you can simply add a route, which typically takes precedence over the VPN route even with additional options.
The following example will add a route to 10.1.2.0/24
(local network) via the gateway=local router we’re connected via L2 to (192.168.1.1
)
sudo ip route add 10.1.2.0/24 via 192.168.1.1