1

I want to have a DHCP server running on Arch Linux, but I'm having problems. I'm having an issue with getting dhcpd to start on boot. It will start ok when I manually run sudo systemctl start dhcpd@eth0.service when I've logged in.

I'm running the latest version of Arch Linux (4.7.0-1) and I've followed the Arch networking wiki to get this set up.

My setup

  • dhcpcd is disabled
  • I have used systemd-networkd to do the static ip (it is enabled), the config is (/etc/systemd/network/wired.network):

    [Match]
    Name=eth0
    
    [Network]
    Address=10.0.0.2/24
    Gateway=10.0.0.1
    
    • My /etc/dhcpd.conf is simple:

      option domain-name-servers 10.0.0.2;   
      option subnet-mask 255.255.255.0;   
      option routers 10.0.0.0.1;   
      subnet 10.0.0.0 netmask 255.255.255.0 {
          range 10.0.0.5 10.0.0.50;   
      }
      
  • I created my systemd service file (/etc/systemd/system/dhcpd4@.service) and enabled it with systemctl enable dhcpd4@eth0.service:

    [Unit]
    Description=IPv4 DHCP server on %I
    Wants=network.target
    After=network-pre.target
    Before=network.target
    
    [Service]
    Type=forking
    PIDFile=/run/dhcpd4.pid
    ExecStart=/usr/bin/dhcpd -4 -q -pf /run/dhcpd4.pid %I
    KillSignal=SIGINT
    
    [Install]
    WantedBy=multi-user.target
    

When I reboot I get an error in the start up that says (when i run journalctl -xe):

 No subnet declaration for eth0 (no IPv4 addresses).
 ** Ignoring requests on eth0....

Then when I run systemctl start dhcpd4@eth0.service it all runs fine no problems.

I've done a lot of googling but found no solution to this issue. I've tried tweaking the files (dhcpd.conf, dhcpd4@.service and wired.network) to hard code interfaces, add extra DHCP declarations, alter Unit wants etc and more; but nothing seems to work.

0

Are you trying to restrict dhcpd to only eth0? If not, you may simply use the standard systemd service file dhcpd4.service.

If you are, maybe try changing

After=network-pre.target
Before=network.target

to

After=network.target

This is also specified in the standard dhcpd4.service. It seems that dhcpd needs an active interface - which is not guaranteed if it is started before network.target.

  • I'm not explicitly trying to restrict it to just eth0, I only have one NIC so don't need to worry about it. As you suggested I can just have it as ...dhcpd4.service. With the After and Before, I did try changing these without any change in behaviour. I have managed to find the answer to this problem, which I've put below. – Johnny Aug 17 '16 at 11:27
0

I found the answer to the problem! The problem is that the boot process is trying to start DHCP service whilst the network is starting up/being configured, and so DHCP can't find an working interface to bind to. This is why it always worked when I ran the start dhcpd service manually and didn't work on boot.

I found a clue to the answer from this post: dhcp on arch linux - rasp-pi. The user used a restart declaration in the unit file, which made the service retry every 6 seconds until the service was up. - This temporary solution worked for me too.

I had a dig around the systemd web site on the special targets page and found this link to running services after the network is up. From this page's recommendations I made the following adjustments:

  • In the dhcpd4@.service unit file I removed the Before=..., changed After to After=network-online.target and changed Wants to Wants=network-online.target
  • I also enabled the systemd-networkd-wait-online.serviceto start on boot.

It now works on boot! However, the recommendations page does say that enabling systemd-networkd-wait-online.service does slow down your boot time and can do by 90 seconds (if I've read it correctly). Though I've only noticed about 1 or 2 seconds increase in boot time in my case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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