dns问题 hosts修改 网络连接

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
MGZX
帖子: 4
注册时间: 2016-08-12 15:58
系统: Ubuntu 16.04 LTS

dns问题 hosts修改 网络连接

#1

帖子 MGZX » 2016-08-19 7:31

环境:
>系统:ubuntu 16.04 LTS 64位
>硬件:ThinkPad T440p
>网络:家用普通路由器,联通网络

问题:

1. github连接不上,报错 can't resolve host:github.com
2. 一个sudo 命令要很久才会出现提示输入密码,而且报错 sudo: unable to resolve host pc-t440p: Connection timed out
3. sudo apt-get update 无法成功完成,软件源为aliyun


我觉得应该是dns,hosts之类的问题,但不知如何解决,求教,感谢...
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: dns问题 hosts修改 网络连接

#2

帖子 poloshiao » 2016-08-19 8:09

2. 一个sudo 命令要很久才会出现提示输入密码,而且报错 sudo: unable to resolve host pc-t440p: Connection timed out
1. 先處理這個問題
參閱
http://askubuntu.com/questions/59458/er ... -host-none
Error message when I run sudo: unable to resolve host

2. 如果這個報錯還未消失
把下面指令 複製 貼進終端機 執行
sudo cat /etc/hosts
sudo cat /etc/hostname
把結果全部直接 選取/複製/貼上來
MGZX
帖子: 4
注册时间: 2016-08-12 15:58
系统: Ubuntu 16.04 LTS

Re: dns问题 hosts修改 网络连接

#3

帖子 MGZX » 2016-08-19 8:20

poloshiao 写了:
2. 一个sudo 命令要很久才会出现提示输入密码,而且报错 sudo: unable to resolve host pc-t440p: Connection timed out
1. 先處理這個問題
參閱
http://askubuntu.com/questions/59458/er ... -host-none
Error message when I run sudo: unable to resolve host

2. 如果這個報錯還未消失
把下面指令 複製 貼進終端機 執行
sudo cat /etc/hosts
sudo cat /etc/hostname
把結果全部直接 選取/複製/貼上來
执行下列命令的结果:

代码: 全选

zhaoxiaodong@pc-t440p:~$ sudo cat /etc/hosts
sudo: unable to resolve host pc-t440p: Connection timed out
[sudo] password for zhaoxiaodong: 
127.0.0.1	localhost
127.0.1.1	zhaoxiaodong-ThinkPad-T440p
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
zhaoxiaodong@pc-t440p:~$ sudo cat /etc/hostname
pc-t440p
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: dns问题 hosts修改 网络连接

#4

帖子 poloshiao » 2016-08-19 9:21

sudo cat /etc/hostname
pc-t440p
1. 你的電腦名稱 hostname 是 pc-t440p
sudo cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 zhaoxiaodong-ThinkPad-T440p
... 以下省略
2. 但是 在 dns 檔案 /etc/hosts
找不到 pc-t440p
Error message when I run sudo: unable to resolve host
2-1. 所以回答你 無法解析 pc-t440p 為 IPv4

3. 把這一行
127.0.1.1 zhaoxiaodong-ThinkPad-T440p
改為
127.0.1.1 pc-t440p zhaoxiaodong-ThinkPad-T440p
注意 兩者中間是空一格
再試試
可以了 再處理另兩個問題
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: dns问题 hosts修改 网络连接

#5

帖子 poloshiao » 2016-08-19 10:22

github连接不上,报错 can't resolve host:github.com
1. ping -c 3 github.com
PING github.com (192.30.253.113) 56(84) bytes of data.
64 bytes from 192.30.253.113: icmp_seq=1 ttl=47 time=227 ms
64 bytes from 192.30.253.113: icmp_seq=2 ttl=47 time=228 ms
64 bytes from 192.30.253.113: icmp_seq=3 ttl=47 time=228 ms
--- github.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 6268ms
rtt min/avg/max/mdev = 227.426/228.196/228.640/0.776 ms

2. ping -c 3 192.30.253.113
PING 192.30.253.113 (192.30.253.113) 56(84) bytes of data.
64 bytes from 192.30.253.113: icmp_seq=1 ttl=47 time=228 ms
64 bytes from 192.30.253.113: icmp_seq=2 ttl=47 time=227 ms
64 bytes from 192.30.253.113: icmp_seq=3 ttl=47 time=227 ms
--- 192.30.253.113 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 227.663/227.908/228.209/0.595 ms

3. 如果只是這個 github.com
可能是網路不穩定
稍後一下 再試
或者 清晨再試
sudo apt-get update 无法成功完成,软件源为aliyun
4. sudo apt-get update
請把全部回應內容直接複製貼上來
MGZX
帖子: 4
注册时间: 2016-08-12 15:58
系统: Ubuntu 16.04 LTS

Re: dns问题 hosts修改 网络连接

#6

帖子 MGZX » 2016-08-20 9:04

poloshiao 写了:
4. sudo apt-get update
請把全部回應內容直接複製貼上來

代码: 全选

zhaoxiaodong@pc-t440p:~$ sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu xenial InRelease                        
Hit:2 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease                
Hit:3 http://mirrors.aliyun.com/ubuntu xenial-backports InRelease              
Hit:4 http://mirrors.aliyun.com/ubuntu xenial-security InRelease               
Hit:5 http://ppa.launchpad.net/wiznote-team/ppa/ubuntu xenial InRelease        
Err:6 http://archive.canonical.com/ubuntu xenial InRelease                     
  Temporary failure resolving 'archive.canonical.com'
Reading package lists... Done           
W: Failed to fetch http://archive.canonical.com/ubuntu/dists/xenial/InRelease  Temporary failure resolving 'archive.canonical.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
以上是update运行的结果,请解释下出错原因,谢谢
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: dns问题 hosts修改 网络连接

#7

帖子 poloshiao » 2016-08-20 10:28

Err:6 http://archive.canonical.com/ubuntu xenial InRelease Temporary failure resolving 'archive.canonical.com'
Reading package lists... Done
W: Failed to fetch http://archive.canonical.com/ubuntu/dis ... /InRelease Temporary failure resolving 'archive.canonical.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
1. 這個網址
http://archive.canonical.com/ubuntu/
沒有 Mirror 可以代替
只有唯一的網址
偏偏 網路頻寬不足 或 網路不穩
常常出錯

2. 對策
2-1. 選網路狀況比較穩定時 例如 清晨 再試試
2-2. 或者 暫時把 /etc/apt/sources.list 軟體來源表 裡面 有
http://archive.canonical.com/ubuntu/
的那一行 最前面加 #
意思是 暫時把它排除在軟體來源名單之外
等到網路狀況比較穩定時 再把 # 移除
回复