CentOS: Set Up DHCP Service
To set up the DHCP service on CentOS, do the following:
-
Install dhcp client (as root / with
sudo
):yum install dhcp
. -
Edit the dhcp config file (/etc/dhcp/dhcpd.conf). Add the following, filling in the blanks. Anything in [square brackets] is optional:
subnet ___.___.___.___ netmask ___.___.___.___ {
option routers ___.___.___.___;
option subnet-mask ___.___.___.___;
[option domain-name "________.___";]
option domain-name-servers ___.___.___.___[, ___.___.___.___];
range ___.___.___.___ ___.___.___.___;
}
Example: if you had a network 192.0.2.0/24, with a router at 192.0.2.1, and the domain for
subnet 192.0.2.0 netmask 255.255.255.0 {
option routers 192.0.2.1;
option subnet-mask 255.255.255.0;
option domain-name "for.example";
option domain-name-servers 192.0.2.0/24;
range 192.0.2.128 192.0.2.254;
}
systemctl start dhcpd
, and set it to start at boot with systemctl enable dhcpd
.
- Allow the DHCP service through the firewall with the command
firewall-cmd --add-service=dhcp --permanent
, then reload the firewall withfirewall-cmd --reload
.