6

I want my ppp0 connection to have higher priority over wlan0. I added following lines to /etc/network/interfaces file.

iface wlan0 inet dhcp
    up ifmetric wlan0 20
----------------------------------------------------------------------------
#route table after modifying
$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.43.1    0.0.0.0         UG    20     0        0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U     20     0        0 wlan0
192.168.43.0    0.0.0.0         255.255.255.0   U     20     0        0 wlan0
220.224.141.145 0.0.0.0         255.255.255.255 UH    0      0        0 ppp0

As you can see, metric of wlan0 changed to 20, but still it is preferred over ppp0 as default gateway. When i checked man page of route, it was mentioned "metric was not used by recent kernels".

I can change the route manually by deleting the unwanted gw and adding ppp0 as gw. But when wlan0 disconnects and reconnects, the routing table changed to default. How could i set my ppp0 as default gw permanently?

Kumar
  • 307

1 Answers1

4

You have several possibility to change the default route.

Nice place for this kind of action is in /etc/network/if-down.d/ or /etc/network/if-up.d/

You can in this folder put some script and make action. For example put this 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

In second case wifi reconnect, make one more script aka script2

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

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

This will if wlan0 go up set default route to ppp0, if is ppp0 down route will not be changed from wlan0.

Try.

Edit 1

Based on internet research, for ppp0 interface you move script in /etc/ppp/if-up.d

2707974
  • 10,758