You can add default gateway with command
by the ip address
sudo ip route add default via xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
- represent ip of vpn server
or by interface
sudo ip route add default dev ppp0
This can be done manually from terminal when you are connected to vpn.
Second solution is to make script to chance default gw when vpn is connected
Then create script witch will be executed when interface ppp0
go up.
Create script for ppp0
interface
sudo nano /etc/ppp/if-up.d/script
put in script this
# Check for specific interface if desired
[ "$IFACE" != "ppp0" ] || exit 0
# trigger vpn connection
ip route add default dev ppp0
Save and exit.
Make script called script
with execute permissions 755
sudo chmod 755 /etc/network/if-up.d/script
Explanation
When vpn
connection will established and ppp0
interface is up script will run and set default device to ppp0
Also you can manually add route to resource on vpn
site
sudo ip route add xxx.xxx.xxx.xxx/yy dev ppp0
xxx.xxx.xxx.xxx
- represent host/network
yy
- represent network mask
example:
add route to host 10.35.5.181
trough ppp0
sudo ip route add 10.35.5.181/32 dev ppp0
add route to network range 10.35.5.0
with mask 255.255.255.0
trough ppp0
sudo ip route add 10.35.5.0/24 dev ppp0
This also can be done in Network Manager
. On same places where is use this connection only for resources on its network
you can add route.
You can modify the gateway for network manager connections from the command line. So while I cannot find this option in the GUI, you can list the connections
nmcli con show
find yours
NAME UUID TYPE DEVICE
thenameyougaveit some-id-ksadbf019-aksb821 vpn wlan1
change the address (it will be discarded afaict but you cannot change the gateway address without setting it)
nmcli con mod some-id-ksadbf019-aksb821 ipv4.addresses 192.168.1.113/24
and then set the desired ip4 gateway
nmcli con mod some-id-ksadbf019-aksb821 ipv4.gateway 192.168.1.1
And now it works from the GUI. Of course, if anything changes on the other end, it will stop working.
Best Answer
You can use the
ip
command for setting up routes. You basically need to remove your default route. At make sure you have a route entry into your local network.