DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议
dhcp服务器端监控端口67
涉及的配置文件:/etc/dhcp/dhcpd.conf
实验环境:
vmware workstation 11
centos : 192.168.10.10
windows xp :?
centos 与windows xp 分别只连接到VMnet8上面 #此处VMware8可以理解为一个单独的交换机
基础命令:
1:查看开机启动项:
1 [root@cooca ~]# chkconfig --list | grep dhcpd
2 dhcpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3 dhcpd6 0:off 1:off 2:off 3:off 4:off 5:off 6:off
2:查看端口是否打开:
1 [root@cooca ~]# netstat -anulp | grep :67
2 udp 0 0 0.0.0.0:67 0.0.0.0:*
3:查看服务状态:
1 [root@cooca ~]# service dhcpd status
2 dhcpd (pid 2872) is running...
简单说明:
小型公司一般192.168.1.0/24基本上够用了,一般路由器也有dhcp功能,所以linux搭建dhcp可能用在大中型公司,那么这就涉及到多网段ip地址动态分配。
这里仅研究linux搭建dhcp功能的实现,至于更实用的多网段可用性,实用性方面暂且不谈。
配置过程:
1:配置静态ip地址:
192.168.10.10/24
主机名:
cooca.com
2:dhcp服务套件查询:
1 [root@cooca ~]# rpm -qa | grep dhcp
2 dhcp-common-4.1.1-43.P1.el6.centos.1.x86_64
3 dhcp-4.1.1-43.P1.el6.centos.1.x86_64
3:vi编辑:
1 [root@cooca ~]# cat /etc/dhcp/dhcpd.conf
2 #
3 # DHCP Server Configuration file.
4 # see /usr/share/doc/dhcp*/dhcpd.conf.sample
5 # see 'man 5 dhcpd.conf'
6 #
7 default-lease-time 600;
8 max-lease-time 7200;
9
10 option domain-name "cooca.com";
11 option domain-name-servers 192.168.10.10;
12 authoritative;
13
14 subnet 192.168.10.0 netmask 255.255.255.0 {
15 range dynamic-bootp 192.168.10.130 192.168.10.150;
16 option broadcast-address 192.168.10.255;
17 option routers 192.168.10.1;
18 }
其中:authoritative:拒绝不合法ip请求
4:查看windwos xp ip获取状态:
5:ping dhcp主机确认网络连接状态:
6:系统日志查看:
1 [root@cooca ~]# tali /var/log/messages
2 bash: tali: command not found
3 [root@cooca ~]# tail /var/log/messages
4 Jul 5 00:49:53 cooca dhcpd: DHCPACK on 192.168.10.130 to 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
5 Jul 5 00:54:53 cooca dhcpd: DHCPREQUEST for 192.168.10.130 from 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
6 Jul 5 00:54:53 cooca dhcpd: DHCPACK on 192.168.10.130 to 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
7 Jul 5 00:59:53 cooca dhcpd: DHCPREQUEST for 192.168.10.130 from 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
8 Jul 5 00:59:53 cooca dhcpd: DHCPACK on 192.168.10.130 to 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
9 Jul 5 01:04:53 cooca dhcpd: DHCPREQUEST for 192.168.10.130 from 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
10 Jul 5 01:04:53 cooca dhcpd: DHCPACK on 192.168.10.130 to 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
11 Jul 5 01:09:53 cooca dhcpd: Wrote 1 leases to leases file.
12 Jul 5 01:09:53 cooca dhcpd: DHCPREQUEST for 192.168.10.130 from 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
13 Jul 5 01:09:53 cooca dhcpd: DHCPACK on 192.168.10.130 to 00:0c:29:2a:a2:6d (zkero-661eadb17) via eth0
其中可以看到:日志中显示的mac地址:00:0c:29:2a:a2:6d与zkero-661eadb17以及ip地址和查看xp系统mac地址与计算机名以及ip地址是一致的。