linux中DHCP服務分配固定IP地址
阿新 • • 發佈:2020-12-13
伺服器: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的服務。