The redirect-gateway
option may or may not change the gateway for reaching the OpenVPN server, depending on the flags provided to it.
According to man page of openvpn
:
Option flags:
local -- Add the local flag if both OpenVPN servers are directly connected via a common subnet, such as with wireless. The local flag will cause step 1 above (Creation of a static route for the --remote address which forwards to the pre-existing default gateway) to be omitted.
So, just add a redirect-gateway local
option in client config file, to override the pushed option. This will cause openvpn
to just add a new default route, and not a specific route for the server. So the current route being used to connect to ther server will continue to be used.
If you want this behavior for all clients, edit the server config file and change the option push "redirect-gateway"
to push "redirect-gateway local"
.
/sbin/route add -net [VPN_SERVER_IP] [OLD_DEFAULT_GATEWAY] 255.255.255.255
, right? so I need way to specify my own [OLD_DEFAULT_GATEWAY] value--redirect-gateway
without thedef1
flag (which preserves the old gateway), or write and run a script which has the same effect after the first VPN is brought up./sbin/route add -net [VPN_SERVER_IP] [OLD_GATEWAY_FOR_VPN_SERVER_IP] 255.255.255.255
. So, while connecting to second vpn, if the vpnserver2 is routed through first VPN, then the correct route will automatically be added by openvpn.