openvpn client override default gateway for vpn sever

When openvpn client connects to a vpn server it creates a route for server ip with old default gateway. How can I tell openvpn not to use old default gateway but use my provided custom gateway ip.

I.e. when I have vpn server in another vpn network which is not default route on my machine.


Solution 1:

I also don't want the first VPN to be default gateway. I just need it only for certain subnet.

On the client side you can ignore any routes from vpn server with the following options

script-security 2
route-noexec
route-up setup-routing.sh

and configure your own routes with route-up script, that could be something like this

$ cat setup-routing.sh 

#!/bin/bash

ip ro add 192.168.10.0/24 via ${route_vpn_gateway}

Where route_vpn_gateway is environment variable that points to the default gateway used by --route options, as specified in either the --route-gateway option or the second parameter to --ifconfig when --dev tun is specified.