centos7 ping外网问题

一、提前说两句
在centos7工作环境中,无论是玩爬虫还是安装更新软件我们可能都需要连接外网,但是经常会出现无法连接外网的情况。现在我们一起解决常见的几种ping 不通外网的情况。

二、解决问题
1.mtu值
在安装docker时,我们遇到了云主机的mtu值和物理环境的mtu值不同的问题。
解决方案参考《mtu值不匹配问题》

2.DNS问题
查看路由

[root@cgls]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         
0.0.0.0         192.168.11.1    0.0.0.0        
192.168.11.0    0.0.0.0         255.255.255.0  
192.168.111.0   0.0.0.0         255.255.255.0  

如果你缺失第一个路由,是肯定无法ping通外网的。

添加dns

[root@cgls]# vim /etc/resolv.conf
nameserver 114.114.114.114
nameserver 8.8.8.8

添加路由

[root@cgls]# route add default gw 192.168.11.1

现在问题解决了,试一下ping百度

[root@cgls]# ping www.baidu.com

问题解决。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章