大纲
一、BOOTP协议
二、DHCP协议
三、BOOTP与DHCP比较
四、DHCP工作流程图
五、DHCP服务器实现
一、BOOTP(Bootstrap Protocol)协议概念
BOOTP使用UDP报文传输,并使用保留端口号67(BOOTP服务器)和68(BOOTP客户端)工作。使用BOOTP协议的时候,一般包括Bootstrap Protocol Server(自举协议服务端)和Bootstrap Protocol Client(自举协议客户端)两部分。BOOTP的一般工作流程就是BOOTP客户端和BOOTP服务器之间的交互,其流程如下:
①由BOOTP启动代码来启动BOOTP客户端,这个时候BOOTP客户端还没有IP地址。
②BOOTP客户端使用广播形式的IP地址255.255.255.255向网络中发出IP地址查询要求。
③运行BOOTP协议的服务器接收到这个请求,会根据请求中提供的MAC地址找到BOOTP客户端,并发送一个含有IP地址、服务器IP地址、网关等信息的回应帧。
④BOOTP客户端会根据该回应帧来获得自己的IP地址并通过专用文件服务器(如TFTP服务器)下载启动镜像文件,模拟成磁盘来完成启动。
二、DHCP(Dynamic Host Configuration Protocol)协议概念
DHCP是一个局域网的网络协议,使用UDP协议工作, 主要有两个用途:给内部网络或网络服务供应商自动分配IP地址,给用户或者内部网络管理员作为对所有计算机作中央管理的手段,在RFC 2131中有详细的描述。DHCP有3个端口,其中UDP67和UDP68为正常的DHCP服务端口,分别作为DHCP Server和DHCP Client的服务端口;546号端口用于DHCPv6 Client,而不用于DHCPv4,是为DHCP failover服务,这是需要特别开启的服务,DHCP failover是用来做“双机热备”的。
三、BOOTP与DHCP比较
我们熟知的DHCP协议是从BOOTP的基础上发展而来的,它们都是主机配置协议,都可以大大减少管理员的工作量。BOOTP可以看成是简单版的DHCP,是对主机的静态配置,没有DHCP中租约的概念;而DHCP可以依据一些策略对主机进行动态配置。BOOTP用于无盘工作站的启动和配置,而DHCP更适用于客户端接入变化的网络,即客户端接入时间、接入地点不固定。
四、DHCP工作流程
五、DHCP服务器实现
1、安装DHCP服务器端
[root@CentOS5 ~]# yum remove -y "dhcp" Loaded plugins: fastestmirror, security Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package dhcp.x86_64 12:3.0.5-33.el5_9 set to be erased --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================== Package Arch Version Repository Size ======================================================================================================================================== Removing: dhcp x86_64 12:3.0.5-33.el5_9 installed 2.2 M Transaction Summary ======================================================================================================================================== Remove 1 Package(s) Reinstall 0 Package(s) Downgrade 0 Package(s) Downloading Packages: Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Erasing : dhcp 1/1 Removed: dhcp.x86_64 12:3.0.5-33.el5_9 Complete! [root@CentOS5 ~]# yum install -y "dhcp" Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile * epel: mirrors.ustc.edu.cn Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package dhcp.x86_64 12:3.0.5-33.el5_9 set to be updated --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================== Package Arch Version Repository Size ======================================================================================================================================== Installing: dhcp x86_64 12:3.0.5-33.el5_9 base 890 k Transaction Summary ======================================================================================================================================== Install 1 Package(s) Upgrade 0 Package(s) Total download size: 890 k Downloading Packages: dhcp-3.0.5-33.el5_9.x86_64.rpm | 890 kB 00:00 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : dhcp 1/1 Installed: dhcp.x86_64 12:3.0.5-33.el5_9 Complete!
2、修改配置文件
[root@CentOS5 ~]# cat /etc/dhcpd.conf # # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.sample #[root@CentOS5 ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf cp: overwrite `/etc/dhcpd.conf'? y [root@CentOS5 ~]# vim /etc/dhcpd.conf [root@CentOS5 ~]# cat /etc/dhcpd.conf ddns-update-style interim; ignore client-updates; subnet 172.16.0.0 netmask 255.255.0.0 { # --- default gateway option routers 172.16.1.1; option subnet-mask 255.255.0.0; option nis-domain "domain.org"; option domain-name "soysauce.om"; option domain-name-servers 172.16.1.110; option time-offset -18000; # Eastern Standard Time # option ntp-servers 192.168.1.1; # option netbios-name-servers 192.168.1.1; # --- Selects point-to-point node (default is hybrid). Don't change this unless # -- you understand Netbios very well # option netbios-node-type 2; range 172.16.1.150 172.16.1.180; default-lease-time 21600; max-lease-time 43200; # we want the nameserver to appear at a fixed address host ns { next-server marvin.redhat.com; hardware ethernet 12:34:56:78:AB:CD; fixed-address 207.175.42.254; } } [root@CentOS5 ~]# service dhcpd restart # 服务器端重新启动dhcpd服务 Stopping dhcpd: [ OK ] Starting dhcpd: [ OK ]
3、测试客户端能否动态获取地址
[root@CentOS6 ~]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: [ OK ]
注:可以看到这个地址是我们定义在地址池列表中最后一个。
4、给客户端使用保留地址
[root@CentOS5 ~]# vim /etc/dhcpd.conf [root@CentOS5 ~]# cat /etc/dhcpd.conf ddns-update-style interim; ignore client-updates; subnet 172.16.0.0 netmask 255.255.0.0 { # --- default gateway option routers 172.16.1.1; option subnet-mask 255.255.0.0; option nis-domain "domain.org"; option domain-name "soysauce.om"; option domain-name-servers 172.16.1.110; option time-offset -18000; # Eastern Standard Time # option ntp-servers 192.168.1.1; # option netbios-name-servers 192.168.1.1; # --- Selects point-to-point node (default is hybrid). Don't change this unless # -- you understand Netbios very well # option netbios-node-type 2; range 172.16.1.150 172.16.1.180; default-lease-time 21600; max-lease-time 43200; # we want the nameserver to appear at a fixed address host myhost { next-server marvin.redhat.com; hardware ethernet 00:0C:29:1B:6D:AF; # 此MAC定义为CentOS6主机的MAC地址 fixed-address 172.16.1.120; # 此保留地址不能是地址池列表中的 } } [root@CentOS5 ~]# service dhcpd restart # 服务器端重新启动dhcpd服务 Stopping dhcpd: [ OK ] Starting dhcpd: [ OK ] [root@CentOS6 ~]# service network restart # 客户端重启网络服务 Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: [ OK ]
注:可以看到此时使用的是我们定义的保留地址,而不是地址池列表中的地址
转载于:https://blog.51cto.com/soysauce93/1721964