在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在DHCP协议中有个术语是“预约”,它用来确保局域网中特定的设备总是获取到固定的IP地址。换句话说,就是dhcpd服务程序会把某个IP地址私藏下来,只将其用于相匹配的特定设备。 要想把某个IP地址与某台主机进行绑定,就需要用到这台主机的MAC地址。MAC地址是网卡上面的一串独立的标识符,具备唯一性,因此不会存在冲突的情况,如图14-6所示。
图14-6 查看运行Linux系统的主机MAC地址 在Linux系统或Windows系统中,都可以通过查看网卡的状态来获知主机的MAC地址。在dhcpd服务程序的配置文件中,按照如下格式将IP地址与MAC地址进行绑定。
host 主机名称 { [root@linuxprobe ~]# tail -f /var/log/messages Mar 30 05:33:17 localhost dhcpd: Copyright 2004-2013 Internet Systems Consortium. Mar 30 05:33:17 localhost dhcpd: All rights reserved. Mar 30 05:33:17 localhost dhcpd: For info, please visit https://www.isc.org/software/dhcp/ Mar 30 05:33:17 localhost dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file Mar 30 05:33:17 localhost dhcpd: Wrote 0 leases to leases file. Mar 30 05:33:17 localhost dhcpd: Listening on LPF/eno16777728/00:0c:29:c4:a4:09/192.168.10.0/24 Mar 30 05:33:17 localhost dhcpd: Sending on LPF/eno16777728/00:0c:29:c4:a4:09/192.168.10.0/24 Mar 30 05:33:17 localhost dhcpd: Sending on Socket/fallback/fallback-net Mar 30 05:33:26 localhost dhcpd: DHCPDISCOVER from 00:0c:29:27:c6:12 via eno16777728 Mar 30 05:33:27 localhost dhcpd: DHCPOFFER on 192.168.10.50 to 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPDISCOVER from 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPOFFER on 192.168.10.50 to 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPREQUEST for 192.168.10.50 (192.168.10.10) from 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPACK on 192.168.10.50 to 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 之前我在线下讲课时,讲完DHCP服务后总是看到有些学员在挠头。起初我很不理解,毕竟dhcpd服务程序是Linux系统中一个很简单的实验,总共就那么十几行的配置参数还能写错?后来发现了原因—有些学员是以Windows系统为对象做的IP与MAC地址的绑定实验。而在Windows系统中看到的MAC地址,其格式类似于00-0c-29-27-c6-12,间隔符为减号(-)。但是在Linux系统中,MAC地址的间隔符则变成了冒号(:)。 [root@linuxprobe ~]# 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.50 192.168.10.150; 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 linuxprobe { hardware ethernet 00:0c:29:27:c6:12; fixed-address 192.168.10.88; } } 确认参数填写正确后就可以保存退出配置文件,然后就可以重启dhcpd服务程序了。 [root@linuxprobe ~]# systemctl restart dhcpd 需要说明的是,如果您刚刚为这台主机分配了IP地址,则它的IP地址租约时间还没有到期,因此不会立即换成新绑定的IP地址。要想立即查看绑定效果,则需要重启一下客户端的网络服务,如图14-7所示。
图14-7 重启客户端的网络服务,查看绑定效果 |
请发表评论