Skip to content

Instantly share code, notes, and snippets.

@ReeseWang
Created October 13, 2019 10:49
Show Gist options
  • Save ReeseWang/01903f478c710eb1c6ecf1767bd8cce8 to your computer and use it in GitHub Desktop.
Save ReeseWang/01903f478c710eb1c6ecf1767bd8cce8 to your computer and use it in GitHub Desktop.
Systemd service file for starting a DHCP server on a specific interface with a separate lease file, modified from the dhcp package from Arch Linux.
[Unit]
Description=IPv4 DHCP server on %i
After=network.target network-online.target
Wants=network-online.target
[Service]
Type=forking
ExecStartPre=/usr/bin/touch /var/lib/dhcp/dhcpd@%i.leases
ExecStart=/usr/bin/dhcpd -4 -q -cf /etc/dhcpd.conf.d/%i.conf -pf /run/dhcpd4/dhcpd@%i.pid -lf /var/lib/dhcp/dhcpd@%i.leases %i
RuntimeDirectory=dhcpd4
PIDFile=/run/dhcpd4/dhcpd@%i.pid
User=dhcp
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_RAW
ProtectSystem=full
ProtectHome=on
KillSignal=SIGINT
# We pull in network-online.target for a configured network connection.
# However this is not guaranteed to be the network connection our
# networks are configured for. So try to restart on failure with a delay
# of two seconds. Rate limiting kicks in after 12 seconds.
RestartSec=2s
Restart=on-failure
StartLimitInterval=12s
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment