centos8按照yum及dhcp
一、安装yum
1.1 清理系统自带yum源
[root@master ~]# cd /etc/yum.repos.d/
[root@master yum.repos.d]# mkdir bak
[root@master yum.repos.d]# mkdir *.repo ./bak
[root@master yum.repos.d]# ll
total 4
drwxr-xr-x. 2 root root 4096 Aug 7 2023 bak
1.2 安装yum网络源
wget获取与手动写入二选一,优先选wget获取
1.2.1wget获取阿里源
[root@master yum.repos.d]# wget -O /etc/yum.repos.d/Centos-8.repo http://mirrors.aliyun.com/repo/Centos-8.repo
--2024-12-19 17:27:24-- http://mirrors.aliyun.com/repo/Centos-8.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 175.12.102.187, 113.219.178.241, 219.153.157.235, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|175.12.102.187|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2590 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/Centos-8.repo’/etc/yum.repos.d/Centos-8.repo 100%[=======================================================================================>] 2.53K --.-KB/s in 0.001s 2024-12-19 17:27:24 (3.08 MB/s) - ‘/etc/yum.repos.d/Centos-8.repo’ saved [2590/2590][root@master yum.repos.d]# ll
total 8
drwxr-xr-x. 2 root root 4096 Dec 19 17:24 bak
-rw-r--r--. 1 root root 2590 Aug 4 2022 Centos-8.repo
1.2.2 手动写入
[root@master yum.repos.d]# cat Centos-8.repo
# CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/http://mirrors.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/http://mirrors.cloud.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
1.3 获取yum仓库信息
#清理缓存
[root@master yum.repos.d]# yum clean all
23 files removed
#获取新的仓库缓存及信息
[root@master yum.repos.d]# yum makecache
CentOS-8 - Base - mirrors.aliyun.com 32 kB/s | 3.9 kB 00:00
CentOS-8 - Extras - mirrors.aliyun.com 94 kB/s | 1.5 kB 00:00
CentOS-8 - AppStream - mirrors.aliyun.com 275 kB/s | 4.3 kB 00:00
Metadata cache created.
[root@master yum.repos.d]# yum repolist
repo id repo name
AppStream CentOS-8 - AppStream - mirrors.aliyun.com
base CentOS-8 - Base - mirrors.aliyun.com
extras CentOS-8 - Extras - mirrors.aliyun.com
[root@master yum.repos.d]#
二、安装dhcp
2.1 安装dhcp包
[root@master yum.repos.d]# yum install -y dhcp-server.x86_64
Last metadata expiration check: 0:33:01 ago on Thu 19 Dec 2024 05:53:13 PM CST.
Dependencies resolved.
===========================================================================================================================================================================Package Architecture Version Repository Size
===========================================================================================================================================================================
Installing:dhcp-server x86_64 12:4.3.6-45.el8 base 530 k
Upgrading:bind-export-libs x86_64 32:9.11.26-6.el8 base 1.1 Mdhcp-client x86_64 12:4.3.6-45.el8 base 318 kdhcp-common noarch 12:4.3.6-45.el8 base 207 kdhcp-libs x86_64 12:4.3.6-45.el8 base 148 kTransaction Summary
===========================================================================================================================================================================
Install 1 Package
Upgrade 4 PackagesTotal download size: 2.3 M
Downloading Packages:
(1/5): dhcp-client-4.3.6-45.el8.x86_64.rpm 1.5 MB/s | 318 kB 00:00
(2/5): bind-export-libs-9.11.26-6.el8.x86_64.rpm 3.5 MB/s | 1.1 MB 00:00
(3/5): dhcp-server-4.3.6-45.el8.x86_64.rpm 1.4 MB/s | 530 kB 00:00
(4/5): dhcp-libs-4.3.6-45.el8.x86_64.rpm 1.4 MB/s | 148 kB 00:00
(5/5): dhcp-common-4.3.6-45.el8.noarch.rpm 365 kB/s | 207 kB 00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 3.0 MB/s | 2.3 MB 00:00
warning: /var/cache/dnf/base-be643a1e920f6036/packages/dhcp-server-4.3.6-45.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - Base - mirrors.aliyun.com 13 kB/s | 1.6 kB 00:00
Importing GPG key 0x8483C65D:Userid : "CentOS (CentOS Official Signing Key) <security@centos.org>"Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65DFrom : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing : 1/1 Upgrading : dhcp-libs-12:4.3.6-45.el8.x86_64 1/9 Upgrading : dhcp-common-12:4.3.6-45.el8.noarch 2/9 Upgrading : bind-export-libs-32:9.11.26-6.el8.x86_64 3/9 Running scriptlet: bind-export-libs-32:9.11.26-6.el8.x86_64 3/9 Running scriptlet: dhcp-server-12:4.3.6-45.el8.x86_64 4/9 Installing : dhcp-server-12:4.3.6-45.el8.x86_64 4/9 Running scriptlet: dhcp-server-12:4.3.6-45.el8.x86_64 4/9 Upgrading : dhcp-client-12:4.3.6-45.el8.x86_64 5/9 Cleanup : dhcp-client-12:4.3.6-40.el8.x86_64 6/9 Cleanup : dhcp-common-12:4.3.6-40.el8.noarch 7/9 Cleanup : dhcp-libs-12:4.3.6-40.el8.x86_64 8/9 Cleanup : bind-export-libs-32:9.11.13-3.el8.x86_64 9/9 Running scriptlet: bind-export-libs-32:9.11.13-3.el8.x86_64 9/9 Verifying : dhcp-server-12:4.3.6-45.el8.x86_64 1/9 Verifying : bind-export-libs-32:9.11.26-6.el8.x86_64 2/9 Verifying : bind-export-libs-32:9.11.13-3.el8.x86_64 3/9 Verifying : dhcp-client-12:4.3.6-45.el8.x86_64 4/9 Verifying : dhcp-client-12:4.3.6-40.el8.x86_64 5/9 Verifying : dhcp-common-12:4.3.6-45.el8.noarch 6/9 Verifying : dhcp-common-12:4.3.6-40.el8.noarch 7/9 Verifying : dhcp-libs-12:4.3.6-45.el8.x86_64 8/9 Verifying : dhcp-libs-12:4.3.6-40.el8.x86_64 9/9 Upgraded:bind-export-libs-32:9.11.26-6.el8.x86_64 dhcp-client-12:4.3.6-45.el8.x86_64 dhcp-common-12:4.3.6-45.el8.noarch dhcp-libs-12:4.3.6-45.el8.x86_64 Installed:dhcp-server-12:4.3.6-45.el8.x86_64 Complete!
2.2 修改dhcp配置文件
[root@master yum.repos.d]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.20.0 netmask 255.255.255.0 {# DHCP地址池range 192.168.20.100 192.168.20.200;# 默认网关 option routers 192.168.20.1;# DNS服务器option domain-name-servers 8.8.8.8;# 默认租约时间 default-lease-time 600;# 最大租约时间max-lease-time 7200;}
2.3 设置防火墙放行
[root@master yum.repos.d]# firewall-cmd --zone=public --add-service=dhcp --permanent
success
[root@master yum.repos.d]# firewall-cmd --reload
success
[root@master yum.repos.d]#
2.4 启动dhcp及自启动
重启dhcp服务
[root@master yum.repos.d]# systemctl restart dhcpd
自启动dhcp服务
[root@master yum.repos.d]# systemctl enable dhcpd
Created symlink /etc/systemd/system/multi-user.target.wants/dhcpd.service → /usr/lib/systemd/system/dhcpd.service.
2.5 查看dhcp服务状态
查看dhcp状态
[root@master yum.repos.d]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server DaemonLoaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)Active: active (running) since Thu 2024-12-19 18:57:55 CST; 7s agoDocs: man:dhcpd(8)man:dhcpd.conf(5)Main PID: 25005 (dhcpd)Status: "Dispatching packets..."Tasks: 1 (limit: 11298)Memory: 5.1MCGroup: /system.slice/dhcpd.service└─25005 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pidDec 19 18:57:55 master dhcpd[25005]: Config file: /etc/dhcp/dhcpd.conf
Dec 19 18:57:55 master dhcpd[25005]: Database file: /var/lib/dhcpd/dhcpd.leases
Dec 19 18:57:55 master dhcpd[25005]: PID file: /var/run/dhcpd.pid
Dec 19 18:57:55 master dhcpd[25005]: Source compiled to use binary-leases
Dec 19 18:57:55 master dhcpd[25005]: Wrote 0 leases to leases file.
Dec 19 18:57:55 master dhcpd[25005]: Listening on LPF/ens160/00:0c:29:97:d9:ba/192.168.20.0/24
Dec 19 18:57:55 master dhcpd[25005]: Sending on LPF/ens160/00:0c:29:97:d9:ba/192.168.20.0/24
Dec 19 18:57:55 master dhcpd[25005]: Sending on Socket/fallback/fallback-net
Dec 19 18:57:55 master dhcpd[25005]: Server starting service.
Dec 19 18:57:55 master systemd[1]: Started DHCPv4 Server Daemon.
三、测试dhcp
测试前需设置本机静态IP地址
需关闭网络内其他dhcp服务