Linux系统之部署DHCP服务器

一、ssh连接Linux

Connection to 192.168.3.169 closed.
PS C:\Users\jeven> ssh root@192.168.3.169
root@192.168.3.169's password:
Last login: Mon Oct 17 01:13:05 2022 from computer-work.dhcp-route
[root@serer01 ~]#
[root@serer01 ~]# ls
anaconda-ks.cfg
[root@serer01 ~]#

二、检查系统版本

[root@serer01 ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

三、设置yum仓库

1.设置阿里的yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

2.检查yum仓库

[root@serer01 ~]# yum repolist all |grep enable
base/7/x86_64                        CentOS-7 - Base - mirrors.a enabled: 10,072
docker-ce-stable/7/x86_64            Docker CE Stable - x86_64   enabled:    169
extras/7/x86_64                      CentOS-7 - Extras - mirrors enabled:    515
updates/7/x86_64                     CentOS-7 - Updates - mirror enabled:  4,300

四、安装DHCP服务

1.安装dhcp

[root@serer01 ~]# yum -y install dhcp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-83.el7.centos.1 will be installed
--> Processing Dependency: dhcp-libs(x86-64) = 12:4.2.5-83.el7.centos.1 for package: 12:dhcp-4.2.5-83.el7.centos.1.x86_64
--> Processing Dependency: dhcp-common = 12:4.2.5-83.el7.centos.1 for package: 12:dhcp-4.2.5-83.el7.centos.1.x86_64
--> Processing Dependency: libisc-export.so.169()(64bit) for package: 12:dhcp-4.2.5-83.el7.centos.1.x86_64
--> Processing Dependency: libdns-export.so.1102()(64bit) for package: 12:dhcp-4.2.5-83.el7.centos.1.x86_64
--> Running transaction check
---> Package bind-export-libs.x86_64 32:9.11.4-26.P2.el7_9.10 will be installed
---> Package dhcp-common.x86_64 12:4.2.5-42.el7.centos will be updated
--> Processing Dependency: dhcp-common = 12:4.2.5-42.el7.centos for package: 12:dhclient-4.2.5-42.el7.centos.x86_64
---> Package dhcp-common.x86_64 12:4.2.5-83.el7.centos.1 will be an update
---> Package dhcp-libs.x86_64 12:4.2.5-42.el7.centos will be updated
---> Package dhcp-libs.x86_64 12:4.2.5-83.el7.centos.1 will be an update
--> Running transaction check
---> Package dhclient.x86_64 12:4.2.5-42.el7.centos will be updated
---> Package dhclient.x86_64 12:4.2.5-83.el7.centos.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                        Arch                 Version                                Repository             Size
========================================================================================================================
Installing:
 dhcp                           x86_64               12:4.2.5-83.el7.centos.1               updates               515 k
Installing for dependencies:
 bind-export-libs               x86_64               32:9.11.4-26.P2.el7_9.10               updates               1.1 M
Updating for dependencies:
 dhclient                       x86_64               12:4.2.5-83.el7.centos.1               updates               286 k
 dhcp-common                    x86_64               12:4.2.5-83.el7.centos.1               updates               177 k
 dhcp-libs                      x86_64               12:4.2.5-83.el7.centos.1               updates               133 k

Transaction Summary
========================================================================================================================
Install  1 Package  (+1 Dependent package)
Upgrade             ( 3 Dependent packages)

Total download size: 2.2 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): dhclient-4.2.5-83.el7.centos.1.x86_64.rpm                                                 | 286 kB  00:00:00
(2/5): dhcp-4.2.5-83.el7.centos.1.x86_64.rpm                                                     | 515 kB  00:00:00
(3/5): dhcp-common-4.2.5-83.el7.centos.1.x86_64.rpm                                              | 177 kB  00:00:00
(4/5): bind-export-libs-9.11.4-26.P2.el7_9.10.x86_64.rpm                                         | 1.1 MB  00:00:01
(5/5): dhcp-libs-4.2.5-83.el7.centos.1.x86_64.rpm                                                | 133 kB  00:00:00
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   1.0 MB/s | 2.2 MB  00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 12:dhcp-libs-4.2.5-83.el7.centos.1.x86_64                                                            1/8
  Updating   : 12:dhcp-common-4.2.5-83.el7.centos.1.x86_64                                                          2/8
  Installing : 32:bind-export-libs-9.11.4-26.P2.el7_9.10.x86_64                                                     3/8
  Installing : 12:dhcp-4.2.5-83.el7.centos.1.x86_64                                                                 4/8
  Updating   : 12:dhclient-4.2.5-83.el7.centos.1.x86_64                                                             5/8
  Cleanup    : 12:dhclient-4.2.5-42.el7.centos.x86_64                                                               6/8
  Cleanup    : 12:dhcp-common-4.2.5-42.el7.centos.x86_64                                                            7/8
  Cleanup    : 12:dhcp-libs-4.2.5-42.el7.centos.x86_64                                                              8/8
  Verifying  : 32:bind-export-libs-9.11.4-26.P2.el7_9.10.x86_64                                                     1/8
  Verifying  : 12:dhcp-common-4.2.5-83.el7.centos.1.x86_64                                                          2/8
  Verifying  : 12:dhcp-4.2.5-83.el7.centos.1.x86_64                                                                 3/8
  Verifying  : 12:dhcp-libs-4.2.5-83.el7.centos.1.x86_64                                                            4/8
  Verifying  : 12:dhclient-4.2.5-83.el7.centos.1.x86_64                                                             5/8
  Verifying  : 12:dhclient-4.2.5-42.el7.centos.x86_64                                                               6/8
  Verifying  : 12:dhcp-libs-4.2.5-42.el7.centos.x86_64                                                              7/8
  Verifying  : 12:dhcp-common-4.2.5-42.el7.centos.x86_64                                                            8/8

Installed:
  dhcp.x86_64 12:4.2.5-83.el7.centos.1

Dependency Installed:
  bind-export-libs.x86_64 32:9.11.4-26.P2.el7_9.10

Dependency Updated:
  dhclient.x86_64 12:4.2.5-83.el7.centos.1                  dhcp-common.x86_64 12:4.2.5-83.el7.centos.1
  dhcp-libs.x86_64 12:4.2.5-83.el7.centos.1

Complete!

2.复制dhcp示例配置文件

[root@serer01 ~]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? yes
[root@serer01 ~]#

3.修改dhcp配置文件

[root@serer01 ~]# cat   /etc/dhcp/dhcpd.conf
ddns-update-style interim;     #配置使用过渡性 DHCP-DNS互动更新模式。
ignore client-updates;         #忽略客户端更新

subnet 192.168.3.0 netmask 255.255.255.0 {

        option routers                  192.168.3.254;        #网关地址
        option subnet-mask              255.255.255.0;      #子网掩码选项

        option nis-domain               "my.dhcp.com";
        option domain-name              "my.dhcp.com";     #域名
        option domain-name-servers      192.168.3.169;       #DNS地址

        option time-offset              -18000; # Eastern Standard Time

        range dynamic-bootp 192.168.3.100 192.168.3.200;       #租用IP地址的范围
        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@serer01 ~]#

4.绑定网卡

在/etc/sysconfig/dhcpd中添加一行
<span style="font-size:14px;">DHCPDARGS=eth0</span>

5.重启dhcp服务

systemctl restart dhcpd

6.查看dhcp服务状态

[root@serer01 ~]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-10-17 02:08:15 CST; 39s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 5268 (dhcpd)
   Status: "Dispatching packets..."
   Memory: 4.8M
   CGroup: /system.slice/dhcpd.service
           └─5268 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

五、测试网卡获取DHCP分发地址

在这里插入图片描述

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值