Two ethernet ports not working at the same time with static IP

I have an embedded system with two integrated ethernet ports. I’m running Ubuntu Core 18 on it. The network at my company associates a fixed IP to every MAC address of the network adapters. When the network configuration is set to DHCP for both ports by using console-conf I can properly connect to the device over both ports. Now, to control a PLC, we need to set a static IPv4 configuration for one of the network adapters (IP, NetMask and Gateway). The other port should still use DHCP to log in by SSH. I used console-conf for this setting as well.

As long as the PLC is not turned on or not connected to the port with the fixed IP, SSH over the DHCP port is possible. But when I connect the PLC, the static configuration works fine, but my DHCP port is not available anymore. I can neither ping nor login via SSH. This can easily be undone by unplugging the PLC. The same behaviour occurs if I just plug-in another network cable to the port with the static IP. I’m a little bit confused since I can’t see what’s happening on the device while I can’t login.

You can’t have two (default) gateways active at the same time, unless you give the routing subsystem additional data about it (metrics, routing tables etc.).

Do you actually need a gateway on the PLC port?

I’ll need to check with my colleagues. At the moment it seems like they’re connecting to a Gateway, which doesn’t make too much sense to me.

Just realized that this is not really snap specific now. But I would like to ask this follow-up question:

Let’s say I remove the Gateway from NIC 2 as proposed. NIC 1 is using DHCP from our business network. NIC 2 will not end up in the same network since the IP is defined by the PLC and must be configured accordingly. How does the system know that it should check the subnet of NIC 2 and not use the Gateway of NIC 1 if an IP outside of NIC 1’s netmask is called? Will it check the subnets of every NIC before using the Gateway?

It checks the routing table, you’ll have a situation like this:

$ ip route
default via <gateway> dev eth0 proto static 
<business network> dev eth0 proto kernel scope link src <business IP>
<plc network> dev eth1 proto kernel scope link src <PLC IP>

It will always prefer the direct route rather than the default gateway. But we’re going off topic here, there’s plenty of reading material out there about Linux routing :slight_smile:

1 Like