【Linux基础服务教程】DHCP服务
一、关于DHCP
1.DHCP服务
依赖DHCP软件包
# yum install -y dhcp
# rpm -q dhcp
dhcp-4.2.5-83.el7.centos.1.x86_64
配置文件
二、配置DHCP服务
1.关闭SELinux、防火墙、时间同步
# systemctl stop firewalld.service
# systemctl disable firewalld.service
# vi /etc/selinux/config
SELINUX=disabled
2.复制DHCP配置文件
[root@node01 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? yes
3.修改配置文件
[root@node01 ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.140.0 netmask 255.255.255.0 {
range 192.168.140.100 192.168.140.188;
option routers 192.168.140.2;
option domain-name-servers 114.114.114.114, 223.5.5.5;
}
4.设置服务开启自启
[root@node01 ~]# systemctl start dhcpd #启动服务
[root@node01 ~]# systemctl enable dhcpd #设置开启自启
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
[root@node01 ~]# netstat -tunlp | grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 17620/dhcpd #默认使用udp/67号端口
- DHCP默认服务端口是67/udp
- 默认发送端口是68/udp
5.验证DHCP服务
关闭虚拟机默认DHCP服务
第二台虚拟机设置网卡工作模式为DHCP
三、DHCP工作原理
1.DHCP Discovery 发现
2.DHCP Offer 提供
3.DHCP Request 请求
4.DHCP ACK 同意