1)配置DHCP服務器
安裝服務端
[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
option domain-name "servera.example.com"; //本機域名(如果沒有可以不寫)
option domain-name-servers "example.com"; //指向DNS(如果沒有可以不寫)
default-lease-time 600; //租約(s)
max-lease-time 7200; //最大租約(s)
authoritative;
subnet 172.25.0.0 netmask 255.255.255.0 {
range dynamic-bootp 172.25.0.100 172.25.0.200;
option broadcast-address 172.25.0.255;
option routers 172.25.0.1;
}
#設置網段,掩碼
#分發地址範圍
#廣播地址
#路由地址
[root@localhost ~]# systemctl restart dhcpd //重啓服務
[root@localhost ~]# systemctl enable dhcpd //開機自啓
ln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/multi-user.target.wants/dhcpd.service'
設置防火牆放行
[root@localhost ~]# firewall-cmd --add-service=dhcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
2)配置客戶端
確保UDP68端口可達網絡
[root@localhost ~]# nmcli connection modify "System eth0" ipv4.method auto //將IP地址設置爲自動獲取
[root@localhost ~]# nmcli connection down "System eth0" ; nmcli connection up "System eth0" //重新加載網卡