WSL2 ubuntu20.04 “sudo apt update“失败-connection failed,创建proxy解决
程序员文章站
2022-07-14 15:58:12
...
概述
记录WSL2 with * “sudo apt update”失败的网络问题,及解决方法。
-
问题描述
WSL2(Ubuntu20.04),安装完成后,运行“sudo apt update”,一直连接网络失败,报错如下。
Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
Connection failed [IP: 91.189.88.152 80]
Err:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Connection failed [IP: 91.189.91.39 80]
Err:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Connection failed [IP: 91.189.88.152 80]
Err:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Connection failed [IP: 91.189.88.152 80]
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease Connection failed [IP: 91.189.88.152 80]
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease Connection failed [IP: 91.189.88.152 80]
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease Connection failed [IP: 91.189.88.152 80]
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease Connection failed [IP: 91.189.91.39 80]
W: Some index files failed to download. They have been ignored, or old ones used instead.
- 更换清华源
#备份原来的文件,以防改错。
sudo mv /etc/apt/sources.list /etc/apt/sources.list.old
#修改源
sudo vim /etc/apt/souces.list
#粘贴如下
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
#保存退出
还是会报错"Could not wait for server fd - select(11: Resource temporarily unavailable)",如下。
Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease
Ign:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease
Ign:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease
Ign:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security InRelease
Err:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal Release
Could not wait for server fd - select (11: Resource temporarily unavailable) [IP: 101.6.15.130 443]
Err:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates Release
Could not wait for server fd - select (11: Resource temporarily unavailable) [IP: 101.6.15.130 443]
Err:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports Release
Could not wait for server fd - select (11: Resource temporarily unavailable) [IP: 101.6.15.130 443]
Err:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security Release
Could not wait for server fd - select (11: Resource temporarily unavailable) [IP: 101.6.15.130 443]
Reading package lists... Done
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
- 关闭防火墙,设置宿主机IP代理
https://www.mail-archive.com/[email protected]/msg22786.html
参考上述方法,首先,ipconfig /all 查询宿主机IP(非vEthernet (WSL) IP),替代下述prox.srv.world,所用*端口为7890。
Acquire::http::proxy "http://prox.srv.world:7890/";;
Acquire::https::proxy "http://prox.srv.world:7890/";;
#创建apt.conf
sudo vim /etc/apt/apt.conf
#粘贴上述代码,保存退出
此方法能够解决我的问题,能够正确执行下述语句。注:若宿主机IP改变,需要更新apt.conf。
sudo apt update
sudo apt upgrade
-
其他方法
对我无效,可能存在*代理的原因,而不是DNS的问题。
#创建wsl.conf文件
sudo vim /etc/wsl.conf
#粘贴如下代码,保存退出
[network]
generateResolvConf = false
#修改resolve.conf文件
sudo vim /etc/resolve.conf
#更改nameserver,保存退出
nameserver = 8.8.8.8
其他参考如下。
https://blog.csdn.net/swordsm/article/details/107948497
https://lengthmin.me/posts/wsl2-network-tricks/
https://github.com/microsoft/WSL/issues/5256
https://*.com/questions/60269422/windows10-wsl2-ubuntu-debian-no-network