changing the priority of network interface
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
Related videos on Youtube
Kumar
Updated on September 18, 2022Comments
-
Kumar almost 2 years
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?
-
2707974 about 9 yearsadding
ppp0
asgw
with commandroute add default dev ppp0
or on some different way? -
Kumar about 9 yearsbut it will change if wlan0 reconnects, or when you boot the system.
-
-
Kumar about 9 yearswhat does [ "$IFACE" != "ppp0" ] || exit 0 this line represent?
-
2707974 about 9 yearscompare
ifup
andifdown
action against interface. If is script inif-up.d
, checkifup
action that belongsppp0
interface and go to command. -
Kumar about 9 yearsScripts 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 about 9 yearsI am using wvdial to start the pppd.
-
2707974 about 9 yearsPelase, give me output from command
ifconfig
whenwvdial
is connected. -
Kumar about 9 yearsppp0 Link encap:Point-to-Point Protocol inet addr:115.241.58.163 P-t-P:220.224.141.145 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:106 errors:0 dropped:0 overruns:0 frame:0 TX packets:108 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:3 RX bytes:26594 (26.5 KB) TX bytes:19725 (19.7 KB)
-
2707974 about 9 yearsName on the interface is
ppp0
script should be work. Script will be executed only when interface change state, in this case, from down to up. -
Kumar about 9 yearsCouldn't get you. Interface changes stated from down to up, when we disconnect and connect again. I am doing that, but still the script is not executing.
-
2707974 about 9 yearsAre you set permision?
chmod 755 /etc/network/if-up.d/script
-
Kumar about 9 yearsyes. The output of ls -l. -rwxr-xr-x 1 root root 45 May 22 16:21 test. By the way, script name is test
-
Kumar about 9 yearsI asked a question on this. askubuntu.com/questions/626953/…
-
2707974 about 9 yearsIf you have usb modem try to change
ppp0
withusb0