在 CentOS Stream 8 中,网络配置通常使用 NetworkManager(推荐方式),也可以通过修改配置文件来实现。下面按常见场景说明。
nmcli device status
或
ip addr
nmcli connection add type ethernet ifname eth0 con-name eth0
nmcli connection modify eth0 ipv4.method auto
nmcli connection up eth0
将
eth0替换为你的网卡名(如 ens33)
nmcli connection modify eth0 \
ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns 8.8.8.8
启用连接:
nmcli connection up eth0
nmcli connection modify eth0 ipv4.dns "8.8.8.8 114.114.114.114"
nmcli connection up eth0
配置文件路径:
/etc/sysconfig/network-scripts/ifcfg-eth0
示例(静态 IP):
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
重启网络:
nmcli connection reload
nmcli connection up eth0
或
systemctl restart NetworkManager
hostnamectl set-hostname node1
ping 8.8.8.8
ping www.baidu.com
nmcli connection show
nmcli connection up eth0
nmcli connection add type ethernet ifname eth0
如果你有 具体场景(比如:桥接、双网卡、云服务器、无图形界面),可以告诉我,我给你更精确的配置示例。