1. 安裝dhcp服務
yum install -y dhcp
2. host1
vi /etc/dhcp/dhcpd.failover
failover peer "dhcpfailover" { primary; address host1; port 647; peer address host2; peer port 647; max-response-delay 60; max-unacked-updates 10; mclt 1800; split 128; load balance max seconds 3; }
vi /etc/dhcp/dhcpd.conf
include "/etc/dhcp/dhcpd.failover";
default-lease-time 600; max-lease-time 7200; ddns-update-style none; authoritative; allow booting; allow bootp; option domain-name-servers ns1, ns2; subnet 192.168.1.0 netmask 255.255.255.0 { option routers 192.168.1.1; option subnet-mask 255.255.255.0; pool{ failover peer "dhcpfailover"; range 192.168.1.50 192.168.1.150; } }
3. host2
vi /etc/dhcp/dhcpd.failover
failover peer "dhcpfailover" { secondary; address host2; port 647; peer address host1; peer port 647; max-response-delay 60; max-unacked-updates 10; #mclt 1800; #split 128; load balance max seconds 3; }
從host1下載dhcpd.conf
scp host1:/etc/dhcp/dhcpd.conf /etc/dhcp/
4. 開通所需要的防火牆政策
firewall-cmd --permanent --zone=public --add-port=647/tcp firewall-cmd --permanent --zone=public --add-port=67/udp
5. 啟用dhcp服務
systemctl enable dhcpd
systemctl start dhcpd
6. 確認IP租用狀態
tail -n 30 /var/lib/dhcp/dhcpd.lease