I have connected a USB network interface to my RPi 4 running Raspbian 10 Lite (headless) and I am trying to assign a fixed IP address to it. The onboard eth0
interface should continue to use DHCP as per default.
I tried the following, all of which failed:
- Add these lines to /etc/dhcpcd.conf + reboot:
interface eth1
static ip_address=192.168.60.10/24
- Add /etc/network/interfaces.d with the following content + reboot:
interface eth1
static ip_address=192.168.60.1/24
- Add the above lines directly to /etc/network/interfaces and reboot.
In all cases, eth1 remains unconfigured (no IP address), as witnessed by the output of ifconfig eth1:
eth1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:e0:4c:39:bf:d8 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
The only thing that seems to work is sudo ifconfig eth1 192.168.60.10/24
, but then the result is not persistent, and adding this command to /etc/rc.local
feels like a hack.
What is the correct way to do this?
eth1
should automatically get this fixed IP address when the USB network interface is plugged in.
EDIT: After some experiments triggered by suggestions from @seamus,
I realized that dhcpcd
does assign the requested address to eth1
, but only when a carrier is detected, i.e. when eth1
is physically connected to another device using an ethernet cable. This answers my original question.
There is an alternative way to do this, also suggested by @seamus: instead of static
, use inform
in dhcpcd.conf
. This has the added advantage that a dhcp server running on the 192.168.60.0/24
subnet is informed of the fixed IP, avoiding potential conflicts. In my case, there is no dhcp server, so this is irrelevant.
There is one remaining issue: connections to other hosts on the 192.168.60.0/24
subnet are not routed to eth1
. Since this is a different question, not about assigning a fixed IP, I posted a separate question: How to setup point-to-point ethernet connection to PLC in addition to standard network
man dhcpcd.conf
says "For IPv4, you should use theinform ipaddress
option instead of setting a static address." See these other Q&A: 1, 2, 3 – Seamus Jun 17 '21 at 15:49inform 192.168.60.10/24
works; thanks. I don't understand how: according to the dhcpcd documentation,inform
sends a message to the DHCP ser4ver, but there is no DHCP server on the network connected to eth1. It is intended to be a point-to-point connection, where the other host also has a fixed address. Also, after reading your references, I still don't understand why static does not work. There is no need for DNS on eth1, and the gateway is only reachable via eth0. – ygramoel Jun 17 '21 at 18:13static
address indhcpcd.conf
, for a network without DHCP server? I still have no clue what was wrong with my original configuration. – ygramoel Jun 21 '21 at 07:03dhcpcd
, typically to connect to a microcontroller or some other hardware device that is not intended to work on a general network. I am absolutely not the only person in the world doing something like that; it was quite common, at least in the kind of places where I used to work. – ygramoel Jun 23 '21 at 20:26/etc/network/interfaces
used to work fine, and automatically created the necessary entries in the routing table. My impression is thatdhcpcd
was not designed to handle that case, so requires "tricks" (like usinginform
instead ofstatic
) plus manual configuration for routing. – ygramoel Jun 23 '21 at 20:26man dhcpcd
, but is somewhat hidden under thenoup
option inman dhcpcd.conf
! – Seamus Jun 25 '21 at 06:36