rocky8 中配置静态IP

 

001、查看系统信息

[root@localhost ~]# hostnamectl
   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 0f5ac3970da4429fa028c356ef25e662
           Boot ID: 5012d6e8a2084e5bb03d46166d4550ca
    Virtualization: vmware
  Operating System: Rocky Linux 8.10 (Green Obsidian)
       CPE OS Name: cpe:/o:rocky:rocky:8:GA
            Kernel: Linux 4.18.0-553.el8_10.x86_64
      Architecture: x86-64

 

002、进入网卡配置文件所在的目录

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens160
[root@localhost network-scripts]# 

 

003、编辑网卡配置文件如下,让后保存退出

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=eui64
NAME=ens160
UUID=9a82746f-d9b3-4152-87ee-9483e45c3842
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.30.133
NETMASK=255.255.255.0
GATEWAY=192.168.30.2
DNS1=119.29.29.29
DNS2=8.8.8.8

 

004、调整网络适配器模式

 

 005、重启网络服务

[root@localhost network-scripts]# ifconfig | head          ## 查看IP
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:2c:1e:55  txqueuelen 1000  (Ethernet)
        RX packets 1  bytes 247 (247.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
[root@localhost network-scripts]# nmcli connection reload           ## 重新连接网卡
[root@localhost network-scripts]# ifconfig | head                   ## ip生效,但是无法联网,为啥?
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.30.133  netmask 255.255.255.0  broadcast 192.168.30.255
        inet6 fe80::20c:29ff:fe2c:1e55  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:2c:1e:55  txqueuelen 1000  (Ethernet)
        RX packets 8729  bytes 12750309 (12.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 825  bytes 52873 (51.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
[root@localhost network-scripts]# ping -c www.baidu.com             ## 无法联网
ping: bad number of packets to transmit.

 。

 

006、

[root@localhost network-scripts]# nmcli connection up ens160            ## 网卡生效
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
[root@localhost network-scripts]# ifconfig | head                       ## 查看ip
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.30.133  netmask 255.255.255.0  broadcast 192.168.30.255
        inet6 fe80::20c:29ff:fe2c:1e55  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:2c:1e:55  txqueuelen 1000  (Ethernet)
        RX packets 936396  bytes 1375774442 (1.2 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 208167  bytes 11331406 (10.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
[root@localhost network-scripts]# ping -c 3 www.baidu.com              ## 测试网络连通性
PING www.a.shifen.com (39.156.66.14) 56(84) bytes of data.
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=1 ttl=128 time=16.5 ms
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=2 ttl=128 time=16.2 ms
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=3 ttl=128 time=17.1 ms

--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 16.246/16.634/17.111/0.358 ms

 。

 

ref:

01、https://blog.csdn.net/m0_62934345/article/details/134815331

posted @ 2024-08-21 12:43  小鲨鱼2018  阅读(3)  评论(0编辑  收藏  举报