每当我尝试更新/升级/安装软件包时,它都会告诉我以下内容。
Err http://security.ubuntu.com trusty-security InRelease
Err http://archive.canonical.com trusty InRelease
Err http://archive.canonical.com trusty Release.gpg
Could not resolve 'archive.canonical.com'
Err http://security.ubuntu.com trusty-security Release.gpg
Could not resolve 'security.ubuntu.com'
Err http://nl.archive.ubuntu.com trusty InRelease
Err http://nl.archive.ubuntu.com trusty-updates InRelease
Err http://nl.archive.ubuntu.com trusty-backports InRelease
Err http://nl.archive.ubuntu.com trusty Release.gpg
Could not resolve 'nl.archive.ubuntu.com'
Err http://nl.archive.ubuntu.com trusty-updates Release.gpg
Could not resolve 'nl.archive.ubuntu.com'
Err http://nl.archive.ubuntu.com trusty-backports Release.gpg
Could not resolve 'nl.archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://nl.archive.ubuntu.com/ubuntu/dists/trusty/InRelease
W: Failed to fetch http://nl.archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease
W: Failed to fetch http://nl.archive.ubuntu.com/ubuntu/dists/trusty-backports/InRelease
W: Failed to fetch http://archive.canonical.com/ubuntu/dists/trusty/InRelease
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/trusty-security/InRelease
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg Could not resolve 'security.ubuntu.com'
W: Failed to fetch http://archive.canonical.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'archive.canonical.com'
W: Failed to fetch http://nl.archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'nl.archive.ubuntu.com'
W: Failed to fetch http://nl.archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg Could not resolve 'nl.archive.ubuntu.com'
W: Failed to fetch http://nl.archive.ubuntu.com/ubuntu/dists/trusty-backports/Release.gpg Could not resolve 'nl.archive.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
每当我检查是否可以解析这些主机时,机器都可以正常工作。例如:
root@ubuntu-server:/etc# host nl.archive.ubuntu.com
nl.archive.ubuntu.com is an alias for ubuntuarchive.bit.nl.
ubuntuarchive.bit.nl is an alias for ftp.bit.nl.
ftp.bit.nl has address 213.136.12.213
ftp.bit.nl has IPv6 address 2001:7b8:3:37::21:3
该机器具有有效的互联网连接,并且我的 resolv.conf 没有任何问题
root@ubuntu-server:/etc# cat resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.1.1
有什么想法哪里出了问题以及我该怎么做才能解决这个问题?
编辑:终端环境变量:
root@ubuntu-server:/etc# printenv
XDG_SESSION_ID=6
TERM=xterm
SHELL=/bin/bash
SSH_CLIENT=xxx.xxx.xxx.xxx 2764 22
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00 ;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga =00;36:*.spx=00;36:*.xspf=00;36:
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/us r/local/games
PWD=/etc
LANG=en_US.UTF-8
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=xxx.xxx.xxx.xxx 2764 192.168.1.15 22
LESSOPEN=| /usr/bin/lesspipe %s
XDG_RUNTIME_DIR=/run/user/0
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/printenv
OLDPWD=/etc/network
答案1
列出的环境变量不太可能影响apt-get
。但是, 的输出host
是不是主机名解析是否有效的可靠指标。
考虑:
$ grep hosts /etc/nsswitch.conf
hosts: files
$ host google.com
google.com has address 172.217.26.14
google.com has IPv6 address 2404:6800:4004:809::200e
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
$ sudo apt update
Err:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Could not resolve 'security.ubuntu.com'
Err:2 http://jp.archive.ubuntu.com/ubuntu xenial InRelease
Could not resolve 'jp.archive.ubuntu.com'
Err:3 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease
Could not resolve 'jp.archive.ubuntu.com'
Err:4 http://jp.archive.ubuntu.com/ubuntu xenial-backports InRelease
Could not resolve 'jp.archive.ubuntu.com'
Err:5 http://archive.canonical.com/ubuntu xenial InRelease
Could not resolve 'archive.canonical.com'
Reading package lists... Done
Building dependency tree
Reading state information... Done
12 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Failed to fetch http://jp.archive.ubuntu.com/ubuntu/dists/xenial/InRelease Could not resolve 'jp.archive.ubuntu.com'
W: Failed to fetch http://jp.archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Could not resolve 'jp.archive.ubuntu.com'
W: Failed to fetch http://jp.archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease Could not resolve 'jp.archive.ubuntu.com'
W: Failed to fetch http://archive.canonical.com/ubuntu/dists/xenial/InRelease Could not resolve 'archive.canonical.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Could not resolve 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
apt-get
和大多数应用程序一样,使用 glibc 的gethostbyname(3)
用于主机名解析,由/etc/nsswitch.conf
决定使用哪种方法。如果nsswitch.conf
配置不正确,host
(和nslookup
、dig
等)将正常工作,但大多数应用程序将无法进行主机名解析。
这是一个可能的原因。