OS: CentOS 7.6
DHCP IPv4 來源 >> https://www.zutuanxue.com/home/4/5_257
1. 關閉防火牆和selinux
systemctl stop firewalld.service
systemctl disable firewalld.service
vim /etc/selinux/config
SELINUX=enforcing 改為 SELINUX=disabled
reboot
2. 67端口來自於服務端,68端口來自於客戶端
3. 安裝DHCP > yum -y install dhcp
4. Server端必須配置當前DHCP網段中的一個靜態地址,才能啟動DHCP服務
5. 配置文件 /etc/dhcp/dhcpd.conf
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 10.10.1.0 netmask 255.255.255.0 {
range 10.10.1.1 10.10.1.253;
option domain-name-servers 202.106.0.20, 114.114.114.114;
option routers 10.10.1.254;
option broadcast-address 10.10.1.255;
default-lease-time 7200;
max-lease-time 10800;
}
6. 保留地址方式,讓固定機器的IP保持不變
在配置文件末尾加入以下內容
host print {
hardware ethernet <MAC address>
fixed-address <IP address>
}
host print host為指令,print是個名字,隨便起,但是最好有意義,要不過一段你也記不住了。
hardware ethernet 指定以太網網卡MAC地址
fixed-address 指定要綁定的IP
7. 查看DHCP租約地址信息 /var/lib/dhcpd/dhcpd.leases
8. 超級作用域,支持多個網段分發IP
修改配置文件內容
shared-network supper {
subnet ...{
}
subnet ...{
}
}
DHCP IPv6
1. 配置dhcpd6.conf文件,vim /etc/dhcp/dhcpd6.conf
2. 安裝radvd, yum -y install radvd. 配置radvd.conf, vim /etc/radvd.conf
3. 服務端需要先配置當前網段的任意一靜態ipv6地址,否則無法啟動dhcpd6服務
4. 啟動服務,systemctl start dhcpd6、systemctl start radvd
5. server端添加ipv6轉發功能,echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
5. 查看server與client是否能正常通信