虛擬機器不能解析域名原因詳解
阿新 • • 發佈:2019-01-28
問題描述:
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]
速度增加肉眼可見,親測。