1

I'm running latest Raspbian Stretch Lite (Released @ 2018-06-27) on 3B+ for a project. For network interface dhcp part, I want to enable & start dhcpcd on some specific interfaces instead of starting it on all. But when I run the following cmd in the shell, I got some error message:

pi@raspberrypi:~# sudo systemctl start dhcpcd@eth0.service
Failed to start dhcpcd@eth0.service: Unit dhcpcd@eth0.service not found.

I got the instruction on running this cmd from dhcpcd wiki page https://wiki.archlinux.org/index.php/dhcpcd#dhcpcd_and_systemd_network_interfaces.

The system is fresh burned to the SD card.

I can manually bring up all the interface (eth0, wlan0) with dhcpcd cmd and can also bring up them if I enable dhcpcd.service globally.

Appreciated if someone can help me on this.

Cheers, Wayne

WayneWu411
  • 13
  • 1
  • 3

3 Answers3

2

I assume your question is "Fail to start dhcpcd@eth0.service. Why?"

For interface specific unit files you must have a unit ending with @ before .device as you can see with, for example:

rpi ~$ systemctl list-unit-files *wpa*
UNIT FILE               STATE
wpa_supplicant.service  disabled
wpa_supplicant@.service indirect

dhcpcd has no such unit file. Verify with

rpi ~$ systemctl list-unit-files *dhcp*
UNIT FILE       STATE
dhcpcd.service  enabled
dhcpcd5.service enabled

So your command sudo systemctl start dhcpcd@eth0.service cannot work.

What you want to achieve is to setup DHCP only on specific devices. It seems you like to do it with systemd. It can easily be done with systemd-networkd. Because you haven't given any information about your network configuration I cannot give you specific advices. But here is an example with eth0 with a static ip address and wlan0 with getting its ip address by DHCP.

Step 1: Switch over to systemd-networkd

Just follow to Use systemd-networkd for general networking. You can use section "♦ Quick Step". Then come back here.

Step 2: Configure interfaces

Create these files for interfaces eth0 and wlan0 with your settings:

rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
Address=192.168.0.2/24
Gateway=192.168.0.1
DNS=8.8.8.8
EOF

rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF [Match] Name=wlan0 [Network] DHCP=yes EOF

Reboot.

For additional interfaces create a new /etc/systemd/network/<nn-if>.network file with its specific settings. Look at man systemd.network.

Seamus
  • 23,558
  • 5
  • 42
  • 83
Ingo
  • 42,961
  • 20
  • 87
  • 207
1

"I want to enable & start dhcpcd on some specific interfaces instead of starting it on all"


For such Usage would the config with /etc/network/interfaces fit more.

  1. First deactivate the interface for example ifdown eth0
  2. Open the Config file nano /etc/network/interfaces
  3. For example activate dhcp on eth0, add the followling line
    auto eth0
    iface eth0 inet dhcp
  4. Safe the file
  5. Bring up eth0 again ifup eth0
Weizzo
  • 11
  • 2
0

It is unclear from your question whether you wish to disable permanently or change from time to time.

Advanced dhcpcd Configuration in How to set up networking/WiFi discusses the more common settings which can be customised.

There is only ONE service file - if you need to change run sudo systemctl restart dhcpcd

Milliways
  • 62,573
  • 32
  • 113
  • 225