apt-get update 101錯誤解決辦法

在一次裝好Ubuntu系統, 執行

sudo apt-get update

時,報了錯

"

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/raring-security/Release.gpg Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::13). - connect (101: Network is unreachable) [IP: 2001:67c:1562::13 80]

"

一開始以爲是Ubuntu默認的源訪問不到,於是通過編輯文件 /etc/apt/sources.list,修改源的方式,嘗試去解決問題

先備份sources.list文件,然後把原來的sources.list的文件改爲一下內容

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

發現依然有這個錯誤。

看了報錯信息,以爲是DNS解析有誤,導致訪問不到域名所對應的服務器內容,於是嘗試添加DNS服務器來解決問題,具體爲修改/etc/resolv.conf文件

按照以下格式將代碼添加到文件最後,用以添加DNS服務器,我添加的是Google的DNS服務器

nameserver 8.8.8.8

發現還是有這個問題。

最後用搜索引擎搜了一下apt-get update錯誤信息101,發現有人提出,報錯信息裏給出的IP地址是IPV6,所以可能是系統的IPV6代理沒有設置好。(因爲公司內網默認隔離,如果不設置公司的代理服務器,就無法訪問外網)

我觀察了一下,在UI的系統設置界面裏,我設置好了,但是還是報錯。

於是嘗試着在系統文件裏設置,具體方法是編輯文件~/.bashrc

在文件的最後加入以下內容

#Set Proxy Server
export http_proxy="http://<proxy_name>:<port_number>" 
export https_proxy="https://<proxy_name>:<port_number>"

然後執行下面的命令讓修改生效

source ~/.bashrc

 

由於顯式的export了ipv4(http)和ipv6(https)的代理,ipv6已可以訪問,最後sudo apt-get update執行成功了。

 

值得注意的是,我們在執行"$sudo apt-get install"和''#apt-get install"時,壞境變量是不一樣的,前者是當前普通用戶的環境變量,後者是系統環境變量,因此如果當我們還是發生101錯誤時,一定要檢查當前我們用的是什麼用戶執行命令,以及該用戶對應的環境變量是否顯示聲明瞭代理服務器。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章