Reputation: 643
I have the following system:
Linux <HOSTNAME> 5.4.24-<SPECIFIC_BUILD> #1 SMP PREEMPT [...] aarch64 GNU/Linux
I have configured an access point network on network device wlan0
, while ppp0
is handled by wvdial
cellular connection service. The latter device is not configured in /etc/network/interfaces
, therefore I cannot modify its metric there.
This is my kernel IP routing table:
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ppp0
10.64.64.64 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
192.168.0.0 0.0.0.0 255.255.255.0 U 40 0 0 wlan0
I want it to be like
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 0.0.0.0 0.0.0.0 U 20 0 0 ppp0
10.64.64.64 0.0.0.0 255.255.255.255 UH 20 0 0 ppp0
192.168.0.0 0.0.0.0 255.255.255.0 U 40 0 0 wlan0
namely, the ppp0
metric must be 20
. I am able to edit it manually:
sudo route del -net 0.0.0.0 gw 0.0.0.0 netmask 0.0.0.0 dev ppp0
sudo route del -net 10.64.64.64 gw 0.0.0.0 netmask 255.255.255.255 dev ppp0
sudo route add -net 0.0.0.0 netmask 0.0.0.0 metric 20 dev ppp0
sudo route add -net 10.64.64.64 netmask 255.255.255.255 metric 20 dev ppp0
problem is that this configuration does not persist and it is deleted with reboot.
How can I fix that?
Upvotes: 0
Views: 936
Reputation: 2880
Preventing them from being deleted on reboot is likely the wrong way to phrase/approach this. It is very much standard behaviour to start with a fresh empty routing table on boot, and (re)create the routes (as per configuration) as the devices are being initialised.
I'm not very familiar with the software involved, however it looks like wvdial is a wrapper around pppd, and pppd according to its manpage calls the following shell script after making the connection:
> /etc/ppp/ip-up <interface-name> <tty-device> <speed> <local-IP-address>
So i suspect you could plug your manual route commands in there and be done. (You can leave out the sudo, since pppd runs the scripts as root anyway).
Perhaps something like:
#!/bin/sh
if test "$1" = 'ppp0' ; then
route del -net 0.0.0.0 gw 0.0.0.0 netmask 0.0.0.0 dev ppp0 ;
route del -net 10.64.64.64 gw 0.0.0.0 netmask 255.255.255.255 dev ppp0 ;
route add -net 0.0.0.0 netmask 0.0.0.0 metric 20 dev ppp0 ;
route add -net 10.64.64.64 netmask 255.255.255.255 metric 20 dev ppp0 ;
fi;
Upvotes: 1