如何在 CentOS Stream 9 中设置静态 IP?

Cha*_*ell 3 networking centos network-interface

我在虚拟机管理程序上安装了新版本的 CentOS,但发现它/etc/sysconfig/network-scripts/*不存在。在8版本中我设置了例如bootproto=staticipaddr=192.168.88.101. 在9版本中如何正确设置静态IP?

Mar*_*ler 5

我会直接去

## get a listing of network interfaces
nmcli device
# list here.. say, there's an enp3s0
#
alias cm="nmcli connection modify"
cm enp3s0 ipv4.addresses 192.168.88.101/24
#cm enp3s0 ipv4.gateway, .dns, ...
cm enp3s0 ipv4.method manual
# apply these settings right away!
nmcli connection down enp3s0 ; nmcli connection up enp3s0
Run Code Online (Sandbox Code Playgroud)

如果我使用systemd's NetworkManager(你似乎打算这样做!)。

如果使用systemd-networkd,这可能是正确的方法,特别是对于服务器来说,创建目录/etc/systemd/network,并放置配置(例如,20-wired.network您的网络接口的文件)。arch Linux wiki 有更多示例,但以下来自页面man systemd.network

# /etc/systemd/network/50-static.network
[Match]
Name=enp2s0

[Network]
Address=192.168.88.101/24
Gateway=192.168.88.1
# DNS=10.1.10.1
Run Code Online (Sandbox Code Playgroud)

systemctl disable --now NetworkManager; systemctl enable --now systemd-networkd也许你必须这样做。