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?