创建完虚拟机centos后,有时不能上网,ping www.baidu.com时,出现connect: Network is unreachable,但ping网关又正常,有可能是本地没有默认的路由
0.ping外网提示connect: Network is unreachable
[root@localhost network-scripts]# ping www.baidu.com
connect: Network is unreachable
1.使用ip route查看
[root@localhost network-scripts]# ip route
192.168.1.0/24 dev eno16777736 proto kernel scope link src 192.168.1.200
2.使用route -n查看
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777736
3.添加静态的默认路由,即网关
[root@localhost network-scripts]# route add default gw 192.168.1.1
4.再次查看路由表
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eno16777736
0.0.0.0 192.168.1.1 0.0.0.0 UG 1024 0 0 eno16777736
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777736
5.再次进行ping外网
[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=52 time=39.3 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=52 time=2.01 ms