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 [email protected]
Failed to start [email protected]: Unit [email protected] 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

3
  • so, you're using archlinux documentation in raspbian and wondering why it doesn't work? what interfaces does your system have? Commented Aug 7, 2018 at 6:14
  • 1
    Of course, what you want to achieve is possible by simply editing /etc/dhcpcd.conf with appropriate information Commented Aug 7, 2018 at 6:15
  • @JaromandaX Yes. But it seems there is no unit files for separate interface on raspbian. Not sure if there is such files on arch because I don't have arch now. I do have eth0, wlan0 interfaces in the system which I can see in ip link show.
    – WayneWu411
    Commented Aug 7, 2018 at 7:08

3 Answers 3

2

I assume your question is "Fail to start [email protected]. 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
[email protected] 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 [email protected] 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.

6
  • Yes. There is no dhcpcd unit files for separate interfaces in Raspbian Stretch which is the cause of this failure. In my scenario, I want to have two modes of network setup. One is automatic dhcp on all interfaces which is OK if I make some configuration in dhcpcd.conf. Another one is manually dhcp on specific interfaces which means I would disable dhcpcd.service and start [email protected] manually without touching dhcpcd.conf. I don't think I can do this by dhcpcd.conf. Maybe I should try to add some unit files.
    – WayneWu411
    Commented Aug 8, 2018 at 0:49
  • @WayneWu I have updated my answer.
    – Ingo
    Commented Aug 8, 2018 at 7:17
  • This didn't do the task for me.
    – Enkum
    Commented Nov 9, 2020 at 8:38
  • @Enku What's the problem?
    – Ingo
    Commented Nov 9, 2020 at 9:30
  • 1
    @Enku I have updated Step 1 of the answer.
    – Ingo
    Commented Nov 9, 2020 at 19:57
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
1
  • 1
    good answer for Raspbian wheezy - not so much for Jessie and Stretch Commented Aug 7, 2018 at 6:31
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.