In many environments you’ll need to tweak how your DHCP server daemon (dhcpd) starts—whether it’s to bind to a specific interface, point to a custom config file, enable debug logging or change the listening port. On CentOS/RHEL 7 the DHCP service is managed by systemd, so you won’t edit /etc/init.d scripts—instead you’ll create a systemd unit override that adds exactly the command-line flags you need.

 

In this guide you’ll learn how to:

  1. Copy the original dhcpd.service into /etc/systemd/system/ for safe editing

  2. Add common dhcpd options such as -cf (config file), -lf (lease file), -p (port), -f (foreground) and -d (debug) to the ExecStart line

  3. Reload systemd, restart the DHCP service, and verify your new settings are in effect

By following these straightforward steps—even if you’re new to Linux—you’ll have a DHCP server that starts exactly the way your network requires. For a full beginner’s walkthrough on installing and configuring both DHCP server and client, see our “Beginners Guide to DHCP” article.

 

Specifying command-line arguments and options while starting dhcpd service

 

1. To specify command-line arguments and options when the dhcpd service is started, copy the /usr/lib/systemd/system/dhcpd.service file to the /etc/systemd/system/ directory:

# cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/

 

2. You can then edit the /etc/systemd/system/dhcpd.service file and append command-line arguments and options to the ExecStart line. For example, if your DHCP server has multiple network interfaces (eth0, eth1, eth2) but you want only the dhcpd service to listen for DHCP requests on eth2, include eth2 as a command-line argument:

# vi /etc/systemd/system/dhcpd.service ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user
dhcpd -group dhcpd --no-pid eth2

 

3. When you enable the service to start at boot time, a symbolic link is created to the dhcpd.service file in the /etc/systemd/system/ directory rather than the file in the /usr/lib/systemd/system/ directory:

# systemctl enable dhcpd
ln –s ‘/etc/systemd/system/dhcpd.service’ ‘/etc/systemd/system/multi-user.target.wants/dhcpd.service’

 

Refer to the dhcpd man page for additional command-line options and arguments. Some of the most commonly available options are described below:

 

-p [port]: Specifies the UDP port number on which dhcpd listens. The default is port 67.

-f: Runs the dhcpd as a foreground process instead of a background daemon. This is helpful when debugging a problem.

-d: Logs the DHCP server daemon to the standard error descriptor. This is helpful when debugging. If this is not specified, dhcpd logs all output using syslog.

-cf [filename]: Specifies the location of the configuration file. The default configuration file is /etc/dhcp/dhcpd.conf.

-lf [filename]: Specifies the location of the lease database file. The default lease file is /var/lib/dhcpd/dhcpd.leases.

-q: Specifies to be quiet at startup. This suppresses printing of the entire copyright message when starting the daemon.

–no-pid: Disables writing pid (Process ID) files. With this option, the service does not check for an existing server process.

 

Bu cevap yeterince yardımcı oldu mu? 0 Bu dökümanı faydalı bulan kullanıcılar: (0 Oy)