How to make wlan to always be the default route? (ip route list)












8















Whenever I add my 4G modem to my raspberry, it gets on top of the default routes ou ip route list, however I want everything to go through wlan, and only use the 4G modem to receive SSH connections.



I've found this answer on how to disable the default routes.



however, after reboot, the 4G modem comes back to the top.



How do I make wlan0 to always be the first rule on default?



UPDATE:



Here's the dmesg output when I connect the USB dongle:



[426102.910168] usb 1-1.5.1: new full-speed USB device number 6 using dwc_otg
[426103.046670] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426103.056674] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[426103.056693] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[426103.056704] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426103.056714] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426103.056724] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[426103.121355] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[426103.122875] scsi host0: usb-storage 1-1.5.1:1.0
[426103.987177] usb 1-1.5.1: USB disconnect, device number 6
[426105.470211] usb 1-1.5.1: new full-speed USB device number 7 using dwc_otg
[426105.606666] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426105.615673] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[426105.615692] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[426105.615703] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426105.615713] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426105.766297] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[426105.766768] scsi host0: usb-storage 1-1.5.1:1.2
[426105.855053] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[426105.855593] usbcore: registered new interface driver cdc_ether
[426106.785653] scsi 0:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[426106.803758] sd 0:0:0:0: Attached scsi generic sg0 type 0
[426106.820687] sd 0:0:0:0: [sda] Attached SCSI removable disk


Here's ip addr



eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 0c:5b:8f:27:9a:64 brd ff:ff:ff:ff:ff:ff
inet6 fe80::584f:751f:bb3e:e26b/64 scope link
valid_lft forever preferred_lft forever


UPDATE 2



I attached it a few more times until it showed the eth1 route:



[10787.229141] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
[10787.363515] usb 1-1.5: New USB device found, idVendor=05e3, idProduct=0606
[10787.363533] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10787.363544] usb 1-1.5: Product: USB Hub 2.0
[10787.363555] usb 1-1.5: Manufacturer: ALCOR
[10787.365166] hub 1-1.5:1.0: USB hub found
[10787.369831] hub 1-1.5:1.0: 4 ports detected
[10797.419094] usb 1-1.5.1: new full-speed USB device number 8 using dwc_otg
[10797.555636] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10797.565759] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[10797.565777] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[10797.565789] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10797.565799] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10797.565808] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[10797.630477] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[10797.631101] scsi host0: usb-storage 1-1.5.1:1.0
[10798.472745] usb 1-1.5.1: USB disconnect, device number 8
[10799.469081] usb 1-1.5.1: new full-speed USB device number 9 using dwc_otg
[10799.630768] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10799.646891] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[10799.646909] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10799.646920] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10799.646930] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10799.814489] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[10799.815008] scsi host0: usb-storage 1-1.5.1:1.2
[10799.897788] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[10799.898127] usbcore: registered new interface driver cdc_ether
[10800.889652] scsi 0:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[10800.910585] sd 0:0:0:0: Attached scsi generic sg0 type 0
[10800.923297] sd 0:0:0:0: [sda] Attached SCSI removable disk


Here's route -n



Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
0.0.0.0 192.168.8.1 0.0.0.0 UG 207 0 0 eth1
0.0.0.0 192.168.1.1 0.0.0.0 UG 303 0 0 wlan0
169.254.0.0 0.0.0.0 255.255.0.0 U 202 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 204 0 0 docker0
169.254.0.0 0.0.0.0 255.255.0.0 U 206 0 0 veth4557ad2
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.8.0 0.0.0.0 255.255.255.0 U 207 0 0 eth1


See that I did ifmetric wlan0 in order to be able to use the wlan0 to ssh into my raspberry



UPDATE 09/10:



allow-hotplug wlan0
iface wlan0 inet dhcp
up ifmetric wlan0 0
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


This won't make my wlan0 have metric 0. What am I doing wrong?










share|improve this question




















  • 1





    First step is to find out why the 4G modem gets a default route. Does it do DHCP? If yes, figure out what calls it (network manager? traditional ifup/ifdown?), and configure dhclient etc. in that call to not set the default route for that particular interface.

    – dirkt
    Jul 5 '18 at 5:49











  • @dirkt it's a USB dongle, so when it is connected it gets a new interface by default. There's no rule for eth1 on /etc/network/interfaces, however this is the ethernet device assigned to it. Do you know why? I don't know if it does DHCP, the interface is pretty simple, there's no advanced things to change or look. It's a huawei modem. Could you give soe help?

    – Guerlando OCs
    Jul 5 '18 at 13:41






  • 1





    Please edit the question with the output of dmesg and syslog (use journalctl if you have systemd) after you plug in the USB dongle (indent 4 spaces for proper formatting on stackoverflow).

    – dirkt
    Jul 5 '18 at 14:13











  • @dirkt I'll post the dmesg soon when I get somebody to plug the 4G modem for me. In the meantime, how do I find which thing is giving an IP address for my router? I'm using raspbian which is debian based so do you have an idea?

    – Guerlando OCs
    Jul 16 '18 at 21:45











  • In general, you'll get IP addresses via DHCP, usually by calling dhclient, or, if the modem uses a point-to-point protocol, from this protocol. All that should be shown somewhere in the logs, which is why I was asking for the logs. If you don't have physical access to the RaspPi (you didn't mention this), ip link or ip addr should also show if it's a point-to-point protocol or not (possibly you need verbose mode).

    – dirkt
    Jul 17 '18 at 5:43
















8















Whenever I add my 4G modem to my raspberry, it gets on top of the default routes ou ip route list, however I want everything to go through wlan, and only use the 4G modem to receive SSH connections.



I've found this answer on how to disable the default routes.



however, after reboot, the 4G modem comes back to the top.



How do I make wlan0 to always be the first rule on default?



UPDATE:



Here's the dmesg output when I connect the USB dongle:



[426102.910168] usb 1-1.5.1: new full-speed USB device number 6 using dwc_otg
[426103.046670] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426103.056674] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[426103.056693] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[426103.056704] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426103.056714] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426103.056724] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[426103.121355] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[426103.122875] scsi host0: usb-storage 1-1.5.1:1.0
[426103.987177] usb 1-1.5.1: USB disconnect, device number 6
[426105.470211] usb 1-1.5.1: new full-speed USB device number 7 using dwc_otg
[426105.606666] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426105.615673] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[426105.615692] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[426105.615703] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426105.615713] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426105.766297] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[426105.766768] scsi host0: usb-storage 1-1.5.1:1.2
[426105.855053] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[426105.855593] usbcore: registered new interface driver cdc_ether
[426106.785653] scsi 0:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[426106.803758] sd 0:0:0:0: Attached scsi generic sg0 type 0
[426106.820687] sd 0:0:0:0: [sda] Attached SCSI removable disk


Here's ip addr



eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 0c:5b:8f:27:9a:64 brd ff:ff:ff:ff:ff:ff
inet6 fe80::584f:751f:bb3e:e26b/64 scope link
valid_lft forever preferred_lft forever


UPDATE 2



I attached it a few more times until it showed the eth1 route:



[10787.229141] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
[10787.363515] usb 1-1.5: New USB device found, idVendor=05e3, idProduct=0606
[10787.363533] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10787.363544] usb 1-1.5: Product: USB Hub 2.0
[10787.363555] usb 1-1.5: Manufacturer: ALCOR
[10787.365166] hub 1-1.5:1.0: USB hub found
[10787.369831] hub 1-1.5:1.0: 4 ports detected
[10797.419094] usb 1-1.5.1: new full-speed USB device number 8 using dwc_otg
[10797.555636] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10797.565759] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[10797.565777] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[10797.565789] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10797.565799] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10797.565808] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[10797.630477] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[10797.631101] scsi host0: usb-storage 1-1.5.1:1.0
[10798.472745] usb 1-1.5.1: USB disconnect, device number 8
[10799.469081] usb 1-1.5.1: new full-speed USB device number 9 using dwc_otg
[10799.630768] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10799.646891] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[10799.646909] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10799.646920] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10799.646930] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10799.814489] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[10799.815008] scsi host0: usb-storage 1-1.5.1:1.2
[10799.897788] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[10799.898127] usbcore: registered new interface driver cdc_ether
[10800.889652] scsi 0:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[10800.910585] sd 0:0:0:0: Attached scsi generic sg0 type 0
[10800.923297] sd 0:0:0:0: [sda] Attached SCSI removable disk


Here's route -n



Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
0.0.0.0 192.168.8.1 0.0.0.0 UG 207 0 0 eth1
0.0.0.0 192.168.1.1 0.0.0.0 UG 303 0 0 wlan0
169.254.0.0 0.0.0.0 255.255.0.0 U 202 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 204 0 0 docker0
169.254.0.0 0.0.0.0 255.255.0.0 U 206 0 0 veth4557ad2
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.8.0 0.0.0.0 255.255.255.0 U 207 0 0 eth1


See that I did ifmetric wlan0 in order to be able to use the wlan0 to ssh into my raspberry



UPDATE 09/10:



allow-hotplug wlan0
iface wlan0 inet dhcp
up ifmetric wlan0 0
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


This won't make my wlan0 have metric 0. What am I doing wrong?










share|improve this question




















  • 1





    First step is to find out why the 4G modem gets a default route. Does it do DHCP? If yes, figure out what calls it (network manager? traditional ifup/ifdown?), and configure dhclient etc. in that call to not set the default route for that particular interface.

    – dirkt
    Jul 5 '18 at 5:49











  • @dirkt it's a USB dongle, so when it is connected it gets a new interface by default. There's no rule for eth1 on /etc/network/interfaces, however this is the ethernet device assigned to it. Do you know why? I don't know if it does DHCP, the interface is pretty simple, there's no advanced things to change or look. It's a huawei modem. Could you give soe help?

    – Guerlando OCs
    Jul 5 '18 at 13:41






  • 1





    Please edit the question with the output of dmesg and syslog (use journalctl if you have systemd) after you plug in the USB dongle (indent 4 spaces for proper formatting on stackoverflow).

    – dirkt
    Jul 5 '18 at 14:13











  • @dirkt I'll post the dmesg soon when I get somebody to plug the 4G modem for me. In the meantime, how do I find which thing is giving an IP address for my router? I'm using raspbian which is debian based so do you have an idea?

    – Guerlando OCs
    Jul 16 '18 at 21:45











  • In general, you'll get IP addresses via DHCP, usually by calling dhclient, or, if the modem uses a point-to-point protocol, from this protocol. All that should be shown somewhere in the logs, which is why I was asking for the logs. If you don't have physical access to the RaspPi (you didn't mention this), ip link or ip addr should also show if it's a point-to-point protocol or not (possibly you need verbose mode).

    – dirkt
    Jul 17 '18 at 5:43














8












8








8


2






Whenever I add my 4G modem to my raspberry, it gets on top of the default routes ou ip route list, however I want everything to go through wlan, and only use the 4G modem to receive SSH connections.



I've found this answer on how to disable the default routes.



however, after reboot, the 4G modem comes back to the top.



How do I make wlan0 to always be the first rule on default?



UPDATE:



Here's the dmesg output when I connect the USB dongle:



[426102.910168] usb 1-1.5.1: new full-speed USB device number 6 using dwc_otg
[426103.046670] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426103.056674] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[426103.056693] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[426103.056704] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426103.056714] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426103.056724] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[426103.121355] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[426103.122875] scsi host0: usb-storage 1-1.5.1:1.0
[426103.987177] usb 1-1.5.1: USB disconnect, device number 6
[426105.470211] usb 1-1.5.1: new full-speed USB device number 7 using dwc_otg
[426105.606666] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426105.615673] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[426105.615692] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[426105.615703] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426105.615713] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426105.766297] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[426105.766768] scsi host0: usb-storage 1-1.5.1:1.2
[426105.855053] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[426105.855593] usbcore: registered new interface driver cdc_ether
[426106.785653] scsi 0:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[426106.803758] sd 0:0:0:0: Attached scsi generic sg0 type 0
[426106.820687] sd 0:0:0:0: [sda] Attached SCSI removable disk


Here's ip addr



eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 0c:5b:8f:27:9a:64 brd ff:ff:ff:ff:ff:ff
inet6 fe80::584f:751f:bb3e:e26b/64 scope link
valid_lft forever preferred_lft forever


UPDATE 2



I attached it a few more times until it showed the eth1 route:



[10787.229141] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
[10787.363515] usb 1-1.5: New USB device found, idVendor=05e3, idProduct=0606
[10787.363533] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10787.363544] usb 1-1.5: Product: USB Hub 2.0
[10787.363555] usb 1-1.5: Manufacturer: ALCOR
[10787.365166] hub 1-1.5:1.0: USB hub found
[10787.369831] hub 1-1.5:1.0: 4 ports detected
[10797.419094] usb 1-1.5.1: new full-speed USB device number 8 using dwc_otg
[10797.555636] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10797.565759] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[10797.565777] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[10797.565789] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10797.565799] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10797.565808] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[10797.630477] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[10797.631101] scsi host0: usb-storage 1-1.5.1:1.0
[10798.472745] usb 1-1.5.1: USB disconnect, device number 8
[10799.469081] usb 1-1.5.1: new full-speed USB device number 9 using dwc_otg
[10799.630768] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10799.646891] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[10799.646909] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10799.646920] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10799.646930] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10799.814489] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[10799.815008] scsi host0: usb-storage 1-1.5.1:1.2
[10799.897788] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[10799.898127] usbcore: registered new interface driver cdc_ether
[10800.889652] scsi 0:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[10800.910585] sd 0:0:0:0: Attached scsi generic sg0 type 0
[10800.923297] sd 0:0:0:0: [sda] Attached SCSI removable disk


Here's route -n



Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
0.0.0.0 192.168.8.1 0.0.0.0 UG 207 0 0 eth1
0.0.0.0 192.168.1.1 0.0.0.0 UG 303 0 0 wlan0
169.254.0.0 0.0.0.0 255.255.0.0 U 202 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 204 0 0 docker0
169.254.0.0 0.0.0.0 255.255.0.0 U 206 0 0 veth4557ad2
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.8.0 0.0.0.0 255.255.255.0 U 207 0 0 eth1


See that I did ifmetric wlan0 in order to be able to use the wlan0 to ssh into my raspberry



UPDATE 09/10:



allow-hotplug wlan0
iface wlan0 inet dhcp
up ifmetric wlan0 0
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


This won't make my wlan0 have metric 0. What am I doing wrong?










share|improve this question
















Whenever I add my 4G modem to my raspberry, it gets on top of the default routes ou ip route list, however I want everything to go through wlan, and only use the 4G modem to receive SSH connections.



I've found this answer on how to disable the default routes.



however, after reboot, the 4G modem comes back to the top.



How do I make wlan0 to always be the first rule on default?



UPDATE:



Here's the dmesg output when I connect the USB dongle:



[426102.910168] usb 1-1.5.1: new full-speed USB device number 6 using dwc_otg
[426103.046670] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426103.056674] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[426103.056693] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[426103.056704] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426103.056714] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426103.056724] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[426103.121355] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[426103.122875] scsi host0: usb-storage 1-1.5.1:1.0
[426103.987177] usb 1-1.5.1: USB disconnect, device number 6
[426105.470211] usb 1-1.5.1: new full-speed USB device number 7 using dwc_otg
[426105.606666] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[426105.615673] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[426105.615692] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[426105.615703] usb 1-1.5.1: Product: HUAWEI_MOBILE
[426105.615713] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[426105.766297] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[426105.766768] scsi host0: usb-storage 1-1.5.1:1.2
[426105.855053] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[426105.855593] usbcore: registered new interface driver cdc_ether
[426106.785653] scsi 0:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[426106.803758] sd 0:0:0:0: Attached scsi generic sg0 type 0
[426106.820687] sd 0:0:0:0: [sda] Attached SCSI removable disk


Here's ip addr



eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 0c:5b:8f:27:9a:64 brd ff:ff:ff:ff:ff:ff
inet6 fe80::584f:751f:bb3e:e26b/64 scope link
valid_lft forever preferred_lft forever


UPDATE 2



I attached it a few more times until it showed the eth1 route:



[10787.229141] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
[10787.363515] usb 1-1.5: New USB device found, idVendor=05e3, idProduct=0606
[10787.363533] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10787.363544] usb 1-1.5: Product: USB Hub 2.0
[10787.363555] usb 1-1.5: Manufacturer: ALCOR
[10787.365166] hub 1-1.5:1.0: USB hub found
[10787.369831] hub 1-1.5:1.0: 4 ports detected
[10797.419094] usb 1-1.5.1: new full-speed USB device number 8 using dwc_otg
[10797.555636] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10797.565759] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=1f01
[10797.565777] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[10797.565789] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10797.565799] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10797.565808] usb 1-1.5.1: SerialNumber: 0123456789ABCDEF
[10797.630477] usb-storage 1-1.5.1:1.0: USB Mass Storage device detected
[10797.631101] scsi host0: usb-storage 1-1.5.1:1.0
[10798.472745] usb 1-1.5.1: USB disconnect, device number 8
[10799.469081] usb 1-1.5.1: new full-speed USB device number 9 using dwc_otg
[10799.630768] usb 1-1.5.1: not running at top speed; connect to a high speed hub
[10799.646891] usb 1-1.5.1: New USB device found, idVendor=12d1, idProduct=14dc
[10799.646909] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[10799.646920] usb 1-1.5.1: Product: HUAWEI_MOBILE
[10799.646930] usb 1-1.5.1: Manufacturer: HUAWEI_MOBILE
[10799.814489] usb-storage 1-1.5.1:1.2: USB Mass Storage device detected
[10799.815008] scsi host0: usb-storage 1-1.5.1:1.2
[10799.897788] cdc_ether 1-1.5.1:1.0 eth1: register 'cdc_ether' at usb-3f980000.usb-1.5.1, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[10799.898127] usbcore: registered new interface driver cdc_ether
[10800.889652] scsi 0:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[10800.910585] sd 0:0:0:0: Attached scsi generic sg0 type 0
[10800.923297] sd 0:0:0:0: [sda] Attached SCSI removable disk


Here's route -n



Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
0.0.0.0 192.168.8.1 0.0.0.0 UG 207 0 0 eth1
0.0.0.0 192.168.1.1 0.0.0.0 UG 303 0 0 wlan0
169.254.0.0 0.0.0.0 255.255.0.0 U 202 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 204 0 0 docker0
169.254.0.0 0.0.0.0 255.255.0.0 U 206 0 0 veth4557ad2
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.8.0 0.0.0.0 255.255.255.0 U 207 0 0 eth1


See that I did ifmetric wlan0 in order to be able to use the wlan0 to ssh into my raspberry



UPDATE 09/10:



allow-hotplug wlan0
iface wlan0 inet dhcp
up ifmetric wlan0 0
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


This won't make my wlan0 have metric 0. What am I doing wrong?







debian networking network-interface






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago







Guerlando OCs

















asked Jul 4 '18 at 12:09









Guerlando OCsGuerlando OCs

237




237








  • 1





    First step is to find out why the 4G modem gets a default route. Does it do DHCP? If yes, figure out what calls it (network manager? traditional ifup/ifdown?), and configure dhclient etc. in that call to not set the default route for that particular interface.

    – dirkt
    Jul 5 '18 at 5:49











  • @dirkt it's a USB dongle, so when it is connected it gets a new interface by default. There's no rule for eth1 on /etc/network/interfaces, however this is the ethernet device assigned to it. Do you know why? I don't know if it does DHCP, the interface is pretty simple, there's no advanced things to change or look. It's a huawei modem. Could you give soe help?

    – Guerlando OCs
    Jul 5 '18 at 13:41






  • 1





    Please edit the question with the output of dmesg and syslog (use journalctl if you have systemd) after you plug in the USB dongle (indent 4 spaces for proper formatting on stackoverflow).

    – dirkt
    Jul 5 '18 at 14:13











  • @dirkt I'll post the dmesg soon when I get somebody to plug the 4G modem for me. In the meantime, how do I find which thing is giving an IP address for my router? I'm using raspbian which is debian based so do you have an idea?

    – Guerlando OCs
    Jul 16 '18 at 21:45











  • In general, you'll get IP addresses via DHCP, usually by calling dhclient, or, if the modem uses a point-to-point protocol, from this protocol. All that should be shown somewhere in the logs, which is why I was asking for the logs. If you don't have physical access to the RaspPi (you didn't mention this), ip link or ip addr should also show if it's a point-to-point protocol or not (possibly you need verbose mode).

    – dirkt
    Jul 17 '18 at 5:43














  • 1





    First step is to find out why the 4G modem gets a default route. Does it do DHCP? If yes, figure out what calls it (network manager? traditional ifup/ifdown?), and configure dhclient etc. in that call to not set the default route for that particular interface.

    – dirkt
    Jul 5 '18 at 5:49











  • @dirkt it's a USB dongle, so when it is connected it gets a new interface by default. There's no rule for eth1 on /etc/network/interfaces, however this is the ethernet device assigned to it. Do you know why? I don't know if it does DHCP, the interface is pretty simple, there's no advanced things to change or look. It's a huawei modem. Could you give soe help?

    – Guerlando OCs
    Jul 5 '18 at 13:41






  • 1





    Please edit the question with the output of dmesg and syslog (use journalctl if you have systemd) after you plug in the USB dongle (indent 4 spaces for proper formatting on stackoverflow).

    – dirkt
    Jul 5 '18 at 14:13











  • @dirkt I'll post the dmesg soon when I get somebody to plug the 4G modem for me. In the meantime, how do I find which thing is giving an IP address for my router? I'm using raspbian which is debian based so do you have an idea?

    – Guerlando OCs
    Jul 16 '18 at 21:45











  • In general, you'll get IP addresses via DHCP, usually by calling dhclient, or, if the modem uses a point-to-point protocol, from this protocol. All that should be shown somewhere in the logs, which is why I was asking for the logs. If you don't have physical access to the RaspPi (you didn't mention this), ip link or ip addr should also show if it's a point-to-point protocol or not (possibly you need verbose mode).

    – dirkt
    Jul 17 '18 at 5:43








1




1





First step is to find out why the 4G modem gets a default route. Does it do DHCP? If yes, figure out what calls it (network manager? traditional ifup/ifdown?), and configure dhclient etc. in that call to not set the default route for that particular interface.

– dirkt
Jul 5 '18 at 5:49





First step is to find out why the 4G modem gets a default route. Does it do DHCP? If yes, figure out what calls it (network manager? traditional ifup/ifdown?), and configure dhclient etc. in that call to not set the default route for that particular interface.

– dirkt
Jul 5 '18 at 5:49













@dirkt it's a USB dongle, so when it is connected it gets a new interface by default. There's no rule for eth1 on /etc/network/interfaces, however this is the ethernet device assigned to it. Do you know why? I don't know if it does DHCP, the interface is pretty simple, there's no advanced things to change or look. It's a huawei modem. Could you give soe help?

– Guerlando OCs
Jul 5 '18 at 13:41





@dirkt it's a USB dongle, so when it is connected it gets a new interface by default. There's no rule for eth1 on /etc/network/interfaces, however this is the ethernet device assigned to it. Do you know why? I don't know if it does DHCP, the interface is pretty simple, there's no advanced things to change or look. It's a huawei modem. Could you give soe help?

– Guerlando OCs
Jul 5 '18 at 13:41




1




1





Please edit the question with the output of dmesg and syslog (use journalctl if you have systemd) after you plug in the USB dongle (indent 4 spaces for proper formatting on stackoverflow).

– dirkt
Jul 5 '18 at 14:13





Please edit the question with the output of dmesg and syslog (use journalctl if you have systemd) after you plug in the USB dongle (indent 4 spaces for proper formatting on stackoverflow).

– dirkt
Jul 5 '18 at 14:13













@dirkt I'll post the dmesg soon when I get somebody to plug the 4G modem for me. In the meantime, how do I find which thing is giving an IP address for my router? I'm using raspbian which is debian based so do you have an idea?

– Guerlando OCs
Jul 16 '18 at 21:45





@dirkt I'll post the dmesg soon when I get somebody to plug the 4G modem for me. In the meantime, how do I find which thing is giving an IP address for my router? I'm using raspbian which is debian based so do you have an idea?

– Guerlando OCs
Jul 16 '18 at 21:45













In general, you'll get IP addresses via DHCP, usually by calling dhclient, or, if the modem uses a point-to-point protocol, from this protocol. All that should be shown somewhere in the logs, which is why I was asking for the logs. If you don't have physical access to the RaspPi (you didn't mention this), ip link or ip addr should also show if it's a point-to-point protocol or not (possibly you need verbose mode).

– dirkt
Jul 17 '18 at 5:43





In general, you'll get IP addresses via DHCP, usually by calling dhclient, or, if the modem uses a point-to-point protocol, from this protocol. All that should be shown somewhere in the logs, which is why I was asking for the logs. If you don't have physical access to the RaspPi (you didn't mention this), ip link or ip addr should also show if it's a point-to-point protocol or not (possibly you need verbose mode).

– dirkt
Jul 17 '18 at 5:43










4 Answers
4






active

oldest

votes


















4





+25









For changing the routing priority for an interface you change metrics.



By default, all are 0, which is the highest priority. So, you can do:



allow-hotplug eth1
iface eth1 inet dhcp
up ifmetric eth1 30


To use ifmetric in Debian, you have got to install it:



sudo apt-get install ifmetric



ifmetric



Set routing metrics for a network interface



ifmetric is a Linux tool for setting the metrics of all IPv4 routes
attached to a given network interface at once. This may be used to
change the priority of routing IPv4 traffic over the interface. Lower
metrics correlate with higher priorities.



The metric 0 means the highest priority route and is the default one.
The larger metric value means lower priority routes. The IP address of
the active interface with the lowest metric value becomes the
originating one. See ifmetric(8).







share|improve this answer





















  • 1





    Maybe you should also explain why this will help getting DHCP from a particular interface (instead of ignoring it) if there are other interfaces present.

    – dirkt
    Jul 20 '18 at 6:13











  • @dirkt could you explain better the dhcp thing? I currently have iface wlan0 inet manual up ifmetric wlan0 0 but wlan0 metric won't appear as 0

    – Guerlando OCs
    Oct 9 '18 at 13:35





















1














This is the good old problem of how to override a default route.



The easiest way for IPv4 is not to try and change the metric/priority but split the route:



ip route add 0.0.0.0/1 via wlan0-gw
ip route add 128.0.0.0/1 via wlan0-gw


The reason this works is that routing table lookups are performed using a longest-matching-prefix search. Route metrics come into play only when there are two otherwise equivalent routes. In this case, these two routes have a 1-bit prefix which is longer than the 0-bits prefix of the default route (0.0.0.0/0) and will be consulted first. Since these two routes cover the whole of 0.0.0.0/0, they will always have preference over the default route.



An alternative approach is to use a separate routing table with the default route you prefer and add a rule to send all traffic there. I've never seen any automation that messes with ip rules, so it won't matter what other routes they add. The problem here is that your automation won't be able to insert additional routes though.



So, tl;dr:



iface wlan0 inet manual
up ip route add 0.0.0.0/1 via wlan0-gw
up ip route add 128.0.0.0/1 via wlan0-gw
....


Or (but you will also have to add all other routes to "table 5"):



iface wlan0 inet manual
up ip rule add to 0.0.0.0/0 table 5
up ip route add default via wlan0-gw table 5
....





share|improve this answer































    0














    One way to Persist the ip route add/del in debian is to write them down into /etc/network/interfaces like below:



    allow-hotplug eth1
    iface eth1 inet dhcp
    post-up ip route del default
    post-up ip route add default via <gateway IP> dev wlan0





    share|improve this answer
























    • I think this way it will just add a default gateway for each interface, but not which one is used preferably

      – Guerlando OCs
      Oct 9 '18 at 13:38













    • Ok I understood, it will exclude the default one and add one for wlan0. But won't a default one for eth0 be added too?

      – Guerlando OCs
      Oct 9 '18 at 13:39



















    0














    I think the matter on default gateway. Here is the tutorial.



    I briefly explain the steps. First, you need to delete the default gateway and add the one you want to add. Then, you edit "/etc/network/interfaces" for permanent change. Finally, you restart the service.



    https://www.wikihow.com/Add-or-Change-the-Default-Gateway-in-Linux






    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453414%2fhow-to-make-wlan-to-always-be-the-default-route-ip-route-list%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4





      +25









      For changing the routing priority for an interface you change metrics.



      By default, all are 0, which is the highest priority. So, you can do:



      allow-hotplug eth1
      iface eth1 inet dhcp
      up ifmetric eth1 30


      To use ifmetric in Debian, you have got to install it:



      sudo apt-get install ifmetric



      ifmetric



      Set routing metrics for a network interface



      ifmetric is a Linux tool for setting the metrics of all IPv4 routes
      attached to a given network interface at once. This may be used to
      change the priority of routing IPv4 traffic over the interface. Lower
      metrics correlate with higher priorities.



      The metric 0 means the highest priority route and is the default one.
      The larger metric value means lower priority routes. The IP address of
      the active interface with the lowest metric value becomes the
      originating one. See ifmetric(8).







      share|improve this answer





















      • 1





        Maybe you should also explain why this will help getting DHCP from a particular interface (instead of ignoring it) if there are other interfaces present.

        – dirkt
        Jul 20 '18 at 6:13











      • @dirkt could you explain better the dhcp thing? I currently have iface wlan0 inet manual up ifmetric wlan0 0 but wlan0 metric won't appear as 0

        – Guerlando OCs
        Oct 9 '18 at 13:35


















      4





      +25









      For changing the routing priority for an interface you change metrics.



      By default, all are 0, which is the highest priority. So, you can do:



      allow-hotplug eth1
      iface eth1 inet dhcp
      up ifmetric eth1 30


      To use ifmetric in Debian, you have got to install it:



      sudo apt-get install ifmetric



      ifmetric



      Set routing metrics for a network interface



      ifmetric is a Linux tool for setting the metrics of all IPv4 routes
      attached to a given network interface at once. This may be used to
      change the priority of routing IPv4 traffic over the interface. Lower
      metrics correlate with higher priorities.



      The metric 0 means the highest priority route and is the default one.
      The larger metric value means lower priority routes. The IP address of
      the active interface with the lowest metric value becomes the
      originating one. See ifmetric(8).







      share|improve this answer





















      • 1





        Maybe you should also explain why this will help getting DHCP from a particular interface (instead of ignoring it) if there are other interfaces present.

        – dirkt
        Jul 20 '18 at 6:13











      • @dirkt could you explain better the dhcp thing? I currently have iface wlan0 inet manual up ifmetric wlan0 0 but wlan0 metric won't appear as 0

        – Guerlando OCs
        Oct 9 '18 at 13:35
















      4





      +25







      4





      +25



      4




      +25





      For changing the routing priority for an interface you change metrics.



      By default, all are 0, which is the highest priority. So, you can do:



      allow-hotplug eth1
      iface eth1 inet dhcp
      up ifmetric eth1 30


      To use ifmetric in Debian, you have got to install it:



      sudo apt-get install ifmetric



      ifmetric



      Set routing metrics for a network interface



      ifmetric is a Linux tool for setting the metrics of all IPv4 routes
      attached to a given network interface at once. This may be used to
      change the priority of routing IPv4 traffic over the interface. Lower
      metrics correlate with higher priorities.



      The metric 0 means the highest priority route and is the default one.
      The larger metric value means lower priority routes. The IP address of
      the active interface with the lowest metric value becomes the
      originating one. See ifmetric(8).







      share|improve this answer















      For changing the routing priority for an interface you change metrics.



      By default, all are 0, which is the highest priority. So, you can do:



      allow-hotplug eth1
      iface eth1 inet dhcp
      up ifmetric eth1 30


      To use ifmetric in Debian, you have got to install it:



      sudo apt-get install ifmetric



      ifmetric



      Set routing metrics for a network interface



      ifmetric is a Linux tool for setting the metrics of all IPv4 routes
      attached to a given network interface at once. This may be used to
      change the priority of routing IPv4 traffic over the interface. Lower
      metrics correlate with higher priorities.



      The metric 0 means the highest priority route and is the default one.
      The larger metric value means lower priority routes. The IP address of
      the active interface with the lowest metric value becomes the
      originating one. See ifmetric(8).








      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jul 20 '18 at 7:45

























      answered Jul 19 '18 at 23:20









      Rui F RibeiroRui F Ribeiro

      40.7k1479137




      40.7k1479137








      • 1





        Maybe you should also explain why this will help getting DHCP from a particular interface (instead of ignoring it) if there are other interfaces present.

        – dirkt
        Jul 20 '18 at 6:13











      • @dirkt could you explain better the dhcp thing? I currently have iface wlan0 inet manual up ifmetric wlan0 0 but wlan0 metric won't appear as 0

        – Guerlando OCs
        Oct 9 '18 at 13:35
















      • 1





        Maybe you should also explain why this will help getting DHCP from a particular interface (instead of ignoring it) if there are other interfaces present.

        – dirkt
        Jul 20 '18 at 6:13











      • @dirkt could you explain better the dhcp thing? I currently have iface wlan0 inet manual up ifmetric wlan0 0 but wlan0 metric won't appear as 0

        – Guerlando OCs
        Oct 9 '18 at 13:35










      1




      1





      Maybe you should also explain why this will help getting DHCP from a particular interface (instead of ignoring it) if there are other interfaces present.

      – dirkt
      Jul 20 '18 at 6:13





      Maybe you should also explain why this will help getting DHCP from a particular interface (instead of ignoring it) if there are other interfaces present.

      – dirkt
      Jul 20 '18 at 6:13













      @dirkt could you explain better the dhcp thing? I currently have iface wlan0 inet manual up ifmetric wlan0 0 but wlan0 metric won't appear as 0

      – Guerlando OCs
      Oct 9 '18 at 13:35







      @dirkt could you explain better the dhcp thing? I currently have iface wlan0 inet manual up ifmetric wlan0 0 but wlan0 metric won't appear as 0

      – Guerlando OCs
      Oct 9 '18 at 13:35















      1














      This is the good old problem of how to override a default route.



      The easiest way for IPv4 is not to try and change the metric/priority but split the route:



      ip route add 0.0.0.0/1 via wlan0-gw
      ip route add 128.0.0.0/1 via wlan0-gw


      The reason this works is that routing table lookups are performed using a longest-matching-prefix search. Route metrics come into play only when there are two otherwise equivalent routes. In this case, these two routes have a 1-bit prefix which is longer than the 0-bits prefix of the default route (0.0.0.0/0) and will be consulted first. Since these two routes cover the whole of 0.0.0.0/0, they will always have preference over the default route.



      An alternative approach is to use a separate routing table with the default route you prefer and add a rule to send all traffic there. I've never seen any automation that messes with ip rules, so it won't matter what other routes they add. The problem here is that your automation won't be able to insert additional routes though.



      So, tl;dr:



      iface wlan0 inet manual
      up ip route add 0.0.0.0/1 via wlan0-gw
      up ip route add 128.0.0.0/1 via wlan0-gw
      ....


      Or (but you will also have to add all other routes to "table 5"):



      iface wlan0 inet manual
      up ip rule add to 0.0.0.0/0 table 5
      up ip route add default via wlan0-gw table 5
      ....





      share|improve this answer




























        1














        This is the good old problem of how to override a default route.



        The easiest way for IPv4 is not to try and change the metric/priority but split the route:



        ip route add 0.0.0.0/1 via wlan0-gw
        ip route add 128.0.0.0/1 via wlan0-gw


        The reason this works is that routing table lookups are performed using a longest-matching-prefix search. Route metrics come into play only when there are two otherwise equivalent routes. In this case, these two routes have a 1-bit prefix which is longer than the 0-bits prefix of the default route (0.0.0.0/0) and will be consulted first. Since these two routes cover the whole of 0.0.0.0/0, they will always have preference over the default route.



        An alternative approach is to use a separate routing table with the default route you prefer and add a rule to send all traffic there. I've never seen any automation that messes with ip rules, so it won't matter what other routes they add. The problem here is that your automation won't be able to insert additional routes though.



        So, tl;dr:



        iface wlan0 inet manual
        up ip route add 0.0.0.0/1 via wlan0-gw
        up ip route add 128.0.0.0/1 via wlan0-gw
        ....


        Or (but you will also have to add all other routes to "table 5"):



        iface wlan0 inet manual
        up ip rule add to 0.0.0.0/0 table 5
        up ip route add default via wlan0-gw table 5
        ....





        share|improve this answer


























          1












          1








          1







          This is the good old problem of how to override a default route.



          The easiest way for IPv4 is not to try and change the metric/priority but split the route:



          ip route add 0.0.0.0/1 via wlan0-gw
          ip route add 128.0.0.0/1 via wlan0-gw


          The reason this works is that routing table lookups are performed using a longest-matching-prefix search. Route metrics come into play only when there are two otherwise equivalent routes. In this case, these two routes have a 1-bit prefix which is longer than the 0-bits prefix of the default route (0.0.0.0/0) and will be consulted first. Since these two routes cover the whole of 0.0.0.0/0, they will always have preference over the default route.



          An alternative approach is to use a separate routing table with the default route you prefer and add a rule to send all traffic there. I've never seen any automation that messes with ip rules, so it won't matter what other routes they add. The problem here is that your automation won't be able to insert additional routes though.



          So, tl;dr:



          iface wlan0 inet manual
          up ip route add 0.0.0.0/1 via wlan0-gw
          up ip route add 128.0.0.0/1 via wlan0-gw
          ....


          Or (but you will also have to add all other routes to "table 5"):



          iface wlan0 inet manual
          up ip rule add to 0.0.0.0/0 table 5
          up ip route add default via wlan0-gw table 5
          ....





          share|improve this answer













          This is the good old problem of how to override a default route.



          The easiest way for IPv4 is not to try and change the metric/priority but split the route:



          ip route add 0.0.0.0/1 via wlan0-gw
          ip route add 128.0.0.0/1 via wlan0-gw


          The reason this works is that routing table lookups are performed using a longest-matching-prefix search. Route metrics come into play only when there are two otherwise equivalent routes. In this case, these two routes have a 1-bit prefix which is longer than the 0-bits prefix of the default route (0.0.0.0/0) and will be consulted first. Since these two routes cover the whole of 0.0.0.0/0, they will always have preference over the default route.



          An alternative approach is to use a separate routing table with the default route you prefer and add a rule to send all traffic there. I've never seen any automation that messes with ip rules, so it won't matter what other routes they add. The problem here is that your automation won't be able to insert additional routes though.



          So, tl;dr:



          iface wlan0 inet manual
          up ip route add 0.0.0.0/1 via wlan0-gw
          up ip route add 128.0.0.0/1 via wlan0-gw
          ....


          Or (but you will also have to add all other routes to "table 5"):



          iface wlan0 inet manual
          up ip rule add to 0.0.0.0/0 table 5
          up ip route add default via wlan0-gw table 5
          ....






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 13 '18 at 23:12









          V13V13

          2,849613




          2,849613























              0














              One way to Persist the ip route add/del in debian is to write them down into /etc/network/interfaces like below:



              allow-hotplug eth1
              iface eth1 inet dhcp
              post-up ip route del default
              post-up ip route add default via <gateway IP> dev wlan0





              share|improve this answer
























              • I think this way it will just add a default gateway for each interface, but not which one is used preferably

                – Guerlando OCs
                Oct 9 '18 at 13:38













              • Ok I understood, it will exclude the default one and add one for wlan0. But won't a default one for eth0 be added too?

                – Guerlando OCs
                Oct 9 '18 at 13:39
















              0














              One way to Persist the ip route add/del in debian is to write them down into /etc/network/interfaces like below:



              allow-hotplug eth1
              iface eth1 inet dhcp
              post-up ip route del default
              post-up ip route add default via <gateway IP> dev wlan0





              share|improve this answer
























              • I think this way it will just add a default gateway for each interface, but not which one is used preferably

                – Guerlando OCs
                Oct 9 '18 at 13:38













              • Ok I understood, it will exclude the default one and add one for wlan0. But won't a default one for eth0 be added too?

                – Guerlando OCs
                Oct 9 '18 at 13:39














              0












              0








              0







              One way to Persist the ip route add/del in debian is to write them down into /etc/network/interfaces like below:



              allow-hotplug eth1
              iface eth1 inet dhcp
              post-up ip route del default
              post-up ip route add default via <gateway IP> dev wlan0





              share|improve this answer













              One way to Persist the ip route add/del in debian is to write them down into /etc/network/interfaces like below:



              allow-hotplug eth1
              iface eth1 inet dhcp
              post-up ip route del default
              post-up ip route add default via <gateway IP> dev wlan0






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jul 18 '18 at 9:49









              EzwigEzwig

              325213




              325213













              • I think this way it will just add a default gateway for each interface, but not which one is used preferably

                – Guerlando OCs
                Oct 9 '18 at 13:38













              • Ok I understood, it will exclude the default one and add one for wlan0. But won't a default one for eth0 be added too?

                – Guerlando OCs
                Oct 9 '18 at 13:39



















              • I think this way it will just add a default gateway for each interface, but not which one is used preferably

                – Guerlando OCs
                Oct 9 '18 at 13:38













              • Ok I understood, it will exclude the default one and add one for wlan0. But won't a default one for eth0 be added too?

                – Guerlando OCs
                Oct 9 '18 at 13:39

















              I think this way it will just add a default gateway for each interface, but not which one is used preferably

              – Guerlando OCs
              Oct 9 '18 at 13:38







              I think this way it will just add a default gateway for each interface, but not which one is used preferably

              – Guerlando OCs
              Oct 9 '18 at 13:38















              Ok I understood, it will exclude the default one and add one for wlan0. But won't a default one for eth0 be added too?

              – Guerlando OCs
              Oct 9 '18 at 13:39





              Ok I understood, it will exclude the default one and add one for wlan0. But won't a default one for eth0 be added too?

              – Guerlando OCs
              Oct 9 '18 at 13:39











              0














              I think the matter on default gateway. Here is the tutorial.



              I briefly explain the steps. First, you need to delete the default gateway and add the one you want to add. Then, you edit "/etc/network/interfaces" for permanent change. Finally, you restart the service.



              https://www.wikihow.com/Add-or-Change-the-Default-Gateway-in-Linux






              share|improve this answer




























                0














                I think the matter on default gateway. Here is the tutorial.



                I briefly explain the steps. First, you need to delete the default gateway and add the one you want to add. Then, you edit "/etc/network/interfaces" for permanent change. Finally, you restart the service.



                https://www.wikihow.com/Add-or-Change-the-Default-Gateway-in-Linux






                share|improve this answer


























                  0












                  0








                  0







                  I think the matter on default gateway. Here is the tutorial.



                  I briefly explain the steps. First, you need to delete the default gateway and add the one you want to add. Then, you edit "/etc/network/interfaces" for permanent change. Finally, you restart the service.



                  https://www.wikihow.com/Add-or-Change-the-Default-Gateway-in-Linux






                  share|improve this answer













                  I think the matter on default gateway. Here is the tutorial.



                  I briefly explain the steps. First, you need to delete the default gateway and add the one you want to add. Then, you edit "/etc/network/interfaces" for permanent change. Finally, you restart the service.



                  https://www.wikihow.com/Add-or-Change-the-Default-Gateway-in-Linux







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 20 '18 at 1:39









                  jefferyearjefferyear

                  5529




                  5529






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453414%2fhow-to-make-wlan-to-always-be-the-default-route-ip-route-list%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      CARDNET

                      Boot-repair Failure: Unable to locate package grub-common:i386

                      Aws NAT - Aws IGW- Aws router