Installing and configuring DHCP server and client in Centos 7
Installing and configuring DHCP server and client in Centos 7
DHCP (English Dynamic Host Configuration Protocol) is a network protocol that allows computers to automatically obtain an IP address and other parameters necessary to operate on a TCP / IP network. This protocol works on a client-server model.
Setting up a DHCP server
DHCP server is available in the official repository. To install, run the command in the terminal
[[email protected]]# yum install dhcp
Next, you need to register the network interface for which the DHCP server will serve requests
[[email protected]]# nano /etc/sysconfig/dhcpd
DHCPDARGS=”eth0”
DHCP server configuration
The main DHCP server configuration file is located /etc/dhcp/dhcpd.conf Copy the template and open it for editing
[[email protected]]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[[email protected]]# nano /etc/dhcp/dhcpd.conf
option domain-name "domain.local";
option domain-name-servers ns1.domain.local, ns2.domain.local;
default-lease-time 3600;
max-lease-time 7200;
authoritative;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option domain-search "domain.local";
option domain-name-servers 192.168.1.1;
range 192.168.10.10 192.168.10.100;
range 192.168.10.110 192.168.10.200;
}
Let’s add the service to startup, start it and check the status
[[email protected]]# systemctl enable dhcpd
[[email protected]]# systemctl start dhcpd
[[email protected]]# systemctl status dhcpd
Let’s add an allowing rule for the firewall
[[email protected]]# firewall-cmd --zone=public --permanent --add-service=dhcp
[[email protected]]# firewall-cmd --reload
DHCP client configuration
Editing the network interface configuration file
[[email protected]]# nano /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
TYPE=Ethernet
ONBOOT=yes
Restart the network service
[[email protected]]# systemctl restart network