DHCP服务器只作用于局域网同一网段内,客户端是通过广播消息来获得DHCP服务器响应后才能得到IP地址的,但广播消息不能跨越子网,那么如何让客户端获取到DHCP服务器提供的IP地址呢?这就是DHCP中继服务器的功能了。

实验拓扑图:

实验环境:

DHCP服务器:CentOS Linux release 7.3.1611

DHCP中继代理:CentOS Linux release 7.3.1611

客户端:CentOS 6.9

1、DHCP服务器配置

(1)、配置DHCP服务器的网络参数

  1. [root@host02 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
  2.  
  3. TYPE="Ethernet"
  4. BOOTPROTO="static"
  5. IPADDR=192.168.8.250
  6. NETMASK=255.255.255.0
  7. GATEWAY=192.168.8.254
  8. DEFROUTE="yes"
  9. PEERDNS="yes"
  10. PEERROUTES="yes"
  11. IPV4_FAILURE_FATAL="no"
  12. IPV6INIT="yes"
  13. IPV6_AUTOCONF="yes"
  14. IPV6_DEFROUTE="yes"
  15. IPV6_PEERDNS="yes"
  16. IPV6_PEERROUTES="yes"
  17. IPV6_FAILURE_FATAL="no"
  18. IPV6_ADDR_GEN_MODE="stable-privacy"
  19. NAME="ens33"
  20. UUID="8225206d-ab64-4101-b343-35316fc76a7c"
  21. DEVICE="ens33"
  22. ONBOOT="yes"
  23. ~
  24. ~
  25. ~

(2)、重启网络服务

  1. [root@host02 ~]# systemctl restart network

查看DHCP服务器IP

  1. [root@host02 ~]# ifconfig
  2. ens33: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
  3. inet 192.168.8.250 netmask 255.255.255.0 broadcast 192.168.8.255
  4. inet6 fe80::66d2:4ff4:82d6:a6e4 prefixlen scopeid 0x20<link>
  5. ether :0c:::7e:d0 txqueuelen (Ethernet)
  6. RX packets bytes (18.3 MiB)
  7. RX errors dropped overruns frame
  8. TX packets bytes (5.6 MiB)
  9. TX errors dropped overruns carrier collisions
  10.  
  11. lo: flags=<UP,LOOPBACK,RUNNING> mtu
  12. inet 127.0.0.1 netmask 255.0.0.0
  13. inet6 :: prefixlen scopeid 0x10<host>
  14. loop txqueuelen (Local Loopback)
  15. RX packets bytes (30.4 KiB)
  16. RX errors dropped overruns frame
  17. TX packets bytes (30.4 KiB)
  18. TX errors dropped overruns carrier collisions
  19.  
  20. virbr0: flags=<UP,BROADCAST,MULTICAST> mtu
  21. inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  22. ether :::f7::1e txqueuelen (Ethernet)
  23. RX packets bytes (432.0 B)
  24. RX errors dropped overruns frame
  25. TX packets bytes (0.0 B)
  26. TX errors dropped overruns carrier collisions

(3) 安装DHCP服务

  1. [root@host02 ~]# yum install dhcp
  2. [root@host02 ~]# rpm -qa dhcp
  3. dhcp-4.2.-.el7.centos.x86_64

(4)编辑DHCP服务器的配置文件

  1. [root@host02 ~]# vi dhcpd.conf
  2.  
  3. #dhcp configuration
  4.  
  5. #整体环境设置
  6.  
  7. ddns-update-style none;
  8. ignore client-updates;
  9. default-lease-time ;
  10. max-lease-time ;
  11. option routers 192.168.8.254;
  12. option domain-name "centos.me";
  13. option domain-name-servers 202.102.224.68,202.102.227.68;
  14.  
  15. #二个网段IP分配
  16.  
  17. subnet 192.168.8.0 netmask 255.255.255.0 {
  18. range 192.168.8.200 192.168.8.210;
  19. option subnet-mask 255.255.255.0;
  20. option routers 192.168.8.1;
  21. }
  22. subnet 192.168.100.0 netmask 255.255.255.0 {
  23. range 192.168.100.80 192.168.100.100;
  24. option subnet-mask 255.255.255.0;
  25. option routers 192.168.100.1;
  26. }

将编辑好的DHCP配置文件覆盖初装后的空白配置文件;

  1. [root@host02 ~]# cp dhcpd.conf /etc/dhcp/dhcpd.conf
  2. cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y

(5)启动DHCP服务,并检查状态;

  1. [root@host02 ~]# systemctl start dhcpd
  2. [root@host02 ~]# systemctl status dhcpd
  3. dhcpd.service - DHCPv4 Server Daemon
  4. Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
  5. Active: active (running) since Thu -- :: CST; 6s ago
  6. Docs: man:dhcpd()
  7. man:dhcpd.conf()
  8. Main PID: (dhcpd)
  9. Status: "Dispatching packets..."
  10. CGroup: /system.slice/dhcpd.service
  11. └─ /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
  12.  
  13. Aug :: host02.linux.com dhcpd[]: No subnet declaration for virbr0 (192.168.122.1).
  14. Aug :: host02.linux.com dhcpd[]: ** Ignoring requests on virbr0. If this is not what
  15. Aug :: host02.linux.com dhcpd[]: you want, please write a subnet declaration
  16. Aug :: host02.linux.com dhcpd[]: in your dhcpd.conf file for the network segment
  17. Aug :: host02.linux.com dhcpd[]: to which interface virbr0 is attached. **
  18. Aug :: host02.linux.com dhcpd[]:
  19. Aug :: host02.linux.com dhcpd[]: Listening on LPF/ens33/:0c:::7e:d0/192.168.8.0/
  20. Aug :: host02.linux.com dhcpd[]: Sending on LPF/ens33/:0c:::7e:d0/192.168.8.0/
  21. Aug :: host02.linux.com dhcpd[]: Sending on Socket/fallback/fallback-net
  22. Aug :: host02.linux.com systemd[]: Started DHCPv4 Server Daemon.
  23. [root@host02 ~]# netstat -tunlp |grep dhcp
  24. udp 0.0.0.0: 0.0.0.0:* /dhcpd
  25. udp 0.0.0.0: 0.0.0.0:* /dhcpd
  26. udp6 ::: :::* /dhcpd

DHCP服务器一切正常!至此DHCP服务器的配置已经完成;下一步配置DHCP中继代理服务器。

2、配置DHCP中继服务器

(1)、做为中继服务器首先要确保有两张网卡,否则没法中继;

本实验我已经在中继服务器上虚拟出两个网卡;

  1. [root@host-a ~]# lspci |grep ethernet
  2. [root@host-a ~]# lspci |grep Ethernet
  3. :01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev )
  4. :05.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev )

(2)查看网卡信息

  1. [root@host-a ~]# ifconfig
  2. ens33: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
  3. ether :0c::a9::dd txqueuelen (Ethernet)
  4. RX packets bytes (561.4 KiB)
  5. RX errors dropped overruns frame
  6. TX packets bytes (78.5 KiB)
  7. TX errors dropped overruns carrier collisions
  8.  
  9. ens37: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
  10. ether :0c::a9::e7 txqueuelen (Ethernet)
  11. RX packets bytes (2.8 KiB)
  12. RX errors dropped overruns frame
  13. TX packets bytes (68.6 KiB)
  14. TX errors dropped overruns carrier collisions
  15.  
  16. lo: flags=<UP,LOOPBACK,RUNNING> mtu
  17. inet 127.0.0.1 netmask 255.0.0.0
  18. inet6 :: prefixlen scopeid 0x10<host>
  19. loop txqueuelen (Local Loopback)
  20. RX packets bytes (12.5 KiB)
  21. RX errors dropped overruns frame
  22. TX packets bytes (12.5 KiB)
  23. TX errors dropped overruns carrier collisions
  24.  
  25. virbr0: flags=<UP,BROADCAST,MULTICAST> mtu
  26. inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  27. ether :::7a:2c:f4 txqueuelen (Ethernet)
  28. RX packets bytes (0.0 B)
  29. RX errors dropped overruns frame
  30. TX packets bytes (0.0 B)
  31. TX errors dropped overruns carrier collisions

(2)接下来分别配置这两个网卡的网络参数

网卡ens33与DHCP服务器相连,属于192.168.8.0/24网段,注意网卡ens33的IP地址是DHCP服务器的网关地址,
配置如下:

  1. [root@host-a ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
  2. TYPE="Ethernet"
  3. BOOTPROTO="static"
  4. IPADDR=192.168.8.254
  5. NETMASK=255.255.255.0
  6. DEFROUTE="yes"
  7. PEERDNS="yes"
  8. PEERROUTES="yes"
  9. IPV4_FAILURE_FATAL="no"
  10. IPV6INIT="yes"
  11. IPV6_AUTOCONF="yes"
  12. IPV6_DEFROUTE="yes"
  13. IPV6_PEERDNS="yes"
  14. IPV6_PEERROUTES="yes"
  15. IPV6_FAILURE_FATAL="no"
  16. IPV6_ADDR_GEN_MODE="stable-privacy"
  17. NAME="ens33"
  18. UUID="065ff1ad-9117-4cf4-a716-c61d5fdc0c00"
  19. DEVICE="ens33"
  20. ONBOOT="yes"

网卡ens37与192.168.100.0/24网段相连,注意网卡ens37的IP地址是192.168.100.0/24网段的网关地址,配置如下:

  1. [root@host-a ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens37
  2. TYPE=Ethernet
  3. BOOTPROTO=static
  4. IPADDR=192.168.100.1
  5. PREFIX=
  6. DEFROUTE=yes
  7. IPV4_FAILURE_FATAL=no
  8. IPV6INIT=yes
  9. IPV6_AUTOCONF=yes
  10. IPV6_DEFROUTE=yes
  11. IPV6_PEERDNS=yes
  12. IPV6_PEERROUTES=yes
  13. IPV6_FAILURE_FATAL=no
  14. IPV6_ADDR_GEN_MODE=stable-privacy
  15. NAME="ens37"
  16. UUID=e3854409-f832-4d4c-b7ae-271d0aa5ecc5
  17. ONBOOT=yes

(3)配置好后,重起网络服务使设置生效

  1. [root@host-a ~]# systemctl restart network
  2. [root@host-a ~]# ifconfig
  3. ens33: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
  4. inet 192.168.8.254 netmask 255.255.255.0 broadcast 192.168.8.255
  5. inet6 fe80::f31:c380:a398:1df6 prefixlen scopeid 0x20<link>
  6. ether :0c::a9::dd txqueuelen (Ethernet)
  7. RX packets bytes (562.4 KiB)
  8. RX errors dropped overruns frame
  9. TX packets bytes (91.6 KiB)
  10. TX errors dropped overruns carrier collisions
  11.  
  12. ens37: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
  13. inet 192.168.100.1 netmask 255.255.255.0 broadcast 192.168.100.255
  14. inet6 fe80:::4bde:b57c:957d prefixlen scopeid 0x20<link>
  15. ether :0c::a9::e7 txqueuelen (Ethernet)
  16. RX packets bytes (2.8 KiB)
  17. RX errors dropped overruns frame
  18. TX packets bytes (76.6 KiB)
  19. TX errors dropped overruns carrier collisions
  20.  
  21. lo: flags=<UP,LOOPBACK,RUNNING> mtu
  22. inet 127.0.0.1 netmask 255.0.0.0
  23. inet6 :: prefixlen scopeid 0x10<host>
  24. loop txqueuelen (Local Loopback)
  25. RX packets bytes (12.5 KiB)
  26. RX errors dropped overruns frame
  27. TX packets bytes (12.5 KiB)
  28. TX errors dropped overruns carrier collisions
  29.  
  30. virbr0: flags=<UP,BROADCAST,MULTICAST> mtu
  31. inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  32. ether :::7a:2c:f4 txqueuelen (Ethernet)
  33. RX packets bytes (0.0 B)
  34. RX errors dropped overruns frame
  35. TX packets bytes (0.0 B)
  36. TX errors dropped overruns carrier collisions

(4)安装DHCP

  1. #安装
  2. [root@host-a network-scripts]# yum install dhcp
  3. #安装成功
  4. [root@host-a network-scripts]# rpm -qa dhcp
  5. dhcp-4.2.-.el7.centos.x86_64
  6. #注意dhcp包含dhcp中继服务
  7. [root@host-a ~]# rpm -ql dhcp |grep dhcrelay
  8. /usr/lib/systemd/system/dhcrelay.service
  9. /usr/sbin/dhcrelay
  10. /usr/share/man/man8/dhcrelay..gz

(5)打开DHCP中继服务器路由转发功能

编辑/etc/sysctl.conf 文件在文件添加一行内容为:

“net.ipv4.ip_forward=1”

开启路由转发功能

  1. [root@host-a ~]# vi /etc/sysctl.conf
  2. # sysctl settings are defined through files in
  3. # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
  4. #
  5. # Vendors settings live in /usr/lib/sysctl.d/.
  6. # To override a whole file, create a new file with the same in
  7. # /etc/sysctl.d/ and put new settings there. To override
  8. # only specific settings, add a file with a lexically later
  9. # name in /etc/sysctl.d/ and put new settings there.
  10. #
  11. # For more information, see sysctl.conf() and sysctl.d().
  12. net.ipv4.ip_forward =

使设置立即生效,执行以下命令:

[root@host-a ~]# sysctl -p
net.ipv4.ip_forward = 1

查看内核参数设置,确认生效;

[root@host-a ~]# sysctl -a  |grep ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
[root@host-a ~]#

(6)开启DHCP中继服务

  1. [root@host-a ~]# dhcrelay 192.168.8.250
  2. Dropped all unnecessary capabilities.
  3. Internet Systems Consortium DHCP Relay Agent 4.2.
  4. Copyright - Internet Systems Consortium.
  5. All rights reserved.
  6. For info, please visit https://www.isc.org/software/dhcp/
  7. Listening on LPF/virbr0/:::7a:2c:f4
  8. Sending on LPF/virbr0/:::7a:2c:f4
  9. Listening on LPF/ens37/:0c::a9::e7
  10. Sending on LPF/ens37/:0c::a9::e7
  11. Listening on LPF/ens33/:0c::a9::dd
  12. Sending on LPF/ens33/:0c::a9::dd
  13. Sending on Socket/fallback
  14. [root@host-a ~]#
  15.  
  16. [root@host-a ~]# netstat -tunlp |grep dhcrelay
  17. udp 0.0.0.0: 0.0.0.0:* /dhcrelay
  18. udp 0.0.0.0: 0.0.0.0:* /dhcrelay
  19. udp6 ::: :::* /dhcrelay

3、客户端测试

(1)配置客户端网络为自动获取IP

(2)重启网络服务

(3)查看IP

(4)查看客户端在重启网络时都做了什么

(5)查看DHCP服务器日志文件

  1. [root@host02 ~]# tail -n /var/log/messages
  2. Aug :: host02 systemd: Stopping user-.slice.
  3. Aug :: host02 dhcpd: DHCPREQUEST for 192.168.6.6 from :0c:::4c:ea via 192.168.100.1: ignored (not authoritative).
  4. Aug :: host02 dhcpd: DHCPREQUEST for 192.168.6.6 from :0c:::4c:ea via 192.168.100.1: ignored (not authoritative).
  5. Aug :: host02 dhcpd: DHCPDISCOVER from :0c:::4c:ea via 192.168.100.1
  6. Aug :: host02 dhcpd: DHCPOFFER on 192.168.100.80 to :0c:::4c:ea (host01) via 192.168.100.1
  7. Aug :: host02 dhcpd: DHCPREQUEST for 192.168.100.80 (192.168.8.250) from :0c:::4c:ea (host01) via 192.168.100.1
  8. Aug :: host02 dhcpd: DHCPACK on 192.168.100.80 to :0c:::4c:ea (host01) via 192.168.100.1
  9. Aug :: host02 dhcpd: DHCPREQUEST for 192.168.100.80 (192.168.8.250) from :0c:::4c:ea (host01) via 192.168.100.1
  10. Aug :: host02 dhcpd: DHCPACK on 192.168.100.80 to :0c:::4c:ea (host01) via 192.168.100.1

(6)检查客户端获取的DNS是否正确

DNS与DHCP服务器设置的一致!

可以看到客户端已经可以正常获取DHCP服务器设置的网络参数了!!

CentOS7.3下关于DHCP中继代理服务器的详细配置的更多相关文章

  1. [moka同学笔记]window下redis的安装以及php-redis详细配置(摘录)

    (注意对应的版本)下载地址:https://github.com/phpredis/phpredis/downloads 首先下载redis安装,windows下安装软件都是下一步下一步over,就不 ...

  2. 7、二种 为二个不同的子网配置DHCP服务器(中继代理服务器)

    环境如下:        (参考之前,保证二个子网可以互相ping通) 虚拟机vm1        192.168.170.3                    VMnet8 (NAT模式) 虚拟 ...

  3. 启用DHCP中继代理,实现跨子网服务 - Win 2003 Server

    伴随着局域网规模的逐步扩大,一个网络常常会被划分成多个不同的子网,以便根据不同子网的工作要求来实现个性化的管理要求.考虑到规模较大的局域网一般会使用DHCP服务器来为各个工作站分配IP地址,不过一旦局 ...

  4. H3C的DHCP中继配置命令

    dhcp enable命令用来使能DHCP服务 dhcp relay information enable 命令用来配置DHCP中继支持Option 82功能 缺省情况下,DHCP中继不支持Optio ...

  5. DHCP配置实例(含DHCP中继代理)

    https://blog.51cto.com/yuanbin/109759. DHCP配置实例(含DHCP中继代理)   某公司局域网有192.168.1.0/24和192.168.2.0/24这两个 ...

  6. 配置DHCP中继

    本实验模拟企业网络场景.某公司分部的网络由交换机S1和网关路由器R1组成,员工终端PC-1和PC-2都连接在S1上.公司要求分部内所有员工主机的IP地址都通过总部的DHCP服务器自动获取.分部网关路由 ...

  7. 网络拓扑实例之交换机处于同一网络作为DHCP中继与服务器(八)

    组网图形 DHCP中继简介 DHCP中继用于在DHCP服务器和客户端之间转发DHCP报文.当DHCP服务器与客户端不在同一个网段时,需要配置DHCP中继.对于DHCP客户端来说,DHCP中继就是DHC ...

  8. 中兴交换机基础配置(备份、dhcp中继、monitor)

    1. 备份配置 格式: copy tftp/sftp/ftp [vrf mng] root: 本地文件 远端文件 1. 通过tftp进行备份,vrf mng表示指定使用管理口链路连接 copy tft ...

  9. 如何搭建DHCP及DHCP中继服务器

    当局域网中有大量的主机时,如果逐台设置ip地址.默认网关.dns服务器地址时等网络参数,显然是一个费力也未必讨好的方法,这时使用DHCP的方式分发ip地址,能够动态配置各客户机的网络地址参数,大大减轻 ...

随机推荐

  1. bcb6重启应用程序

    在工程的cpp文件中WinMain还是得最后添加如下的代码(其中g_blsRunAgain为bool类型的全局变量,在需求重启的时候先将g_blsRunAgain置为true,再将程序关闭,之后就会重 ...

  2. Codeforces Round #339 (Div. 2) A

    Description Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which ...

  3. 2015苏州大学ACM-ICPC集训队选拔赛(1) 1001 1002 1010

    签到题 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submissio ...

  4. shell编程中

    1.1 条件表达式 1.1.1 文件判断 常用文件测试操作符 常用文件测试操作符 说明 -d文件,d的全拼为directory 文件存在且为目录则为真,即测试表达式成立 -f文件,f的全拼为file ...

  5. python3 + pycharm+requests+HTMLTestRunner接口自动化测试步骤

    1.python3 环境的搭建,pycharm安装 2.想要用requests做自动化接口测试,那么就得先安装requests这个第三方库,在命令窗口执行 pip install requests 3 ...

  6. hive表多种存储格式的文件大小差异,无重复数据

    -- 重点,目标表无重复数据 -- dbName.num_result 无重复记录 -- 插入数据 CREATE TABLE dbName.test_textfile( `key` string, ` ...

  7. 在word2010中添加带滚动条的文本框

    由于文件内容过长,为了加强文章的可读性,可以添加一个带滚动条的文本框,既能使文章看起来干净整洁,同时也极大的提高了文章的可读性. 我这里对在word2010中文本框带滚动条作个介绍: 1. 打开wor ...

  8. node服务器端模块化-commomjs

    modele.js getmodule.js 用exports 返回的是一个对象中的每个属性

  9. 转 python 随机走动的模拟

    https://blog.csdn.net/python2014/article/details/21231971 麻省理工的随机走动模块,还不错,三天搞懂了,不过懂得不彻底.   记录下修改的代码 ...

  10. 01 性能优化基础怀实践 之 ASH分析

    1.模拟一个会话阻塞的场景.    通过update 同一行数据达到模拟阻塞的效果 : SQL> create table t1 (id number ,name varchar2(20)) ; ...