DHCP服务器的搭建(RHEL8 )

本次实验用到两台虚拟机演示dhcp服务器的搭建并测试

虚拟机 作用
rhel8 dhcp服务器
rhel7 测试机

一.DHCP服务器

1.什么是dhcp服务器

DHCP(Dynamic Host Configuration Protocol ,动态主机配置协议)通常被用在大型的局域网络中,主要作用是集中的管理,分配IP地址,使网络环境中的主机动态的获得IP地址,Gateway地址,DNS服务器地址等信息,并能够提升地址的使用率。

2.端口

DHCP服务端口是UDP67和UDP68,这两个端口是正常的DHCP服务端口,可以理解为一个发送,一个接收。
1、客户端向68端口(bootps)广播请求配置,
2、服务器向67端口(bootpc)广播回应请求

二.dhcp服务器的搭建

在rhel8中:
1.配置静态网络

vim /etc/sysconfig/network-scripts/ifcfg-ens160
DEVICE=ens160
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.30
NETMASK=255.255.255.0
[root@RHEL8 ~]# systemctl restart NetworkManager
[root@RHEL8 ~]# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.254.30  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 fe80::20c:29ff:fe94:a86  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:94:0a:86  txqueuelen 1000  (Ethernet)
        RX packets 3724  bytes 272842 (266.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 139  bytes 14574 (14.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 48  bytes 4944 (4.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 48  bytes 4944 (4.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.把镜像接入光驱,作用是找到dhcpd安装包
3.df查看光驱挂载位置

[root@RHEL8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          910516       0    910516   0% /dev
tmpfs             924700       0    924700   0% /dev/shm
tmpfs             924700    9848    914852   2% /run
tmpfs             924700       0    924700   0% /sys/fs/cgroup
/dev/nvme0n1p3   8181760 4098312   4083448  51% /
/dev/nvme0n1p1    199328  141344     57984  71% /boot
tmpfs             184940      16    184924   1% /run/user/42
tmpfs             184940    3488    181452   2% /run/user/0
/dev/sr0         6935944 6935944         0 100% /run/media/root/RHEL-8-0-0-BaseOS-x86_64  ##光驱挂载点

4.查找dhcp安装包

[root@RHEL8 ~]# cd /run/media/root/RHEL-8-0-0-BaseOS-x86_64/BaseOS/Packages/
[root@RHEL8 Packages]# ls dhcp-*
dhcp-client-4.3.6-30.el8.x86_64.rpm  dhcp-libs-4.3.6-30.el8.x86_64.rpm
dhcp-common-4.3.6-30.el8.noarch.rpm  dhcp-relay-4.3.6-30.el8.x86_64.rpm
dhcp-libs-4.3.6-30.el8.i686.rpm      dhcp-server-4.3.6-30.el8.x86_64.rpm

5.安装dhcp

[root@RHEL8 Packages]# rpm -ivh dhcp-server-4.3.6-30.el8.x86_64.rpm
warning: dhcp-server-4.3.6-30.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:dhcp-server-12:4.3.6-30.el8      ################################# [100%]

6.配置dhcp文件

[root@RHEL8 Packages]# cd /etc/dhcp/
[root@RHEL8 dhcp]# ls
dhclient.conf  dhclient.d  dhcpd6.conf  dhcpd.conf
[root@RHEL8 dhcp]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example dhcpd.conf
[root@RHEL8 dhcp]# vim dhcpd.conf
  1 # dhcpd.conf
  2 #
  3 # Sample configuration file for ISC dhcpd
  4 #
  5
  6 # option definitions common to all supported networks...
  7 option domain-name "example.org";
  8 option domain-name-servers 114.114.114.114;
  9
 10 default-lease-time 600;
 11 max-lease-time 7200;
 12
 13 # Use this to enble / disable dynamic dns updates globally.
 14 #ddns-update-style none;
 15
 16 # If this DHCP server is the official DHCP server for the local
 17 # network, the authoritative directive should be uncommented.
 18 #authoritative;
 19
 20 # Use this to send dhcp log messages to a different log file (you also
 21 # have to hack syslog.conf to complete the redirection).
 22 log-facility local7;
 23
 24 # No service will be given on this subnet, but declaring it helps the
 25 # DHCP server to understand the network topology.
 26
 27
 28 # This is a very basic subnet declaration.
 29
 30 subnet 172.25.254.0 netmask 255.255.255.0 {    ##设定网段
 31   range 172.25.254.88 172.25.254.100;		   ##分配ip地址
 32   option routers 172.25.254.30;				   ##网关
 33 }

7.重启服务

[root@RHEL8 dhcp]# systemctl restart dhcpd

三.测试dhcp服务器

在rhel7:
1.配置网络

[root@rhel7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-westos
DEVICE=ens33
ONBOOT=yes
BOOTPROTO=dhcp
NAME=westos

2.rhel7中配置dhcp网络看是否可以获得ip,并查看网卡的物理硬件地址
DHCP服务器的搭建(RHEL8 )_第1张图片
在rhel8中查看ip分配情况
DHCP服务器的搭建(RHEL8 )_第2张图片
“注意在rhel7中dhcp的安装如下:”

cd "/run/media/root/RHEL-7.6 Server.x86_64/Packages"
rpm -ivh dhcp-4.2.5-68.el7_5.1.x86_64.rpm

你可能感兴趣的:(linux)