Ubuntu – How to route all traffic through OpenVPN using Network Manager

15.04network-manageropenvpn

I can successfully connect to my OpenVPN server from command line using openvpn --config client.conf. The client.conf file contains redirec-gateway directive to route all traffic through the VPN server. All this works fine.

Now, how can I achieve the same result with Network Manager and nm-applet?

I tried simply configuring the connection. It initializes correctly but doesn't route the traffic through the server. It's as if I ticked "Use this connection only for resources on its network" when I didn't.

It seems that when I connect from the command line, the VPN route is added at the top

# ip route show
default via 192.168.10.5 dev tun0 
default via 192.168.1.1 dev eth0  proto static  metric 1024 

but it's added as second when connecting from the applet

# ip route show
default via 192.168.1.1 dev eth0 
default via 192.168.10.5 dev tun0  proto static  metric 1024 

This is on Ubuntu 15.04 Vivid and OpenVPN 2.3.2.

Best Answer

I don't known how to set this option in NM but you can add script in /etc/ppp/if-up.d/ to make default route to ppp0 interface every time when go up. Make script called script with execute permissions 755

sudo nano /etc/ppp/if-up.d/script

# Check for specific interface if desired
[ "$IFACE" != "ppp0" ] || exit 0
# Do something
sudo route add default dev ppp0


chmod 755 /etc/ppp/if-up.d/script

Try

Edit 1

If you have tun0 interface then place script in /etc/network/if-up.d/ and change interface name

sudo nano /etc/network/if-up.d/script

# Check for specific interface if desired
[ "$IFACE" != "tun0" ] || exit 0
# Do something
sudo route add default dev tun0


chmod 755 /etc/network/if-up.d/script