linux中DHCP服务分配固定IP地址
服务器:PC1
客户端:PC2
1、查看PC2客户机MAC地址
[root@PC2 network-scripts]# ifconfig | head -n 5
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.100 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe25:bb3e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:25:bb:3e txqueuelen 1000 (Ethernet)
RX packets 337 bytes 46180 (45.0 KiB)
2、在服务器中修改dhcp服务配置文件
[root@PC1 ~]# vim /etc/dhcp/dhcpd.conf
ddns-update-style none;
ignore client-updates;
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200;
option subnet-mask 255.255.255.0;
option routers 192.168.10.1;
option domain-name "linuxprobe.com";
option domain-name-servers 192.168.10.1;
default-lease-time 21600;
max-lease-time 43200;
host PC2 {
hardware ethernet 00:0c:29:25:bb:3e;
fixed-address 192.168.10.188;
}
}
3、 查看PC2客户机IP
[root@PC2 network-scripts]# ifconfig | head -n 3
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.100 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe25:bb3e prefixlen 64 scopeid 0x20<link>
4、在PC1服务器主机中重启DHCP服务,在PC2中重启网卡服务,检查PC2主机IP是否改变
[root@PC1 ~]# systemctl restart dhcpd
[root@PC1 ~]# systemctl status dhcpd
dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled)
Active: active (running) since Sun 2020-12-13 18:22:20 CST; 10s ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 34170 (dhcpd)
CGroup: /system.slice/dhcpd.service
└─34170 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
[root@PC2 network-scripts]# systemctl restart network
[root@PC2 network-scripts]# ifconfig | head -n 5
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.188 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe25:bb3e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:25:bb:3e txqueuelen 1000 (Ethernet)
RX packets 355 bytes 48547 (47.4 KiB)
以上实验实现了给PC2客户机分配固定IP192.168.10.188的服务。