问题描述:
VM12 pro中安装的ubuntu,在使用wget和ping baidu、QQ等域名时出现以下问题:
# wget www.baidu.com
--2018-04-24 18:14:42-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... failed: Temporary failure in name resolution.
wget: unable to resolve host address ‘www.baidu.com’
# ping www.baidu.com
ping: unknown host www.baidu.com
# nslookup www.baidu.com
;; connection timed out; no servers could be reached
解决方法:
在网络链接正常的情况下,查看DNS服务器是否设置,如果没有,建议搭建以下DNS服务:(据说谷歌的8.8.8.8和8.8.4.4在国内不稳定,修改DNS服务器设置只需要vim以下/ect/resolv.conf文件即可,修改即生效,不用重启)
# cat /etc/resolv.conf
nameserver 114.114.114.114
nameserver 1.2.4.8
ubuntu用户需要在/etc/network/interfaces中修改dns-nameserver项。
修改完成需要重新启动网络服务:
# service network restart
ubuntu用户使用以下命令重启服务:
# /etc/init.d/networking restart
再次使用wget命令:
# wget www.baidu.com
--2018-04-24 19:11:59-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 220.181.111.188, 220.181.112.244
Connecting to www.baidu.com (www.baidu.com)|220.181.111.188|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html’
index.html 100%[=============================================================================================>] 2.33K --.-KB/s in 0.001s
2018-04-24 19:12:09 (3.08 MB/s) - ‘index.html’ saved [2381/2381]
有个小技巧:wget默认情况下会有限解析Ipv6,但是在那个domain没有Ipv6情况下,服务器会等待解析失败超时后再按照正常流程去解析Ipv4,所以wget一个网站有时会出现很慢的情况,这时候就需要采用如下方式:
# wget -4 www.baidu.com
--2018-04-24 19:12:19-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 220.181.111.188, 220.181.112.244
Connecting to www.baidu.com (www.baidu.com)|220.181.111.188|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html.1’
index.html.1 100%[=============================================================================================>] 2.33K --.-KB/s in 0s
2018-04-24 19:12:24 (16.4 MB/s) - ‘index.html.1’ saved [2381/2381]
速度增加肉眼可见,亲测。