码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2017-09-04 15:08:31      阅读:635      评论:0      收藏:0      [点我收藏+]

标签:域名解析、公网ip、网关

生产环境:

操作系统:CentOS release 6.8 (Final)

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

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

解决问题过程:

[root@sky9896 ~]#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”

[root@sky9896 ~]#ping  www.hao123.com      #无法解析

ping: unknown host www.hao123.com 

 

[root@sky9896 ~]#cat  /etc/resolv.conf

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

nameserver 8.8.8.8

nameserver 8.8.4.4

 

[root@sky9896 ~]#cat /etc/resolv.conf

nameserver220.248.192.12   #修改成联通的DNS

nameserver 8.8.8.8

nameserver 8.8.4.4

 

[root@sky9896 ~]#ping www.hao123.com

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

 

[root@sky9896 ~]# 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

[root@sky9896 ~]#route add  default  gw  113.195.210.1  #添加联通网关

[root@sky9896 ~]#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

 

[root@sky9896 ~]#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

 

[root@sky9896 ~]#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和网关自动删除掉,从而避免冲突。

[root@sky9896 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

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

   顺便测试一下联通网络:

[root@sky9896 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  #测试结果

[root@sky9896 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   #上传速度


[root@sky9896 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无法解析域名的背后原因

标签:域名解析、公网ip、网关

原文地址:http://sky9896.blog.51cto.com/2330653/1962474

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!