Linux无法解析域名的背后原因

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux无法解析域名的背后原因相关的知识,希望对你有一定的参考价值。

生产环境:

操作系统:CentOS release 6.8 (Final)

问题:无法解析域名,无法ping ip,公网不畅通。 

分析:由电信专线换成联通专线,很有可能是这种原因造成的,但是IP和DNS都换成了联通啊。

解决问题过程:

[[email protected] ~]#wget  https://cn.wordpress.org/wordpress-4.8.1-zh_CN.tar.gz

--2017-09-0410:46:26-- https://cn.wordpress.org/wordpress-4.8.1-zh_CN.tar.gz

正在解析主机 cn.wordpress.org... 失败:域名解析暂时失败。

wget: 无法解析主机地址 “cn.wordpress.org”

[[email protected] ~]#ping  www.hao123.com      #无法解析

ping: unknown host www.hao123.com 

 

[[email protected] ~]#cat  /etc/resolv.conf

nameserver202.101.224.68  #这个是电信的DNS,要改吗?

nameserver 8.8.8.8

nameserver 8.8.4.4

 

[[email protected] ~]#cat /etc/resolv.conf

nameserver220.248.192.12   #修改成联通的DNS

nameserver 8.8.8.8

nameserver 8.8.4.4

 

[[email protected] ~]#ping www.hao123.com

ping: unknown host www.hao123.com   #还是无法解析

 

[[email protected] ~]# netstat –rn   #查看路由信息,发现联通网关不存在

Kernel IP routingtable

Destination     Gateway         Genmask         Flags  MSS Window  irtt Iface

113.195.210.0  0.0.0.0         255.255.255.0   U        0 0          0 eth0

117.40.239.0   0.0.0.0         255.255.255.0   U        0 0          0 eth0

169.254.0.0   0.0.0.0         255.255.0.0     U        0 0          0 eth0

0.0.0.0       117.40.239.1    0.0.0.0         UG        0 0          0 eth0

[[email protected] ~]#route add  default  gw  113.195.210.1  #添加联通网关

[[email protected] ~]#netstat -rn

Kernel IP routingtable

Destination     Gateway         Genmask         Flags  MSS Window  irtt Iface

113.195.210.0   0.0.0.0         255.255.255.0   U        0 0          0 eth0

117.40.239.0    0.0.0.0         255.255.255.0   U        0 0          0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U        0 0          0 eth0

0.0.0.0         113.195.210.1   0.0.0.0         UG        0 0          0 eth0

0.0.0.0         117.40.239.1    0.0.0.0         UG        0 0          0 eth0

 

[[email protected] ~]#ping www.hao123.com   #可以解析了,但延时严重哦

PING hao123.n.shifen.com(112.80.248.211) 56(84) bytes of data.

64 bytes from112.80.248.211: icmp_seq=1 ttl=55 time=31.0 ms

64 bytes from112.80.248.211: icmp_seq=2 ttl=55 time=33.4 ms

64 bytes from 112.80.248.211:icmp_seq=3 ttl=55 time=31.0 ms

64 bytes from112.80.248.211: icmp_seq=4 ttl=55 time=31.1 ms

64 bytes from112.80.248.211: icmp_seq=5 ttl=55 time=31.1 ms

 

[[email protected] ~]#wget https://cn.wordpress.org/wordpress-4.8.1-zh_CN.tar.gz

--2017-09-0411:11:47-- https://cn.wordpress.org/wordpress-4.8.1-zh_CN.tar.gz

正在解析主机 cn.wordpress.org... 66.155.40.250, 66.155.40.249

正在连接 cn.wordpress.org|66.155.40.250|:443... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:8641990 (8.2M) [application/octet-stream]

正在保存至: wordpress-4.8.1-zh_CN.tar.gz

  8% [===>                                             ]716,386      399K/s              ^Z

[8]+  Stopped                 wgethttps://cn.wordpress.org/wordpress-4.8.1-zh_CN.tar.gz

   小结:最终原因是在设置网关时少写了一个字母“T”,同时把备份的"ifcfg-eth0"相关文件删除,重新启动网络服务,会把相对应的电信IP和网关自动删除掉,从而避免冲突。

[[email protected] network-scripts]#vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=static

IPADDR=113.195.*.*

NETMASK=255.255.255.0    

GATEWAY=113.195.*.*   #少写了一个字母”T”,导致找不到网关

DNS=220.248.192.12   #联通DNS

HWADDR=00:21:97:68:F2:70

TYPE=Ethernet

UUID=480c82ca-d673-466d-902a-9f31eaeb897c

ONBOOT=yes

NM_CONTROLLED=no

   到这里把所有上述问题解决掉了。

   顺便测试一下联通网络:

[[email protected] network-scripts]# speedtest-cli --share

Retrieving speedtest.net configuration...

Retrieving speedtest.net server list...

Testing from China Unicom (113.195.210.147)...

Selecting best server based on latency...

Hosted by ChinaTelecom.Hunan (Changsha) [107.66 km]: 34.473 ms

Testing download speed........................................

Download: 79.57 Mbit/s   #下载速度

Testing upload speed..................................................

Upload: 48.33 Mbit/s     #上传速度

Share results: https://www.speedtest.net/result/6594856504.png  #测试结果

[[email protected] network-scripts]# speedtest-cli 

Retrieving speedtest.net configuration...

Retrieving speedtest.net server list...

Testing from China Unicom (113.195.210.147)...

Selecting best server based on latency...

Hosted by ChinaTelecom.Hunan (Changsha) [107.66 km]: 36.537 ms

Testing download speed........................................

Download: 49.98 Mbit/s  #下载速度

Testing upload speed..................................................

Upload: 45.33 Mbit/s   #上传速度


[[email protected] network-scripts]#  speedtest-cli 

Retrieving speedtest.net configuration...

Retrieving speedtest.net server list...

Testing from China Unicom (113.195.210.147)...

Selecting best server based on latency...

Hosted by ChinaTelecom.Hunan (Changsha) [107.66 km]: 45.695 ms

Testing download speed........................................

Download: 81.35 Mbit/s

Testing upload speed..................................................

Upload: 22.21 Mbit/s


本文出自 “sky9890” 博客,请务必保留此出处http://sky9896.blog.51cto.com/2330653/1962474

以上是关于Linux无法解析域名的背后原因的主要内容,如果未能解决你的问题,请参考以下文章

Dokcer容器内无法域名解析

域名无法访问怎么办?是啥原因?

实用技能:域名解析导致网站无法访问的原因和解决方法

域名无法访问怎么办?是啥原因?

无法解析此远程名称 求大神帮下啊

我的Linux不能解析域名怎么办?