全国直销电话:4006-854-568
IT-technology
以人为本,众志成城,以“用户至上”.“服务上乘”为原则,
追求产品和服务高质量,努力实现与客户之间真诚有效的沟通,
不断地圆梦、奔跑与腾飞。
新闻动态   NEWS
​Centos7.8部署DHCP及地址保留、超级作用域-北京赛维博信科技发展有限公司
来源: | 作者:svbx001 | 发布时间: 2022-04-15 | 3364 次浏览 | 分享到:

一.准备工作

项目名称基础信息
操作系统Centos7.8
IP地址192.168.250.219
SElinux已关闭
防火墙已启用,开放相关端口:UDP/67和UDP/68
DHCP地址池192.168.250.2-192.168.250.90

二.部署DHCP服务器

1.yum方式安装dhcp服务
[root@dhcp-server ~]# yum -y install dhcp已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile
2.查看dhcpd.conf默认配置文件的内容

默认情况下,dhcpd.conf配置文件在 /etc/dhcp/目录下,默认的配置内容为空,如下:

[root@dhcp-server ~]# cd /etc/dhcp[root@dhcp-server dhcp]# ll总用量 8drwxr-xr-x. 2 root root   236月  102021 dhclient.ddrwxr-xr-x. 2 root root   284月  1216:09 dhclient-exit-hooks.d-rw-r--r--. 1 root root  1206月  102021 dhcpd6.conf-rw-r--r--. 1 root root  1176月  102021 dhcpd.confdrwxr-x---. 2 root dhcpd  284月  1216:09 scripts[root@dhcp-server dhcp]# cat dhcpd.conf## DHCP Server Configuration file.#   see /usr/share/doc/dhcp*/dhcpd.conf.example#   see dhcpd.conf(5) man page#[root@dhcp-server dhcp]#
3.复制example文件

从 /usr/share/doc/dhcp-*/dhcpd.conf.example复制文件到 /etc/dhcp下,文件名为 dhcpd.conf,进行覆盖。

[root@dhcp-server dhcp]# cp -a /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.confcp:是否覆盖"/etc/dhcp/dhcpd.conf"?y[root@dhcp-server dhcp]#
4.查看example的配置信息
  1. [root@dhcp-server dhcp]# cat dhcpd.conf

  2. # dhcpd.conf

  3. #

  4. # Sample configuration file for ISC dhcpd

  5. #


  6. # option definitions common to all supported networks...

  7. option domain-name "example.org";

  8. option domain-name-servers ns1.example.org, ns2.example.org;


  9. default-lease-time 600;

  10. max-lease-time 7200;


  11. # Use this to enble / disable dynamic dns updates globally.

  12. #ddns-update-style none;


  13. # If this DHCP server is the official DHCP server for the local

  14. # network, the authoritative directive should be uncommented.

  15. #authoritative;


  16. # Use this to send dhcp log messages to a different log file (you also

  17. # have to hack syslog.conf to complete the redirection).

  18. log-facility local7;


  19. # No service will be given on this subnet, but declaring it helps the

  20. # DHCP server to understand the network topology.


  21. subnet 10.152.187.0 netmask 255.255.255.0{

  22. }


  23. # This is a very basic subnet declaration.


  24. subnet 10.254.239.0 netmask 255.255.255.224{

  25.  range 10.254.239.1010.254.239.20;

  26.  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;

  27. }


  28. # This declaration allows BOOTP clients to get dynamic addresses,

  29. # which we don't really recommend.


  30. subnet 10.254.239.32 netmask 255.255.255.224{

  31.  range dynamic-bootp 10.254.239.4010.254.239.60;

  32.  option broadcast-address 10.254.239.31;

  33.  option routers rtr-239-32-1.example.org;

  34. }


  35. # A slightly different configuration for an internal subnet.

  36. subnet 10.5.5.0 netmask 255.255.255.224{

  37.  range 10.5.5.2610.5.5.30;

  38.  option domain-name-servers ns1.internal.example.org;

  39.  option domain-name "internal.example.org";

  40.  option routers 10.5.5.1;

  41.  option broadcast-address 10.5.5.31;

  42. default-lease-time 600;

  43.  max-lease-time 7200;

  44. }


  45. # Hosts which require special configuration options can be listed in

  46. # host statements.   If no address is specified, the address will be

  47. # allocated dynamically (if possible), but the host-specific information

  48. # will still come from the host declaration.


  49. host passacaglia {

  50.  hardware ethernet 0:0:c0:5d:bd:95;

  51.  filename "vmunix.passacaglia";

  52.  server-name "toccata.fugue.com";

  53. }


  54. # Fixed IP addresses can also be specified for hosts.   These addresses

  55. # should not also be listed as being available for dynamic assignment.

  56. # Hosts for which fixed IP addresses have been specified can boot using

  57. # BOOTP or DHCP.   Hosts for which no fixed address is specified can only

  58. # be booted with DHCP, unless there is an address range on the subnet

  59. # to which a BOOTP client is connected which has the dynamic-bootp flag

  60. # set.

  61. host fantasia {

  62.  hardware ethernet 08:00:07:26:c0:a5;

  63. fixed-address fantasia.fugue.com;

  64. }


  65. # You can declare a class of clients and then do address allocation

  66. # based on that.   The example below shows a case where all clients

  67. # in a certain class get addresses on the 10.17.224/24 subnet, and all

  68. # other clients get addresses on the 10.0.29/24 subnet.


  69. class"foo"{

  70.  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";

  71. }


  72. shared-network 224-29{

  73.  subnet 10.17.224.0 netmask 255.255.255.0{

  74.    option routers rtr-224.example.org;

  75. }

  76.  subnet 10.0.29.0 netmask 255.255.255.0{

  77.    option routers rtr-29.example.org;

  78. }

  79.  pool {

  80.    allow members of "foo";

  81.    range 10.17.224.1010.17.224.250;

  82. }

  83.  pool {

  84.    deny members of "foo";

  85.    range 10.0.29.1010.0.29.230;

  86. }

  87. }

  88. [root@dhcp-server dhcp]#

5.修改dhcpd.conf配置文件

这里只配一个基本的网络DHCP服务,地址范围为规划的地址:[192.168.250.2,192.168.250.90]。

配置如下:

  1. [root@dhcp-server dhcp]# vim dhcpd.conf

  2. [root@dhcp-server dhcp]#


  3. # This is a very basic subnet declaration.


  4. subnet 192.168.250.0 netmask 255.255.255.0{

  5.  range 192.168.250.2192.168.250.90;  #指定IP地址范围

  6.  option routers 192.168.250.1;   #指定网关地址

  7.  option broadcast-address 192.168.250.255;  #指定广播地址

  8. default-lease-time 600;  #指定默认租约

  9.  max-lease-time 7200;  #指定最大租约

  10. }

6.重启DHCP服务测试
[root@dhcp-server dhcp]# systemctl restart dhcpd[root@dhcp-server dhcp]# systemctl status dhcpd● dhcpd.service - DHCPv4ServerDaemonLoaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)Active: active (running) since 五 2022-04-1512:42:03 CST; 10s agoDocs: man:dhcpd(8)           man:dhcpd.conf(5)Main PID: 18776(dhcpd)Status: "Dispatching packets..."Tasks: 1CGroup: /system.slice/dhcpd.service└─18776/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

启动一个客户面,查看能否获得IP。

本次在LINUX客户机下,先配置自动获取IP地址

[root@mysvn ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0TYPE=EthernetBOOTPROTO=dhcp  #自动获取IP地址DEFROUTE=yesIPV4_FAILURE_FATAL=noNAME=eth0UUID=434372f7-39e5-48b7-968b-61dc7193c902DEVICE=eth0ONBOOT=yes

然后重启网络服务,查看获取的IP地址为 192.168.250.2/24,如下:

[root@mydhcpclient ~]# ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN groupdefault qlen 1000    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00    inet 127.0.0.1/8 scope host lo       valid_lft forever preferred_lft forever    inet6 ::1/128 scope host       valid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP groupdefault qlen 1000    link/ether 52:54:00:43:f4:24 brd ff:ff:ff:ff:ff:ff    inet 192.168.250.2/24 brd 192.168.250.255 scope global noprefixroute dynamic eth0       valid_lft 572sec preferred_lft 572sec    inet6 fe80::652b:6da4:4354:b80a/64 scope link tentative noprefixroute dadfailed       valid_lft forever preferred_lft forever    inet6 fe80::c1d:8fe4:757a:da37/64 scope link tentative noprefixroute dadfailed       valid_lft forever preferred_lft forever    inet6 fe80::941:8a6:6c27:1098/64 scope link tentative noprefixroute dadfailed       valid_lft forever preferred_lft forever3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN groupdefault qlen 1000    link/ether 52:54:00:d7:57:29 brd ff:ff:ff:ff:ff:ff    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0       valid_lft forever preferred_lft forever4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN groupdefault qlen 1000    link/ether 52:54:00:d7:57:29 brd ff:ff:ff:ff:ff:ff[root@mydhcpclient ~]#

三.配置保留地址

那么为什么要有保留地址呢?一些主机需要固定的IP,但是仍然使用DHCP来分配地址,配置完地址保留后,以后每次给这个主机分配的IP都是相同的。

还是打开配置文件 /etc/dhcp/dhcpd.conf

找到下面这部分:

# Fixed IP addresses can also be specified for hosts.   These addresses# should not also be listed as being available for dynamic assignment.# Hosts for which fixed IP addresses have been specified can boot using# BOOTP or DHCP.   Hosts for which no fixed address is specified can only# be booted with DHCP, unless there is an address range on the subnet# to which a BOOTP client is connected which has the dynamic-bootp flag# set.host fantasia {  hardware ethernet 08:00:07:26:c0:a5;fixed-address fantasia.fugue.com;}

然后进行修改,比如,这次要保留地址 192.168.250.10的地址为NC服务器,这台NC服务器的MAC地址为 08-3a-38-9d-9A-71,则进行如下配置:

host fantasia {  hardware ethernet 08:3a:38:9d:9A:71;  #被指定的主机的MAC地址fixed-address 192.168.250.10;    #指定的IP}

四.超级作用域

为什么要用到超级作用域,现在局域网用的是C类网段分配主机,但是主机数目大于254,一个C类网段不够分,所以要两个网段才行,还要这两个网段之间能够通信。这时候我们就可以把路由器和DHCP服务器结合到一起来用。

1.复制当前网卡副本
  1. [root@dhcp-server dhcp]# cd /etc/sysconfig/network-scripts/


  2. [root@dhcp-server network-scripts]# cp ifcfg-eth0 ifcfg-eth0:0

  3. [root@dhcp-server network-scripts]# vim ifcfg-eth0:0

  4. [root@dhcp-server network-scripts]#

  5. [root@dhcp-server network-scripts]# cat ifcfg-eth0:0

  6. TYPE=Ethernet

  7. PROXY_METHOD=none

  8. BROWSER_ONLY=no

  9. BOOTPROTO=none

  10. DEFROUTE=yes

  11. IPV4_FAILURE_FATAL=no

  12. NAME=eth0

  13. UUID=434372f7-39e5-48b7-968b-61dc7193c902

  14. DEVICE=eth0

  15. ONBOOT=yes

  16. IPADDR=192.168.251.219

  17. PREFIX=24

  18. GATEWAY=192.168.251.1

  19. DNS1=192.168.251.219

  20. [root@dhcp-server network-scripts]#

配置另一个的IP为 192.168.251.219

2.修改DHCP的配置文件

/etc/dhcp/dhcpd.conf,找到下面部分:

shared-network 224-29{  subnet 10.17.224.0 netmask 255.255.255.0{    option routers rtr-224.example.org;}  subnet 10.0.29.0 netmask 255.255.255.0{    option routers rtr-29.example.org;}  pool {    allow members of "foo";    range 10.17.224.1010.17.224.250;}  pool {    deny members of "foo";    range 10.0.29.1010.0.29.230;}}[root@dhcp-server dhcp]#

进行修改:

shared-network 250-251{  subnet 192.168.250.0 netmask 255.255.255.0{    option routers 192.168.250.1;    range 192.168.250.2192.168.250.254;}  subnet 192.168.251.0 netmask 255.255.255.0{    option routers 192.168.251.1;    range 192.168.251.2192.168.251.200;}


 

服务热线

1391-024-6332