在虚拟机中ping,发现网络不通:
[root@node01 ~]# ping 114.114.114.114 connect: Network is unreachable
发生此问题时,环境如下:
●网络连接选择的是NAT模式
●虚拟网络配置中NAT模式配置如下:
●/etc/sysconfig/network-scripts/ifcfg-ens33文件内容为
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=stable-privacy NAME=ens33 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.30.136 NETMASK=255.255.255.0 GETWAY=192.168.30.1 DNS1=114.114.114.114
●ip信息为
[root@node01 ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.30.136 netmask 255.255.255.0 broadcast 192.168.30.255 inet6 fe80::20c:29ff:fe4c:9347 prefixlen 64 scopeid 0x20<link> inet6 fd15:4ba5:5a2b:1008:20c:29ff:fe4c:9347 prefixlen 64 scopeid 0x0<global> ether 00:0c:29:4c:93:47 txqueuelen 1000 (Ethernet) RX packets 628 bytes 61587 (60.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 505 bytes 75815 (74.0 KiB) 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> loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.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
参考 “linux关于connect: network is unreachable 问题的解决”(https://blog.csdn.net/xueshao110/article/details/79263498 )这篇博文,添加默认网关问题得到解决:
[root@node01 ~]# route add default gw 192.168.30.1 [root@node01 ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 0 0 0 ens33 link-local 0.0.0.0 255.255.0.0 U 1002 0 0 ens33 192.168.30.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
[root@node01 ~]# ping 114.114.114.114 PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data. 64 bytes from 114.114.114.114: icmp_seq=1 ttl=128 time=6.97 ms 64 bytes from 114.114.114.114: icmp_seq=2 ttl=128 time=6.72 ms 64 bytes from 114.114.114.114: icmp_seq=3 ttl=128 time=7.60 ms 64 bytes from 114.114.114.114: icmp_seq=4 ttl=128 time=4.84 ms 64 bytes from 114.114.114.114: icmp_seq=5 ttl=128 time=6.32 ms ^C --- 114.114.114.114 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4008ms rtt min/avg/max/mdev = 4.841/6.493/7.603/0.928 ms