0

I have several network interfaces - eth0, eth1. ETH0 is connected to the isolated local network (with switch) and has 2 static IP addresses. It was configured using /etc/network/interfaces file and everything works pretty good.

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0

iface eth0 inet static
address 192.168.54.254
gateway 192.168.54.1
netmask 255.255.255.0
broadcast 192.168.0.255

auto eth0:1

iface eth0:1 inet static
address 192.168.168.110
gateway 192.168.168.1
netmask 255.255.255.0
broadcast 192.168.0.255

Interface ETH1 has to be connected to the Internet and need to use DHCP to get right IP address from the main router. When I run sudo systemctl status dhcpcd.service it is clearly visible that dhcpcd conflicting with /etc/network/interfaces.

Jun 03 13:09:17 raspberrypi systemd[1]: Starting dhcpcd on all interfaces...
Jun 03 13:09:17 raspberrypi dhcpcd[1210]: Not running dhcpcd because /etc/network/interfaces
Jun 03 13:09:17 raspberrypi dhcpcd[1210]: defines some interfaces that will use a
Jun 03 13:09:17 raspberrypi dhcpcd[1210]: DHCP client or static address

However, I have found one solution which works, but I am not sure if it is considered to be the best practice. When I execute sudo dhcpcd eth1 then I can start DHCP on eth1 only. My plan is to create a system service which will execute sudo dhcpcd eth1 on every startup.

I have seen on the internet that some people can execute sudo systemctl enable dhcpcd@eth1.service, but I don't have such a service, and I am getting an error:

Failed to enable unit: Unit file dhcpcd@eth1.service does not exist.

Is my approach with creating a custom service with sudo dhcpcd eth1 correct?

Oleksii
  • 103
  • 3

1 Answers1

1

No, your approach isn't correct. Raspbian uses dhcpcd instead of /etc/network/interfaces (which is considered deprecated) by default. But as you've already configured your statics IPs through that file, you can still add eth1 to it and enable DHCP for it. I.e. old-style, like this:

auto eth1
allow-hotplug eth1
iface eth1 inet dhcp

Just add those lines to the end of your /etc/network/interfaces and reboot.

This is actually considered a better approach from the Debian "makers" and dhcpcd.conf are considered unsafe. It also seems that it doesn't allows to create aliases in a normal way.

Or instead if you prefer to stick with dhcpcd, you can tell it not to mess with eth0 and only configure DHCP on eth1 in /etc/dhcpcd.conf:

denyinterfaces eth0

Please also see this question on the issue: https://raspberrypi.stackexchange.com/questions/45330/set-multiple-static-ip-in-dhcpcd-conf-raspbian-8-jessie

NStorm
  • 1,248
  • 7
  • 18