Linux – Openvpn problems with route-nopull

linuxopenvpnroutingvpn

here is the situation,I have:

  • vps with public ip
  • vpn service
  • own router with public ip

if i connect vpn (interface name tunVPN) without route-nopull vps drops all connections (like ssh) sice it has new default gateway through vpn provider. if i use route-nopull on connection it connects but just sits there, i cannot use it (for example if i try to ping -I tunVPN xxx.xxx or bind some service to it).

So my question is what route should i add to make this vpn work.

i've even tried to use openvpn 2.4 with pool-filter but its no good.

here is route wihit route-nopull:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 eth0
10.114.0.0      0.0.0.0         255.255.0.0     U     0      0        0 tunvpn
62.x.x.0        0.0.0.0         255.255.255.0   U     100    0        0 eth0  
62.x.x.254      gateway         255.255.255.255 UGH   100    0        0 eth0

same without route-nopull

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.114.0.1      128.0.0.0       UG    0      0        0 tunvpn
default         gateway         0.0.0.0         UG    100    0        0 eth0
10.114.0.0      0.0.0.0         255.255.0.0     U     0      0        0 tunvpn
62.x.x.0        0.0.0.0         255.255.255.0   U     100    0        0 eth0
62.x.x.254      gateway         255.255.255.255 UGH   100    0        0 eth0
128.0.0.0       10.114.0.1      128.0.0.1       UG    0      0        0 tunvpn
185.x.x.68      gateway         255.255.255.255 UGH   0      0        0 eth0

Any sugestions? I dont want to use vpn for all the traffic just for some 🙂

Best Answer

After some time i managed to work it out: two routing tables

add to /etc/iproute2/rt_tables

# reserved values
#
255 local
254 main
253 default
0   unspec
#
# local
#
#1  inr.ruhep
1 rt2 

then configure rt2 (routing table 2) through up.sh script invoked by openvpn on connection

/usr/sbin/ip route add 0.0.0.0/0  dev tunvpn src $VPNADDR table rt2
/usr/sbin/ip rule add from $VPNADDR table rt2
/usr/sbin/ip rule add to $VPNADDR table rt2

where $VPNADDR is ip from vpn server usually $4 is enough.

Hope this will help.