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.
I configured the PLC to use 192.168.60.2 (fixed IP) and added the following lines to /etc/dhcpcd.conf
:
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 192.168.60.2
.
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 dhcpcd.conf
?