Linux: CentOS: Set Up DHCP Service - eliminmax/cncs-journal GitHub Wiki
Meaning of different command prompts
Unix/Linux:$
: can be run as normal user
Unix/Linux:#
: must be run as root (or withsudo
)
Windows:>
: Command Prompt or PowerShell
Windows:PS>
: PowerShell only
Unix/Linux and Windows:$/>
,#/>
: Works in Windows and Unix/Linux.
To set up the DHCP service on CentOS, do the following:
-
Install dhcp:
# 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.example, and you wanted to reserve addresses 192.0.2.1 through 192.0.2.127 for static IP addresses, and you had a DNS server at 192.0.2.2, you'd want the following configuration:
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;
}
-
Start the service by running the command
systemctl start dhcpd
, and set it to start at boot withsystemctl 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
.