通过代理 apt-get 更新 ubuntu 18.04 时连接被拒绝

通过代理 apt-get 更新 ubuntu 18.04 时连接被拒绝

我最近安装了 ubuntu 18.04,想安装 sublime。但是我sudo apt-get update之前尝试过运行,得到了以下输出

Err:1 http://archive.canonical.com/ubuntu bionic InRelease
  Could not connect to archive.canonical.com:80 (91.189.91.15). - connect (111: Connection refused) Cannot initiate the connection to archive.canonical.com:80 (2001:67c:1360:8c01::16). - connect (101: Network is unreachable) Could not connect to archive.canonical.com:80 (91.189.92.150). - connect (111: Connection refused) Cannot initiate the connection to archive.canonical.com:80 (2001:67c:1562::1c). - connect (101: Network is unreachable) Could not connect to archive.canonical.com:80 (91.189.92.191). - connect (111: Connection refused) Cannot initiate the connection to archive.canonical.com:80 (2001:67c:1360:8c01::1b). - connect (101: Network is unreachable)
Err:2 https://download.sublimetext.com apt/stable/ InRelease                   
  Could not connect to download.sublimetext.com:443 (104.236.0.104). - connect (111: Connection refused)
Err:3 http://security.ubuntu.com/ubuntu bionic-security InRelease              
  Could not connect to security.ubuntu.com:80 (91.189.88.149). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::16). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.91.23). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.161). - connect (111: Connection refused) Could not connect to security.ubuntu.com:80 (91.189.88.162). - connect (111: Connection refused) Could not connect to security.ubuntu.com:80 (91.189.91.26). - connect (111: Connection refused)
Err:4 http://in.archive.ubuntu.com/ubuntu bionic InRelease                     
  Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Could not connect to in.archive.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused) Could not connect to in.archive.ubuntu.com:80 (91.189.88.149). - connect (111: Connection refused) Could not connect to in.archive.ubuntu.com:80 (91.189.88.162). - connect (111: Connection refused) Could not connect to in.archive.ubuntu.com:80 (91.189.88.161). - connect (111: Connection refused)
Err:5 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease
  Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable)
Err:6 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease
  Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable)
Reading package lists... Done
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Could not connect to in.archive.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused) Could not connect to in.archive.ubuntu.com:80 (91.189.88.149). - connect (111: Connection refused) Could not connect to in.archive.ubuntu.com:80 (91.189.88.162). - connect (111: Connection refused) Could not connect to in.archive.ubuntu.com:80 (91.189.88.161). - connect (111: Connection refused)
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable)
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to in.archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable)
W: Failed to fetch http://archive.canonical.com/ubuntu/dists/bionic/InRelease  Could not connect to archive.canonical.com:80 (91.189.91.15). - connect (111: Connection refused) Cannot initiate the connection to archive.canonical.com:80 (2001:67c:1360:8c01::16). - connect (101: Network is unreachable) Could not connect to archive.canonical.com:80 (91.189.92.150). - connect (111: Connection refused) Cannot initiate the connection to archive.canonical.com:80 (2001:67c:1562::1c). - connect (101: Network is unreachable) Could not connect to archive.canonical.com:80 (91.189.92.191). - connect (111: Connection refused) Cannot initiate the connection to archive.canonical.com:80 (2001:67c:1360:8c01::1b). - connect (101: Network is unreachable)
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Could not connect to security.ubuntu.com:80 (91.189.88.149). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::16). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.91.23). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.161). - connect (111: Connection refused) Could not connect to security.ubuntu.com:80 (91.189.88.162). - connect (111: Connection refused) Could not connect to security.ubuntu.com:80 (91.189.91.26). - connect (111: Connection refused)
W: Failed to fetch https://download.sublimetext.com/apt/stable/InRelease  Could not connect to download.sublimetext.com:443 (104.236.0.104). - connect (111: Connection refused)
W: Some index files failed to download. They have been ignored, or old ones used instead.

我已通过代理连接,互联网在浏览器上工作正常。我还尝试了以下操作:

m@m-Lenovo-ideapad-500-15ISK:~$ ping archive.ubuntu.com
PING archive.ubuntu.com (91.189.88.161) 56(84) bytes of data.
64 bytes from keeton.canonical.com (91.189.88.161): icmp_seq=1 ttl=45 time=127 ms
64 bytes from keeton.canonical.com (91.189.88.161): icmp_seq=2 ttl=45 time=127 ms
64 bytes from keeton.canonical.com (91.189.88.161): icmp_seq=3 ttl=45 time=127 ms
64 bytes from keeton.canonical.com (91.189.88.161): icmp_seq=4 ttl=45 time=127 ms
64 bytes from keeton.canonical.com (91.189.88.161): icmp_seq=5 ttl=45 time=127 ms
^C
--- archive.ubuntu.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 127.232/127.426/127.761/0.296 ms

env | grep proxy返回以下内容:

m@m-Lenovo-ideapad-500-15ISK:~$ env | grep proxy
HTTP_PROXY=http://proxy.iiit.ac.in:8080/
FTP_PROXY=http://proxy.iiit.ac.in:8080/
https_proxy=http://proxy.iiit.ac.in:8080/
http_proxy=http://proxy.iiit.ac.in:8080/
ALL_PROXY=socks://proxy.iiit.ac.in:8080/
no_proxy=localhost,127.0.0.0/8,::1
HTTPS_PROXY=http://proxy.iiit.ac.in:8080/
all_proxy=socks://proxy.iiit.ac.in:8080/
ftp_proxy=http://proxy.iiit.ac.in:8080/

请注意,apt-get update在我的移动热点上没有代理也可以正常工作,但在我的局域网/wifi上通过代理则不行。我该如何解决这个问题?

编辑

尝试安装 sublime 时出现以下错误:

m@m-Lenovo-ideapad-500-15ISK:~$ sudo apt-get install sublime-text
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  sublime-text
0 upgraded, 1 newly installed, 0 to remove and 90 not upgraded.
Need to get 8,494 kB of archives.
After this operation, 25.1 MB of additional disk space will be used.
Err:1 https://download.sublimetext.com apt/stable/ sublime-text 3176
  Could not connect to download.sublimetext.com:443 (104.236.0.104). - connect (111: Connection refused)
E: Failed to fetch https://download.sublimetext.com/files/sublime-text_build-3176_amd64.deb  Could not connect to download.sublimetext.com:443 (104.236.0.104). - connect (111: Connection refused)
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

但是,我可以通过同一连接在给定 IP 上 ping 数据包,且无丢包

ping 104.236.0.104
PING 104.236.0.104 (104.236.0.104) 56(84) bytes of data.
64 bytes from 104.236.0.104: icmp_seq=1 ttl=48 time=206 ms
64 bytes from 104.236.0.104: icmp_seq=2 ttl=48 time=207 ms
64 bytes from 104.236.0.104: icmp_seq=3 ttl=48 time=206 ms
64 bytes from 104.236.0.104: icmp_seq=4 ttl=48 time=206 ms
64 bytes from 104.236.0.104: icmp_seq=5 ttl=48 time=207 ms
^C
--- 104.236.0.104 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 206.334/206.879/207.767/0.593 ms

答案1

问题是代理设置未传递到“sudo”级别。由于您为当前用户设置了http_proxy和设置,因此您可以以普通用户身份 ping 和 wget 内容。当您使用 时,这些环境变量不会传递给提升的用户。https_proxysudo

解决方案是使用-Esudo 将这些环境变量传递给提升权限的用户。

例如,执行以下操作:

sudo -E apt-get update

它应该可以工作。

答案2

以下方法很有效果:

将其附加到 ~/.bashrc 文件中

alias iiitproxy='export http_proxy="http://proxy.iiit.ac.in:8080"; export https_proxy="http://proxy.iiit.ac.in:8080";export ftp_proxy="http://proxy.iiit.ac.in:8080"; echo "Acquire::http::proxy \"http://proxy.iiit.ac.in:8080/\";" | sudo tee /etc/apt/apt.conf'

然后在终端中运行以下命令:

 source ~/.bashrc 

刷新终端,

iiitproxy

我不太清楚这里有什么不同,但它确实有效

答案3

对于 18.04,在 /etc/apt/apt.conf.d/proxy.conf 中创建一个新文件

在此文件中写入您的代理设置,例如:

获取::http::代理”http://用户:[电子邮件保护]:港口/";获取::https::代理"http://用户:[电子邮件保护]:港口/“;

并且它有效。

答案4

对于 18.04,在 /etc/apt/apt.conf.d/proxy.conf 中创建一个新文件

在此文件中写入您的代理设置,例如:

获取::http::代理“http://用户:[电子邮件保护]:港口/”;

获取::https::代理“http://用户:[电子邮件保护]:港口/”;

这对我来说是工作

相关内容