I have an RPi 3 running Raspbian 10 (Lite, headless). It is connected to my LAN via eth0 which is working fine.
Now I need to also connect the RPi to a PLC with very limited configuration options (basically: either DHCP client or fixed IP). I plugged in a USB Ethernet adapter, which shows up as eth1, and I am trying to configure a connection with fixed IP addresses.
Some background, as requested in the comments: a PLC is a Programmable Logic Controller, a device commonly used in industrial control applications. It doesn't really matter, the main point is that it is closed source and I have very limited configuration options: I can set it to use DHCP for IP configuration (i.e. as a DHCP client - it doesn't have a server), or assign a fixed IP and netmask.
Here is an attempt to depict the situation with ASCII graphics:
PLC (fixed IP 192.168.60.2; alternative: DHCP client) ^ | | v eth1 (fixed IP 192.168.60.1) RPi ^ eth0 (DHCP client, using default dhcpcd config) | | LAN with DHCP server + gateway to internet
I configured the PLC to use 192.168.60.2 (fixed IP) and added the following lines to
interface eth1 inform 192.168.60.1/24
ifconfig shows that eth1 does indeed get
192.168.60.1, but I can still not reach the PLC at
I suspect that messages to
192.168.60.2 are not routed to eth1:
pi@raspberrypi:~$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.0.1 0.0.0.0 UG 202 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0 pi@raspberrypi:~$
Manually adding a route fixes the problem:
pi@raspberrypi:~$ sudo route add -net 192.168.60.0 netmask 255.255.255.0 dev eth1 pi@raspberrypi:~$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.0.1 0.0.0.0 UG 202 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0 192.168.60.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 pi@raspberrypi:~$ ping 192.168.60.2 PING 192.168.60.2 (192.168.60.2) 56(84) bytes of data. 64 bytes from 192.168.60.2: icmp_seq=1 ttl=255 time=10.6 ms 64 bytes from 192.168.60.2: icmp_seq=2 ttl=255 time=2.23 ms
Is this the right way to do this, and if so, how do I automate this? Is there a better way, maybe by adding something to
One possible alternative would be to run a DHCP server on eth1 on the RPi, and configure the PLC as a DHCP client. The challenge would then be to make sure that the PLC always gets the same IP address, even if I replace it with a different PLC (different MAC address). Note: there will always be only one PLC; this is a point-to-point connection.
The reason why I made this a point-to-point connection separate from the LAN, is that the connection with the PLC needs to work even if there is no LAN (network down or misconfigured). I have very little control over the LAN, and the connection to the PLC needs to be very reliable.