rocky9.1中如何配置静态IP
001、系统
[root@PC1 ~]# hostnamectl Static hostname: PC1 Icon name: computer-vm Chassis: vm 🖴 Machine ID: 0701dfe1316f4cd6be6f958130674e6f Boot ID: 541d72ac4ba142c4a639b3406d5037b5 Virtualization: vmware Operating System: Rocky Linux 9.1 (Blue Onyx) CPE OS Name: cpe:/o:rocky:rocky:9::baseos Kernel: Linux 5.14.0-162.6.1.el9_1.x86_64 Architecture: x86-64 Hardware Vendor: VMware, Inc. Hardware Model: VMware Virtual Platform
002、进入 /etc/NetworkManager/system-connections/ 目录
[root@PC1 ~]# cd /etc/NetworkManager/system-connections/ [root@PC1 system-connections]# ls ens160.nmconnection [root@PC1 system-connections]#
003、修改配置文件
[root@PC1 system-connections]# vim ens160.nmconnection
在ipv4下修改如下内容,然后保存退出:
[ethernet] [ipv4] address1=192.168.254.30/24,192.168.254.2 ## ip,子网掩码,网关 dns=119.29.29.29;114.114.114.114; ## DNS may-fail=false method=manual ## 手动IP
004、加载配置文件
[root@PC1 system-connections]# ls ens160.nmconnection [root@PC1 system-connections]# nmcli connection load /etc/NetworkManager/system-connections/ens160.nmconnection
005、激活配置文件
[root@PC1 system-connections]# ls ens160.nmconnection [root@PC1 system-connections]# nmcli connection up /etc/NetworkManager/system-connections/ens160.nmconnection Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
006、查看IP
[root@PC1 system-connections]# ifconfig | head ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.254.30 netmask 255.255.255.0 broadcast 192.168.254.255 inet6 fe80::20c:29ff:fe36:2755 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:36:27:55 txqueuelen 1000 (Ethernet) RX packets 731 bytes 87910 (85.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 888 bytes 76962 (75.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
007、测试网络
[root@PC1 system-connections]# ping -c 3 www.baidu.com PING www.a.shifen.com (110.242.68.3) 56(84) bytes of data. 64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=128 time=9.94 ms 64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=2 ttl=128 time=10.4 ms 64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=3 ttl=128 time=10.9 ms --- www.a.shifen.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2004ms rtt min/avg/max/mdev = 9.943/10.412/10.865/0.376 ms