如何为CentOS Stream 910配置静态IP及dnfyum源?
摘要:CentOS Stream 9CentOS Stream 10配置静态IP和配置dnfyum源;**CentOS Stream 9****CentOS Stream 10**概述;NetworkManager配置静态IP;nmcli配
目录一.CentOS Stream 9/CentOS Stream 10概述二.系统环境三.CentOS Stream 9/CentOS Stream 10配置静态IP3.1 NetworkManager配置静态IP3.2 nmcli配置静态IP四.centos9/centos10配置dnf/yum源4.1 dnf概述4.2 dnf常用命令4.3 配置dnf/yum源
一.CentOS Stream 9/CentOS Stream 10概述
CentOS Stream 是 Red Hat Enterprise Linux (RHEL) 的上游开发分支,采用“滚动更新”模式。这意味着它介于 Fedora 和 RHEL 之间,让你能提前看到 RHEL 未来的功能。
特性
CentOS Stream 9
CentOS Stream 10
对应 RHEL 版本
RHEL 9 系列
RHEL 10 系列
内核版本
Kernel 5.14
Kernel 6.12+ (显著更新)
Python 默认版本
Python 3.9
Python 3.12 (性能更强)
编译器工具链
GCC 11
GCC 14 (支持新语言特性)
系统架构
传统 YUM/DNF
引入 System Wide Image (SWI) 和 Bootable Container 概念
生命周期
维护至 2027 年 (全支持) / 2032 年 (维护支持)
预计维护至 2030 年代初
代号
无特定代号
Coughlan
二.系统环境
服务器版本
内核版本
CentOS Stream release 10 (Coughlan)
6.12.0-212.el10.x86_64
CentOS Stream release 9
5.14.0-687.el9.x86_64
三.CentOS Stream 9/CentOS Stream 10配置静态IP
3.1 NetworkManager配置静态IP
CentOS Stream 9/CentOS Stream 10的网络配置文件不再使用/etc/sysconfig/network-scripts/ifcfg-eth0,network服务已经弃用,默认使用NetworkManager管理网络,配置文件位于/etc/NetworkManager/system-connections/目录下。
[root@localhost ~]# cd /etc/NetworkManager/system-connections/
[root@localhost system-connections]# ls
ens160.nmconnection
修改配置文件,指定机器静态IP为192.168.0.132。
address1:指定静态IP地址和子网掩码(CIDR格式);
dns:指定DNS服务器列表,多个地址用分号分隔,建议使用国内的DNS服务器地址,这样更快,比如:223.5.5.5;223.6.6.6;
method:method=manual表示强制使用手动配置模式,method=auto表示启用 DHCP (动态主机配置协议),动态获取IP;
gateway:指定服务器网关。
[root@localhost system-connections]# vim ens160.nmconnection
[root@localhost system-connections]# cat ens160.nmconnection
[connection]
#网卡名称
id=ens160
#系统内部用来唯一标识这个连接配置。即使你把 id 改名了,UUID 也不会变,确保系统不会搞混。
uuid=89fcf374-9ca1-30b1-b1dd-ed124953574c
#表明这是一个标准的以太网(有线网卡)连接。
type=ethernet
#自动连接优先级。这是一个非常低的优先级(范围通常是 -999 到 999)。
autoconnect-priority=-999
#绑定的物理网卡名称。
interface-name=ens160
timestamp=1775042953
[ethernet]
#双工模式设置为半双工。半双工意味着同一时间只能发数据或收数据,不能同时进行,且容易发生冲突。这会严重限制网卡性能。除非连接的是非
#常古老的集线器(Hub)或特殊工业设备,否则建议改为 duplex=full 或直接删除此行让网卡自动协商。
duplex=half
#强制网卡速率锁定为 10000 Mbps (10 Gbps)。
speed=10000
[ipv4]
address1=192.168.0.132/24
dns=223.5.5.5;223.6.6.6;119.29.29.29;182.254.116.116;
gateway=192.168.0.2
method=manual
[ipv6]
#地址生成模式。使用 EUI-64 算法基于网卡的 MAC 地址生成 IPv6 地址的后 64 位。这种方式生成的地址是固定的,便于追踪,但隐私性不如#默认的“稳定隐私地址”。
addr-gen-mode=eui64
#自动模式。
method=auto
[proxy]
重载配置文件并重启。
[root@localhost system-connections]# systemctl restart NetworkManager
[root@localhost system-connections]# systemctl status NetworkManager
● NetworkManager.service - Network Manager
Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; preset: enabled)
Active: active (running) since Thu 2026-04-02 22:06:20 CST; 8s ago
Invocation: ed6964f8bf7d4a7aa7301b361329c36a
Docs: man:NetworkManager(8)
Main PID: 1841 (NetworkManager)
Tasks: 5 (limit: 23984)
Memory: 3.4M (peak: 4.3M)
CPU: 52ms
CGroup: /system.slice/NetworkManager.service
└─1841 /usr/sbin/NetworkManager --no-daemon
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7000] device (ens1>
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7015] policy: set >
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7054] device (ens1>
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7071] device (ens1>
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7072] device (ens1>
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7075] manager: Net>
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7076] device (ens1>
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7079] manager: Net>
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.7080] manager: sta>
4月 02 22:06:20 localhost.localdomain NetworkManager[1841]: <info> [1775138780.8850] policy: set->
在/etc/NetworkManager/system-connections/ens160.nmconnection里配置了DNS之后,/etc/resolv.conf 里的DNS也会变化。
[root@localhost system-connections]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 223.5.5.5
nameserver 223.6.6.6
nameserver 119.29.29.29
# NOTE: the libc resolver may not support more than 3 nameservers.
# The nameservers listed below may not be recognized.
nameserver 182.254.116.116
查看IP发现ip配置成功,也能上网了。
[root@localhost system-connections]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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 noprefixroute
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:de:bf:87 brd ff:ff:ff:ff:ff:ff
altname enp3s0
altname enx000c29debf87
inet 192.168.0.132/24 brd 192.168.0.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fede:bf87/64 scope link noprefixroute
valid_lft forever preferred_lft forever
#查看路由
[root@localhost system-connections]# ip r
default via 192.168.0.2 dev ens160 proto static metric 100
192.168.0.0/24 dev ens160 proto kernel scope link src 192.168.0.132 metric 100
#可以上网
[root@localhost system-connections]# ping qq.com
PING qq.com (113.108.81.189) 56(84) 字节的数据。
64 字节,来自 113.108.81.189: icmp_seq=1 ttl=128 时间=61.3 毫秒
64 字节,来自 113.108.81.189: icmp_seq=2 ttl=128 时间=71.2 毫秒
64 字节,来自 113.108.81.189: icmp_seq=3 ttl=128 时间=69.3 毫秒
64 字节,来自 113.108.81.189: icmp_seq=4 ttl=128 时间=71.7 毫秒
64 字节,来自 113.108.81.189: icmp_seq=5 ttl=128 时间=69.7 毫秒
64 字节,来自 113.108.81.189: icmp_seq=6 ttl=128 时间=68.2 毫秒
^C
--- qq.com ping 统计 ---
已发送 7 个包, 已接收 6 个包, 14.2857% packet loss, time 6004ms
rtt min/avg/max/mdev = 61.309/68.572/71.737/3.449 ms
3.2 nmcli配置静态IP
在 CentOS Stream 9 中,网络管理已经完全转向由 NetworkManager 主导。nmcli(NetworkManager Command Line Interface)是其核心的命令行工具。相比传统的 ifcfg 脚本或 ip addr 命令,nmcli 的优势在于它的配置是持久化的(重启不失效),且能实时反映 NetworkManager 的状态。
nmcli常用命令:
操作类型
命令示例
说明
查看状态
nmcli general status
查看 NetworkManager 整体运行状态
查看设备
nmcli device status
查看所有网卡及其连接状态
查看连接
nmcli connection show
列出所有已保存的连接配置文件
启用连接
nmcli connection up <ID>
激活指定的连接配置
禁用连接
nmcli connection down <ID>
断开指定的连接
重新加载
nmcli connection reload
修改配置文件后,重新加载到内存
修改网卡为静态IP,IP地址配置为192.168.0.132。
ipv4.addresses:静态IP地址(CIDR格式);
ipv4.gateway:默认网关;
ipv4.dns:DNS服务器列表(逗号分隔)。
[root@localhost ~]# nmcli connection modify "ens33" \
ipv4.addresses "192.168.0.132/24" \
ipv4.gateway "192.168.0.2" \
ipv4.dns "223.5.5.5,8.8.8.8" \
ipv4.method manual
激活配置。
[root@localhost ~]# nmcli connection down ens33 && sudo nmcli connection up ens33
查看具体连接详情。
[root@localhost ~]# nmcli connection show ens33
四.centos9/centos10配置dnf/yum源
4.1 dnf概述
dnf (Dandified YUM) 是基于 RPM 的 Linux 发行版的新一代软件包管理器,专为 Fedora、RHEL 8+ 及 CentOS Stream 9/10 等系统设计,作为 yum 的直接替代品,dnf 解决了 yum 的性能瓶颈和功能限制,同时保持了类似的命令语法,在 CentOS Stream 9/10 中,yum 命令实际上是指向 dnf 的符号链接,执行 yum 时实际调用的是 dnf 功能。
[root@localhost ~]# ll -h /usr/bin/yum
lrwxrwxrwx. 1 root root 5 2月16日 08:00 /usr/bin/yum -> dnf-3
[root@localhost ~]# ll -h /usr/bin/dnf
lrwxrwxrwx. 1 root root 5 2月16日 08:00 /usr/bin/dnf -> dnf-3
4.2 dnf常用命令
命令类型
命令示例
功能描述
使用场景
基础安装
sudo dnf install <package>
安装指定软件包
安装新软件
sudo dnf install <package1> <package2>
同时安装多个软件包
批量安装
sudo dnf install -y <package>
自动确认安装(无需交互)
自动化脚本
软件包管理
sudo dnf remove <package>
卸载软件包
移除不需要的软件
sudo dnf update
更新所有已安装的软件包
系统升级
sudo dnf update <package>
更新特定软件包
选择性更新
sudo dnf autoremove
自动清理不再需要的依赖
系统精简
查询与搜索
dnf search <keyword>
搜索软件包
查找可用软件
dnf info <package>
查看软件包详细信息
了解软件详情
dnf provides /path/to/file
查找提供特定文件的软件包
问题排查
dnf list installed
列出所有已安装软件包
系统审计
仓库管理
dnf repolist
列出所有启用的仓库
检查源配置
dnf repolist --verbose
显示仓库详细信息(URL、状态等)
源问题排查
sudo dnf config-manager --enable <repo>
启用指定仓库
添加新源
sudo dnf config-manager --disable <repo>
禁用指定仓库
临时移除源
缓存管理
sudo dnf clean all
清除所有缓存(元数据和软件包)
解决缓存问题
sudo dnf makecache
重建缓存
源更新后
sudo dnf clean packages
仅删除已下载的.rpm文件
释放磁盘空间
事务与历史
dnf history
查看所有操作记录
审计系统变更
dnf history info 5
查看第5条记录的详细变更
问题分析
sudo dnf history undo 5
撤销第5条操作
系统回滚
模块化功能
dnf module list
列出可用的模块
查看多版本软件
sudo dnf module enable php:8.0
启用特定模块
使用指定版本
sudo dnf module install php
安装模块化软件
安装多版本软件
高级功能
dnf download <package> --resolve
下载软件包及其依赖(不安装)
离线安装准备
sudo dnf install ./*.rpm
安装本地下载的RPM包
离线安装
sudo dnf repair
尝试自动修复系统
解决软件包损坏问题
4.3 配置dnf/yum源
备份原先的repo文件。
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
centos-addons.repo centos.repo
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak/
[root@localhost yum.repos.d]# ls
bak
配置阿里云的yum源:ali-centos.repo 。
[root@localhost yum.repos.d]# cat ali-centos.repo
[baseos]
name=CentOS Stream $releasever - BaseOS
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1
[baseos-debug]
name=CentOS Stream $releasever - BaseOS - Debug
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[baseos-source]
name=CentOS Stream $releasever - BaseOS - Source
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[appstream]
name=CentOS Stream $releasever - AppStream
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1
[appstream-debug]
name=CentOS Stream $releasever - AppStream - Debug
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[appstream-source]
name=CentOS Stream $releasever - AppStream - Source
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[crb]
name=CentOS Stream $releasever - CRB
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1
[crb-debug]
name=CentOS Stream $releasever - CRB - Debug
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[crb-source]
name=CentOS Stream $releasever - CRB - Source
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
配置阿里云的yum源:ali-addons.repo 。
[root@localhost yum.repos.d]# cat ali-addons.repo
[highavailability]
name=CentOS Stream $releasever - HighAvailability
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0
[highavailability-debug]
name=CentOS Stream $releasever - HighAvailability - Debug
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[highavailability-source]
name=CentOS Stream $releasever - HighAvailability - Source
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[nfv]
name=CentOS Stream $releasever - NFV
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0
[nfv-debug]
name=CentOS Stream $releasever - NFV - Debug
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[nfv-source]
name=CentOS Stream $releasever - NFV - Source
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[rt]
name=CentOS Stream $releasever - RT
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0
[rt-debug]
name=CentOS Stream $releasever - RT - Debug
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[rt-source]
name=CentOS Stream $releasever - RT - Source
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[resilientstorage]
name=CentOS Stream $releasever - ResilientStorage
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0
[resilientstorage-debug]
name=CentOS Stream $releasever - ResilientStorage - Debug
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[resilientstorage-source]
name=CentOS Stream $releasever - ResilientStorage - Source
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
[extras-common]
name=CentOS Stream $releasever - Extras packages
baseurl=http://mirrors.aliyun.com/centos-stream/SIGs/$stream/extras/$basearch/extras-common/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1
[extras-common-source]
name=CentOS Stream $releasever - Extras packages - Source
baseurl=http://mirrors.aliyun.com/centos-stream/SIGs/$stream/extras/source/extras-common/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0
安装EPEL 仓库(提供额外软件包)。
[root@localhost yum.repos.d]# dnf install epel-release
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@localhost yum.repos.d]# ls
ali-addons.repo ali-centos.repo bak epel.repo epel-testing.repo
清除所有缓存(元数据和软件包)。
[root@localhost ~]# dnf clean all
重建缓存以及更新所有已安装的软件包
[root@localhost ~]# dnf makecache
[root@localhost ~]# dnf update
自此yum源配置完毕。
