方法1:
安装systemd-networkd
sudo dnf install systemd-networkd
ifconfig 查看要修改的网络,然后启动服务:
sudo systemctl enable --now systemd-networkd
在 /etc/systemd/network/ 目录下创建文件eth0.network来配置 eth0 接口
[Match]
Name=eth0
[Network]
Address=172.21.8.20/20
Gateway=172.21.0.1
DNS=114.114.114.114
重启服务查看是否生效
sudo systemctl restart systemd-networkd
方法2:
安装并启动服务
sudo yum install NetworkManager
sudo systemctl start NetworkManager
sudo systemctl enable NetworkManager
查看网络连接确定要修改的网络名称:
nmcli d
设置你的ip地址网关DNS等:
nmcli connection modify eth0 ipv4.addresses 172.21.8.22/20 ipv4.gateway 172.21.0.1 ipv4.dns "114.114.114.114 8.8.8.8" ipv4.method manual
ipv4.addresses 172.21.8.22/20:设置静态 IP 地址和子网掩码。
ipv4.gateway 172.21.0.1:设置默认网关。
ipv4.dns "114.114.114.114 8.8.8.8":设置 DNS 服务器地址。
ipv4.method manual:指定 IPv4 配置方式为手动(静态)
使生效
nmcli device reapply eth0
或者
nmcli connection down eth0 && nmcli connection up eth0
然后重启网络
sudo systemctl restart NetworkManager
标签:systemd,ip,sudo,wsl,172.21,ipv4,centos8,114.114,eth0
From: https://blog.csdn.net/lu6603547/article/details/140913438