I have a machine running a derivative of Debian (Raspbian) with two NICs, one Ethernet (eth0) and the other wireless (wlan0). eth0 connects the machine to a private LAN and has a static address, while wlan0 connects the machine to the Internet and is configured with wpa_supplicant. Without additional configuration, I can ping the router on the LAN, and cannot ping, say, google.com. I assumed, after doing some research, that the cleanest way to accomplish this was to setup custom routing tables. The routing rules would route all traffic to and from the LAN network over eth0, while all other traffic would go through wlan0. Correct me if if there is a mistake in that logic.

I've already figured out how I need to set up the routing tables to accomplish this; and I can make it work when I manually set the rules with the ip route command. The issue is that I can't seem to set up the routing tables when bringing the interfaces up by using the post-up command in the interfaces file.

To explain my thought process from the beginning...

This is the output of route -n without additional configuration.

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 eth0         UG    303    0        0 wlan0   U     303    0        0 wlan0   U     0      0        0 eth0

According to my understanding, there is a conflict for communication with 'any destination', which is resolved by using eth0 because of it's lower metric. This makes all outbound traffic go through eth0. Ideally, only traffic meant for, and coming from, the LAN should go through eth0. So, I thought by removing the default generated rules and making a single rule that specifies the destination and gateway for the network, I could achieve the behavior I wanted. After running a few commands to delete the default routing rules and adding the new one I described, I got the following routing table.

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    303    0        0 wlan0   U     303    0        0 wlan0   UG    0      0        0 eth0

Afterwards, I can ping both the LAN's gateway and google.com. So it seems my intuition was correct. Correct me if this was just a fluke.

To make the routing rules permanent, many guides and Serverfault answers I've found suggest that using post-up commands in the interfaces file is the best way to go about that. So I edited my interfaces file, as seen below.

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet static
    up ip route delete via dev eth0
    up ip route delete via dev eth0
    up ip route add via dev eth0

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

After rebooting, the routing table remains the same as the default. boot.log doesn't show ifup eth0 throwing any errors. I'm at a loss as to what might be causing these issues.

migrated from serverfault.com Feb 8 '17 at 20:11

This question came from our site for system and network administrators.

  • Ever thought about using network namespaces? – phk Feb 8 '17 at 21:17
  • @phk I can't say I have. I'm new to routing/networking in general. I'm learning what I need to fix this issue. From what I've read I'm not sure how network namespaces would help. Do you think you could write up a more fledged out explanation as an answer? – ktb Feb 8 '17 at 22:36
  • You don't need to assign routes for directly connected networks. – Khirgiy Mikhail Feb 20 '17 at 5:17

So my issue was not one of concept, but the guides I drew my knowledge from were very outdated. This issue is of the class: Systemd strikes again!.

The current Raspbian distribution follows Debian Jessie, which uses systemd. And systemd doesn't follow everything from /etc/network/interfaces, but uses it to generate rules for /etc/dhcpcd.conf. Systemd bases all interface configuration, whether the addressing is static or dynamic, off of /etc/dhcpcd.conf.

To get the behavior I wanted, I first cut all configuration for eth0 out of /etc/network/interfaces besides

allow-hotplug eth0
iface eth0 inet static

Then I edited the interface eth0 section of /etc/dhcpcd.conf to...

interface eth0
static ip_address=

Note, I didn't set static router= That would generate the default via dev eth0 route I didn't want present (because it conflicts with the default route for wlan0).

With that minimal configuration, I can now use both interfaces to communication over their respective networks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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