DHCP安装
[root@localhost ~]# yum install -y dhcp
DHCP配置文件
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
# DHCP server to understand the network topology.
subnet 10.152.187.0 netmask 255.255.255.0 {
}
subnet 192.168.1.0 netmask 255.255.255.0 {
} //本地网段
DHCP启动
[root@localhost ~]# systemctl enable dhcpd //设置开机启动
[root@localhost ~]# systemctl start dhcpd //dhcp启动时一定要有一个作用域与本地网段相符
[root@localhost ~]# lsof -i :67
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dnsmasq 1705 nobody 3u IPv4 31020 0t0 UDP *:bootps
dhcpd 3553 dhcpd 7u IPv4 53311 0t0 UDP *:bootps
DHCP作用域
subnet 定义一个作用域
netmask 定义作用域的掩码
range 允许发放的IP范围
option routers 指定网关地址
option domain-name-servers 指定DNS服务器地址
option broadcast-address 广播地址
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.50;
option routers 192.168.1.254;
option broadcast-address 192.168.1.255;
}
DHCP保留域
host 为指令
fanstasia 是个名字,随便起
hardware ethernet 指定客户机以太网网卡的MAC地址
fixed-address 指定要绑定的IP地址
option host-name 指定客户机的主机名(需要再客户机上 清空/etc/hostname文件的内容)
host fantasia {
hardware ethernet 00:0c:29:8e:ea:62;
fixed-address 192.168.11.250;
option host-name "testname";
}
查看租约
租约路径:/var/lib/dhcpd/dhcpd.leases
lease 192.168.1.11 {
starts 4 2023/05/04 11:00:55;
ends 4 2023/05/04 23:00:55;
tstp 4 2023/05/04 23:00:55;
cltt 4 2023/05/04 11:00:55;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 00:0c:29:a6:65:2a;
}
DHCP超级作用域
将两个或两个以上的不同网段的作用域合成一个作用域
shared-network 开启一个超级作用域
shared-network suppernet {
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.10;
option routers 192.168.1.254;
option broadcast-address 192.168.1.255;
}
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.10 192.168.2.10;
option routers 192.168.2.254;
option broadcast-address 192.168.2.255;
}
}