0

I am using the AT&T Avnet IoT Starter Kit to provide cellular connectivity to my Raspberry Pi 3b+. In order to establish the routing table I added an ip command to the file /lib/dhcpcd/dhcpcd-hooks/40-route the command I added was:

ip route add default via 0.0.0.0 dev enx001122334456

(The enx001122334456 is the name of my ethernet device, like eth1 but with a 'predictable name').

This sets the routing table, after booting up I'll have a routing table like:

Dest            Gateway     Genmask         Flags Metric Iface
default         0.0.0.0     0.0.0.0         U     0      enx001122334456
default         0.0.0.0     0.0.0.0         U     0      enx001122334456
default         10.0.0.1    0.0.0.0         UG    303    wlan0
10.0.0.0        0.0.0.0     255.255.255.0   U     303    wlan0
10.0.0.1        0.0.0.0     255.255.255.240 U     221    enx001122334456
10.47.206.96    0.0.0.0     255.255.255.240 U     221    enx001122334456
...
Down here there are a bunch of docker virtual ethernet interfaces and bridge networks

This does exactly what I want it to do for a while, but then it seems to reset (I think it is a changing of the IP addresses that triggers it) and I no longer have my default route. I am using dhcp, so it makes sense that the ip address is changing, but it doesn't make sense that it would have an adverse effect on the routing table. Instead it becomes:

Dest            Gateway     Genmask         Flags Metric Iface
default         0.0.0.0     0.0.0.0         U     0      enx001122334456
default         10.0.0.1    0.0.0.0         UG    303    wlan0
10.0.0.0        0.0.0.0     255.255.255.0   U     303    wlan0
10.0.0.1        0.0.0.0     255.255.255.240 U     221    enx001122334456
10.47.206.96    0.0.0.0     255.255.255.240 U     221    enx001122334456
...

which, although nearly identical, ping 8.8.8.8 doesn't work. Sometimes, even if I specify the interface with ping -I enx001122334456 8.8.8.8 it won't work.

I'm thoroughly confused. I have no idea how to continue debugging this, I just want it to work. Anyone have any knowledge on what could be causing my routing table to reset. Even if you just give me debugging tools or tricks that would be amazing.

8
  • /etc/resolv.conf contains # Generated by resolvconf - this is normal for virtually all dhcp clients (including dhcpcd). You can change it but it will be overwritten!
    – Milliways
    Commented Jan 8, 2019 at 2:20
  • @Milliways so you’re saying what exactly? Commented Jan 8, 2019 at 2:23
  • It is unclear (at least to me) what you are trying to do, but dhcpcd is working normally. Explore resolvconf if you want to set routing. man dhcpcd explains this.
    – Milliways
    Commented Jan 8, 2019 at 2:28
  • So, are you saying that I should expect the routing table to reset when I get a new ip address? Also, I’ll explore resolveconf in its man, but on a high level, what is it doing that ip route or route is not? Commented Jan 8, 2019 at 16:08
  • Please do not obfuscate the metric value in the output from the "route" command.
    – MatsK
    Commented Jan 9, 2019 at 13:36

2 Answers 2

2

You should allow interface associated with cellular connection to be configured completely via DHCP. Part of the process is also setting up default router. You should have only one default path in the system. (It is possible to have more but that leads to complications you don't need or want). Network on Raspbian can be configured via dhcpcd or classic debian networking subsystem. You can toggle between them by using

#systemctl disable dhcpcd
#systemctl enable networking

or the opposite.

I prefer networking for headless devices. Even if it is bit dumber and slower but at the same time more reliable - if you want to have interface configured even without Ethernet cable plugged in. Dhdpcd will attempt to configure any visible interface so when you switch to Debian's networking subsystem you will have to set up configuration for every interface you want to be configured during system boot. As I said it is my preference mainly due to fact that it will deal with all interfaces before allowing system to continue. It is important if you have services bound to specific interface, etc.

In case od dhcpcd configuration is in /etc/dhcpcd.conf and networking in /etc/network/interfaces.

Dhcpcd is more than just DHCP client. In Raspbian it is used to completely configure networking and even manage Wi-Fi interfaces. You may define specific rules for every interface including static IP configuration. It is great for devices where network settings change frequently or there are many possible configurations.

/etc/network/interfaces:

auto enx001122334456
allow-hotplug enx001122334456
iface enx001122334456 inet dhcp

Should be all you need to properly set up internet access and make it work across reboots.

Make sure that other interfaces are not auto-configured with default router via DHCP and you're good. Check documentation for mechanism of your choice (man interfaces or man dhcpcd.conf). There is plenty of useful information in there.

Have a look at this topic.

3
  • Ah, this is interesting, I did not realize networking and dhcp would have competing interests. So you’re saying if I’m using interfaces I should not use dhcp and vice versa? When you say networking is more reliable, what makes it more reliable? Commented Jan 9, 2019 at 15:22
  • @ConnorMcCormick This answer is at best incomplete. This would disable your wlan0 interface. The default dhcpcd IS a DHCP client (and arguably better than the Debian one).
    – Milliways
    Commented Jan 10, 2019 at 1:12
  • 2
    @ConnorMcCormick There are plenty of network configuration subsystems in Linux world. Both networking and dhcpcd can do the same work. It does not mean though that networking cannot configure interfaces via DHCP protocol. There are two concerns here - a) having multiple interfaces configured via DHCP may lead to multiple default routes present and b) dhcpcd will not configure ethernet interface unless there is cable plugged in. This may lead to problems when some program started at boot requires interface to be present (like internet sharing iptables configuration) Commented Jan 10, 2019 at 6:27
1

The default route needs a Gateway where to send packages with a destination the kernel does not know. The Gateway must be a host (router) on the same network the RasPi is direct connected to with an interface. According to your routing table the RasPi is connected to two subnets:

10.0.0.0/24     with addresses from 10.0.0.1     to 10.0.0.254    on interface wlan0
10.47.206.96/28 with addresses from 10.47.206.97 to 10.47.206.110 on interface enx001122334456

The gateway must have one of this ip addresses. I don't know on which subnet your gateway resides. It is up to you to find it out. I guess you have a wired uplink so it could be on 10.47.206.96/28, for example 10.47.206.97. Then you have to set the default route to:

ip route add default via 10.47.206.97 dev enx001122334456

You have more than one default route in your routing table. You should ensure that you have only one.

4
  • So, the problem is that if I give it a gateway (like 10.47....) then when it gets a new ip address it disconnects. Commented Jan 8, 2019 at 15:24
  • Another question: how can my pi know how to set the default route on boot up if it will often have a different ip address? Clearly, I can’t put ip route add default via 10.47.206.97 dev enx001122334456 in my 40-route file because in 22 hours that up address will change, right? Commented Jan 8, 2019 at 15:36
  • You can have several default routes, the priority for which one to prefer is controlled by "metric", the lowest metric first and if that one fails it tries the next in succession. Ref.: en.wikipedia.org/wiki/Metrics_(networking)
    – MatsK
    Commented Jan 9, 2019 at 13:08
  • 2
    @MatsK Yes I know. But that's for failover and I don't believe this will help in this situation. It's only to get more confused. Also having double the same default route doesn't make sense. My goal is to get first a simple running system that can then be improved, maybe with additional default routes.
    – Ingo
    Commented Jan 9, 2019 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.