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?

2
  • adding ppp0as gw with command route add default dev ppp0 or on some different way?
    – 2707974
    May 22, 2015 at 8:57
  • but it will change if wlan0 reconnects, or when you boot the system.
    – Kumar
    May 22, 2015 at 9:00

1 Answer 1

3

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

12
  • what does [ "$IFACE" != "ppp0" ] || exit 0 this line represent?
    – Kumar
    May 22, 2015 at 10:11
  • compare ifup and ifdown action against interface. If is script in if-up.d, check ifup action that belongs ppp0 interface and go to command.
    – 2707974
    May 22, 2015 at 10:25
  • Scripts in if-up.d are not executing when ppp0 is up. I tried with sample shell with only this command "sudo touch /home/user/test.txt". No file is created for ppp0 (the script is not executing). But for wlan it is working
    – Kumar
    May 22, 2015 at 10:40
  • I am using wvdial to start the pppd.
    – Kumar
    May 22, 2015 at 10:42
  • Pelase, give me output from command ifconfig when wvdial is connected.
    – 2707974
    May 22, 2015 at 10:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .