注意:以下四个实验,均要注意防火墙和Selinux对服务的影响:

1.简单的DHCP服务搭建

实验环境:两台虚拟机,使用桥接模式

DHCP服务器端IP地址:

DHCP(动态主机配置协议)实验:_第1张图片

安装软件:

wKiom1lIen7iwZ-KAAAznQme7Hw955.png

修改配置文件:

wKioL1lIen7yyOvxAAA0DcrMZUg597.png

DHCP(动态主机配置协议)实验:_第2张图片

客户端验证:(客户端的网卡配置成dhcp自动获取模式)

DHCP(动态主机配置协议)实验:_第3张图片


2.IP地址保留实验:

修改配置文件:

DHCP(动态主机配置协议)实验:_第4张图片

客户端验证:

DHCP(动态主机配置协议)实验:_第5张图片


3.超级域实验:

修改配置文件:

DHCP(动态主机配置协议)实验:_第6张图片

客户端验证:

DHCP(动态主机配置协议)实验:_第7张图片

DHCP(动态主机配置协议)实验:_第8张图片


4.DHCP中继代理实验:

说明:需要三台虚拟机:(一台DHCP服务器、一台作中继及路由转发,一台做客户机)

其中中继代理服务器需要添加两块网卡,实验环境DHCP机在VMnet10、DHCRelay在一块网卡在VMnet10、另一块在VMnet11、客户机则是处在VMnet11中。

DHCP(动态主机配置协议)实验:_第9张图片


(DHCP服务器端)DHCP服务器IP:

指定网关:

修改配置文件:

(DHCRelay)需要安装dhcp软件、并开启路由转发功能:

dhcrelay配置文件:(/etc/sysconfig/dhcrelay)

wKiom1lIe5SC4EG_AAAy5Ig2dXQ458.png

wKioL1lIe5XS9ASQAAAGQN28yLE486.png

DHCP(动态主机配置协议)实验:_第10张图片

(客户端验证)

DHCP(动态主机配置协议)实验:_第11张图片


本次试验所需知识点:

总结:

DHCP服务

    1、软件包:dhcp

    2、服务名:dhcpd(主程序)、dhcrelay(中继服务)

    3、端口:udp 67 udp 68

    4、配置文件:

           /etc/dhcp/dhcpd.conf 主配置文件

           /etc/sysconfig/dhcrelay 中继配置文件

           /usr/share/doc/dhcp*/dhcpd.conf.sample 主配置文件模板

    5、常见配置项

           ……

    6、搭建DHCP和DHCP中继服务

 

实验过程:

    搭建DHCP服务器:  

           服务器端:

           1、yum -y install dhcp

           2、cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

           3、vim /etc/dhcp/dhcpd.conf 删除多余配置,保留一个subnet区域

                       subnet 192.168.115.0 netmask 255.255.255.0 {

                             option routers 192.168.115.172;

                             option subnet-mask 255.255.255.0;

                             range 192.168.115.10 192.168.115.100;

                             default-lease-time 21600;

                       max-lease-time 23200;

                       }

           4、service dhcpd restart           

 

           客户端:

           1、vim /etc/sysconfig/network-scripts/ifcfg-eth0

                         DEVICE=eth0

                         ONBOOT=yes

                         BOOTPROTO=dhcp

           2、service network restart

 

    搭建DHCP中继服务:

           服务器端:

           1、yum -y install dhcp

           2、cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

           3、vim /etc/dhcp/dhcpd.conf 删除多余配置,保留一个subnet区域

                       subnet 192.168.1.0 netmask 255.255.255.0 {

                             option routers 192.168.1.2;

                             option subnet-mask 255.255.255.0;

                             option domain-name-servers 192.168.1.2;

                             range 192.168.1.10 192.168.1.100;

                             default-lease-time 21600;

                              max-lease-time 23200;

                       }

                              subnet 192.168.200.0 netmask 255.255.255.0 {

                             option routers 192.168.200.1;

                             option subnet-mask 255.255.255.0;

                             range 192.168.200.10 192.168.200.100;

                             default-lease-time 21600;

                              max-lease-time 23200;

                       }

           4、service dhcpd restart    

           5、route add default gw 192.168.1.2

 

           中继端:

           1、yum -y install dhcp

           2、vim /etc/sysctl.conf

                         ip.net.ipv4_forward 1

           3、sysctl -p

           4、vim /etc/sysconfig/dhcrelay

                         INTERFACE = "eth0  eth1"

                         DHCPSERVER = "192.168.115.179"

           5、service dhcrelay restart

          

           客户端:

           1、vim /etc/sysconfig/network-scripts/ifcfg-eth0

                         DEVICE=eth0

                         ONBOOT=yes

                         BOOTPROTO=dhcp

           2、service network restart