Rocky 9 静态IP网络配置
今天安装完rocky9后,发现与以往的rocky8的网卡配置不同,在/etc/sysconfig/network-scripts/
下发现了readme-ifcfg-rh.txt
文件,里面介绍了rocky9在/etc/NetworkManager/system-connections/
下进行网卡的配置,以下为该文件的解释
[root@localhost ~]# more /etc/sysconfig/network-scripts/readme-ifcfg-rh.txt
NetworkManager stores new network profiles in keyfile format in the
/etc/NetworkManager/system-connections/ directory.
Previously, NetworkManager stored network profiles in ifcfg format
in this directory (/etc/sysconfig/network-scripts/). However, the ifcfg
format is deprecated. By default, NetworkManager no longer creates
new profiles in this format.
Connection profiles in keyfile format have many benefits. For example,
this format is INI file-based and can easily be parsed and generated.
Each section in NetworkManager keyfiles corresponds to a NetworkManager
setting name as described in the nm-settings(5) and nm-settings-keyfile(5)
man pages. Each key-value-pair in a section is one of the properties
listed in the settings specification of the man page.
If you still use network profiles in ifcfg format, consider migrating
them to keyfile format. To migrate all profiles at once, enter:
# nmcli connection migrate
This command migrates all profiles from ifcfg format to keyfile
format and stores them in /etc/NetworkManager/system-connections/.
Alternatively, to migrate only a specific profile, enter:
# nmcli connection migrate <profile_name|UUID|D-Bus_path>
For further details, see:
* nm-settings-keyfile(5)
* nmcli(1)
静态IP配置
备份网卡默认配置
[root@localhost ~]# cd /etc/NetworkManager/system-connections/
[root@localhost ~]# cp ens33.nmconnection ens33.nmconnection.bak
[root@localhost system-connections]# ll
total 8
-rw-------. 1 root root 277 Jan 23 03:08 ens33.nmconnection
-rw-------. 1 root root 206 Jan 23 02:47 ens33.nmconnection.bak
编辑网卡配置
[root@localhost system-connections]# more ens33.nmconnection
[connection]
id=ens33
uuid=4cdd786f-5ee3-3b61-82c0-81956a350f79
type=ethernet
autoconnect-priority=-999
interface-name=ens33
[ethernet]
[ipv4]
method=manual
address=10.110.141.102/24,10.110.141.254 #IP地址&掩码、网关配置(两者之间用,隔开)
dns=114.114.114.114;8.8.8.8 #DNS配置(多个dns地址之间用;分开)
[ipv6]
addr-gen-mode=eui64
method=auto
[proxy]
重启网卡
[root@localhost system-connections]# nmcli connection reload
[root@localhost system-connections]# nmcli connection up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/16)
测试通过
[root@localhost system-connections]# ping baidu.com
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=51 time=22.5 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=51 time=22.9 ms
THE END