0

I'm trying to setup DHCP server on Raspberry Pi on Arch Linux, but I'm having small problems starting it properly after boot.

My dhcpd.conf is:

    authoritative;
    ddns-update-style standard;
    ignore client-updates;

    subnet 192.168.66.0 netmask 255.255.255.0 {
      range 192.168.66.100 192.168.66.199;
      option subnet-mask 255.255.255.0;
      option routers 192.168.66.2;
      option domain-name "foo.local";
      option domain-name-servers 8.8.8.8, 8.8.4.4;
      default-lease-time 1200;
      max-lease-time 1200;
    }

The dhcpd4.service:

    [Unit]
    Description=IPv4 DHCP server
    After=network.target

    [Service]
    Type=forking
    PIDFile=/run/dhcpd4.pid
    ExecStart=/usr/sbin/dhcpd -4 -q -pf /run/dhcpd4.pid
    KillSignal=SIGINT

    [Install]
    WantedBy=multi-user.target

But after the Raspberry Pi is rebooted I get:

    * dhcpd4.service - IPv4 DHCP server
       Loaded: loaded (/usr/lib/systemd/system/dhcpd4.service; enabled)
       Active: failed (Result: exit-code) since Thu 1970-01-01 01:00:13 CET; 44 years 6 months ago
      Process: 117 ExecStart=/usr/sbin/dhcpd -4 -q -pf /run/dhcpd4.pid (code=exited, status=1/FAILURE)

    Jan 01 01:00:13 x2raspi dhcpd[117]: Wrote 0 deleted host decls to leases file.
    Jan 01 01:00:13 x2raspi dhcpd[117]: Wrote 0 new dynamic host decls to leases file.
    Jan 01 01:00:13 x2raspi dhcpd[117]: Wrote 4 leases to leases file.
    Jan 01 01:00:13 x2raspi dhcpd[117]:
    Jan 01 01:00:13 x2raspi dhcpd[117]: Not configured to listen on any interfaces!

Forcing eth0 (the network card):

    * dhcpd4.service - IPv4 DHCP server
       Loaded: loaded (/usr/lib/systemd/system/dhcpd4.service; enabled)
       Active: failed (Result: exit-code) since Thu 1970-01-01 01:00:13 CET; 44 years 6 months ago
      Process: 117 ExecStart=/usr/sbin/dhcpd -4 -q -pf /run/dhcpd4.pid eth0 (code=exited, status=1/FAILURE)

    Jan 01 01:00:13 x2raspi dhcpd[117]: Wrote 0 deleted host decls to leases file.
    Jan 01 01:00:13 x2raspi dhcpd[117]: Wrote 0 new dynamic host decls to leases file.
    Jan 01 01:00:13 x2raspi dhcpd[117]: Wrote 4 leases to leases file.
    Jan 01 01:00:13 x2raspi dhcpd[117]:
    Jan 01 01:00:13 x2raspi dhcpd[117]: No subnet declaration for eth0 (no IPv4 addresses).
    Jan 01 01:00:13 x2raspi dhcpd[117]: ** Ignoring requests on eth0.  If this is not what
    Jan 01 01:00:13 x2raspi dhcpd[117]: you want, please write a subnet declaration
    Jan 01 01:00:13 x2raspi dhcpd[117]: in your dhcpd.conf file for the network segment
    Jan 01 01:00:13 x2raspi dhcpd[117]: to which interface eth0 is attached. **
    Jan 01 01:00:13 x2raspi dhcpd[117]:

I believe it's because it starts before the IP address from /etc/netctl/eth0 was fully assigned. The eth0 file is:

    Description='A basic static ethernet connection'
    Interface=eth0
    Connection=ethernet
    IP=static
    Address='192.168.66.4/24'
    Gateway='192.168.66.2'
    DNS=('8.8.8.8' '8.8.4.4')
    ExecUpPost='/usr/bin/ntpd -gq || true'

    ## for DHCPv6
    #IP6=dhcp
    ## for IPv6 autoconfiguration
    IP6=stateless

Is it really because the IP address has not yet been configured? And if so, how I can make it start after it's configured (I tried also network-online.target, but that didn't help)?

2

I had just the same problem yesterday. Actually solved it. My problem at least was, that alarmpi uses ifplugd to assign the netctl profile. This means that at the time of network.target your wired connection is up, but ifplugd had no time to load the profile then so you do have no ip at that time. You could try to delay the loading of dhcpd a little until the profile is loaded, but I do not consider that a good way because I do not see any target for that purpose.

In my setup, because the wired connection is the only one, my pi is ever gonna see, I do not need multiple netctl profiles and thus I do not need ifplugd. Luckily getting rid of it is quite simple:

Try the following:

Add the following line to your /etc/netctl/eth0 file:

SkipNoCarrier=yes

Then you run the following:

systemctl disable netctl-ifplugd@eth0.service
netctl enable eth0

This disables the ifplugd resulting in the profile eth0 being on all the time. SkipNoCarrier=yes is needed now, because your profile can get loaded before you actually have the wired connection so netctl will not fail then.

Check if everything works, if It does you might want to get rid of ifplugd completely and not just deactivating the systemd target. Just do this by running

pacman -Rcs ifplugd

and just because you will not need a dhcp client you should also consider removing dhcpcd.

Hope, that helps!

1

I solved it at the end with "temporary" solution. I changed my dhcpd4.service file to restart the service if it fails. It fails when starting and it's the restarted so it's "solved" after. Not a best solution, but works. In [Service] section:

Restart=always
RestartSec=6
1

I had this problem too on a VM, and using what you guys have posted I have come also come up with a solution.

My solution:

I found 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.

@cincura.net's restart declaration in the unit file solution worked for me too. So 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 my 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.

  • Please detail your solution in your post, just in case the contents of that link disappear or get altered. – tlhIngan Aug 17 '16 at 15:03
  • More info added – Johnny Aug 17 '16 at 16:04

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.