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.
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 toppp0
interface every time when go up. Make script called script with executepermissions 755
sudo nano /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 namesudo nano /etc/network/if-up.d/script
I've had the same problem on Ubuntu 15.04 and this solution works for me:
sudo service network-manager restart
)Get the name of the iface used as the default gateway.
> route Destination Gateway Genmask Flags Metric Ref Use Iface default fritz.box 0.0.0.0 UG 0 0 0 enp60s0
Find out the uid for this interface and the uid for your vpn connection
> nmcli c NAME UID TYPE DEVICE ..... Wired conne....3d7cfc99-dd28-45c1-87d8-5ec88b0b687c 802-3-ethernet enp60s0 VPN France 2c5131c6-3d8e-4768-a67e-cbcc4f35db1f vpn -- .....
Set the metric for current default interface to e.g. 2 and for the vpn device to 0
sudo nmcli connection modify uuid 3d7cfc99-dd28-45c1-87d8-5ec88b0b687c ipv4.route-metric 2 sudo nmcli connection modify uuid 2c5131c6-3d8e-4768-a67e-cbcc4f35db1f ipv4.route-metric 0
> route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default VPN-Gateway 0.0.0.0 UG 0 0 0 tun0 default 192.168.220.1 0.0.0.0 UG 2 0 0 enp60s0