DHCP(Dynamic Host Configuration Protocol),动态主机配置协议,是一个应用层协议。当我们将客户主机ip地址设置为动态获取方式时,DHCP服务器就会根据DHCP协议给客户端分配IP,使得客户机能够利用这个IP上网。
DHCP的前身是BOOTP协议(Bootstrap Protocol),BOOTP被创建出来为连接到网络中的设备自动分配地址,后来被DHCP取代了,DHCP比BOOTP更加复杂,功能更强大。后面可以看到,在用Wireshark过滤显示DHCP包,需要输入过滤条件BOOTP,而不是DHCP,但或许是因为我使用的Wireshark版本是比较旧的1.12.9,没有在新版本中尝试过,也许可以输入DHCP让其只显示DHCP包
实验环境
centos6.5_x64
实验软件
dhclient-4.1.1-53.P1.el6.centos.1.x86_64.rpm
dhcp-4.1.1-53.P1.el6.centos.1.x86_64.rpm
hcp-common-4.1.1-53.P1.el6.centos.1.x86_64.rpm
dhcp-devel-4.1.1-53.P1.el6.centos.1.x86_64.rpm
dhcpdump-1.7-1.el6.rf.x86_64.rpm
dhcping-1.2-13.el6.x86_64.rpm
portreserve-0.0.4-11.el6.x86_64.rpm
软件安装
mount /dev/cdrom /mnt/
find /mnt/Packages/ -name *dhcp*
/mnt/Packages/dhcp-4.1.1-53.P1.el6.centos.x86_64.rpm
/mnt/Packages/dhcp-common-4.1.1-53.P1.el6.centos.x86_64.rpm
/mnt/Packages/sblim-cmpi-dhcp-1.0-1.el6.x86_64.rpm
mkdir dhcp
cp /mnt/Packages/dhcp-*.rpm /root/dhcp/
cp /mnt/Packages/sblim-cmpi-dhcp-1.0-1.el6.x86_64.rpm /root/dhcp/
rpm -ivh /root/dhcp/dhcp-*.rpm 以上几步操作为光盘挂载安装dhcp服务安装包的方法
yum install -y dhcp* 使用yum方式安装
/etc/rc.d/init.d/dhcpd start
Starting dhcpd: [FAILED]
less /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample 没有配置文件需要复制一份
# see 'man 5 dhcpd.conf'
#
cp -rv /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200;
} 模板复制和现实网络配置有出入需要修改成现实网络的配置
host passacaglia {
hardware ethernet 0:0:c0:5d:bd:95; 模板mac地址需要修改为本机网卡mac地址
filename "vmunix.passacaglia";
server-name "toccata.fugue.com";
}
# A slightly different configuration for an internal subnet.
subnet 192.168.1.0 netmask 255.255.255.0 { dhcp网段 子网掩码
range 192.168.1.10 192.168.1.100; dhcp地址池
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org"; dhcp域名
option routers 192.168.1.1; dhcp网关
option broadcast-address 192.168.1.254; 广播地址
default-lease-time 600;
max-lease-time 7200;
}
host passacaglia {
hardware ethernet 00:0C:29:45:17:69; 物理网卡mac地址
filename "vmunix.passacaglia";
server-name "toccata.fugue.com";
} 修改为
service dhcpd restart
Starting dhcpd: [ OK ]
测试一台linux测试机,ip为自动获得看dhcp服务端有没有分配ip
本文转自 mailfile 51CTO博客,原文链接:http://blog.51cto.com/mailfile/1199150,如需转载请自行联系原作者