Dynamic Host Configuration Protocol (DHCP) allows client machines to automatically obtain network configuration information from a DHCP server each time they connect to the network. The DHCP server is configured with a range of IP addresses and other network configuration parameters.

 

When the client machine is configured to use DHCP, the client daemon, dhclient, contacts the server daemon, dhcpd, to obtain the networking parameters. Because DHCP is broadcast based, both the client and the server must be on the same subnet.

 

The advantages of using DHCP include ease of adding a new client machine to the network and centralized management of IP addresses. In addition, the number of total IP addresses needed is reduced because IP addresses can be reused. DHCP is also useful if you want to change the IP addresses of a large number of systems. Instead of reconfiguring each system individually, edit the DHCP configuration file on the server and enter the new set of IP addresses.

 

Configuring DHCP server

 

To configure a system as a DHCP server, install the dhcp package:

# yum install dhcp

 

The main configuration file for DHCP is /etc/dhcp/dhcpd.conf. Use this file to store network information for the clients. A sample configuration file is also installed with the dhcp package: /usr/share/doc/dhcp-[version]/dhcpd.conf.sample. You can copy this file to /etc/dhcp/dhcpd.conf and use it as a template. Refer the post below to get details on configuration parameters in the configuration file /etc/dhcp/dhcpd.conf.

 

Start/Stop DHCP server

 

Use the systemctl command to enable the dhcpd service to start at boot time:

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

 

Notice that the command enables a service by creating a symbolic link for the lowest-level system-state target at which the service starts. In the example, the command creates the symbolic link dhcpd.service for the multi-user target.

 

Use the systemctl command to disable the dhcpd service from starting at boot time. The symbolic link is removed when the service is disabled:

# systemctl disable httpd
rm ‘/etc/systemd/system/multi-user.target.wants/httpd.service’

 

Use the systemctl command to start the dhcpd service:

# systemctl start httpd

 

The dhcpd service fails to start if the /var/lib/dhcpd/dhcpd.leases file does not exist. You can use the touch command to create the file. The dhcpd.leases file stores the client lease information. Do not edit this file manually.

 

Configuring DHCP client

 

1. To configure a system as a DHCP client, install the dhclient package:

# yum install dhclient

 

2. Change the BOOTPROTO directive in the /etc/sysconfig/network-scripts/ifcfg-[interface] file for the device to dhcp. For example, to use DHCP on ens33, perform the following:

# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=bbe539aa-5042-4d28-a0e6-2a4d4f5dd744
DEVICE=ens33
ONBOOT=no
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

 

3. You also need to restart the network service on the DHCP client.

# systemctl restart network

 

4. The next time the client system connects to the network, dhclient requests a lease from the DHCP server and configures the client’s network interface. You can also run dhclient from the command line to request a lease and make a connection:

# dhclient

 

5. To request on a specific interface, include the interface as an argument. The following example only requests a lease for ens33:

# dhclient ens33

 

The DHCP client configuration file, /etc/dhcp/dhclient.conf, is required only for custom configurations. A sample file exists in /usr/share/doc/dhclient-[version]/dhclient.conf.example. When the client has requested and established a lease, information about the lease is stored in /var/lib/dhclient/dhclient.leases. For Example:

# cat /var/lib/dhclient/dhclient.leases
lease {
  interface "ens33";
  fixed-address 192.168.219.149;
  option subnet-mask 255.255.255.0;
  option routers 192.168.219.2;
  option dhcp-lease-time 1800;
  option dhcp-message-type 5;
  option domain-name-servers 192.168.219.2;
  option dhcp-server-identifier 192.168.219.254;
  option broadcast-address 192.168.219.255;
  option domain-name "localdomain";
  renew 5 2017/10/20 06:50:39;
  rebind 5 2017/10/20 07:02:37;
  expire 5 2017/10/20 07:06:22;
}

 

Bu cavab sizə kömək etdi? 0 istifadəçi bunu faydalı hesab edir (0 səs)