I'm using a beaglebone black with the newest IoT Debian 9 image (BeagleBoard.org Debian Image 2018-03-05)
Here is how I configured my network interfaces:
/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.220
netmask 255.255.255.0
gateway 192.168.0.155
# Ethernet/RNDIS gadget (g_ether)
iface usb0 inet static
address 192.168.7.2
netmask 255.255.255.252
network 192.168.7.0
gateway 192.168.7.1
# Nameservers
dns-nameservers 192.168.0.155
After I start the interface, my routing table looks like this:
debian@beaglebone:~$ ip route
default via 192.168.0.155 dev eth0 onlink
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.220
192.168.6.0/30 dev usb1 proto kernel scope link src 192.168.6.2 linkdown
192.168.7.0/30 dev usb0 proto kernel scope link src 192.168.7.2
I can reach the internet via my default gateway and everything works as it should, but after 1-2 minutes some additional entries appear.
Now my routing table looks like this:
debian@beaglebone:~$ ip route
default dev eth0 scope link
default via 192.168.0.155 dev eth0 onlink
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.220
169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.66.227
192.168.6.0/30 dev usb1 proto kernel scope link src 192.168.6.2 linkdown
192.168.7.0/30 dev usb0 proto kernel scope link src 192.168.7.2
Now the upper default gateway seems to be used instead of the one defined by me. As a result, the internet (and other internal networks) is not reachable.
This only happens if eth0 is connected to a network. All the other devices within the network I am using are also configured statically.
How can I get my system to use the default gw I want it to use?
I already tried to remove the default gateway from usb0 or putting it into an separate routing table, which resulted in the beaglebone being not reachable via any interface.
Here is the output of ifconfig, just in case somebody finds something suspicious here.
debian@beaglebone:~$ ifconfig
eth0: flags=-28605<UP,BROADCAST,RUNNING,MULTICAST,DYNAMIC> mtu 1500
inet 192.168.0.220 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::564a:16ff:fee5:e79d prefixlen 64 scopeid 0x20<link>
ether 54:4a:16:e5:e7:9d txqueuelen 1000 (Ethernet)
RX packets 79 bytes 9988 (9.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 458 bytes 85028 (83.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 181
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 180 bytes 14118 (13.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 180 bytes 14118 (13.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.7.2 netmask 255.255.255.252 broadcast 192.168.7.3
inet6 fe80::564a:16ff:fee5:e79f prefixlen 64 scopeid 0x20<link>
ether 54:4a:16:e5:e7:9f txqueuelen 1000 (Ethernet)
RX packets 740 bytes 79447 (77.5 KiB)
RX errors 0 dropped 4 overruns 0 frame 0
TX packets 525 bytes 97473 (95.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
usb1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.6.2 netmask 255.255.255.252 broadcast 192.168.6.3
ether 54:4a:16:e5:e7:a2 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0