48小时系统班试听入口

WSL2 ubuntu20.04 “sudo apt update“失败-connection failed,创建proxy解决

发布作者:新盟教育 发布日期:2023-02-28 浏览人数:1029人

Linux运维实战技巧

资源放送 

Linux运维技术教程讲解

↓ 扫一扫 视频在线观看↓

Linux运维资料.png

概述


记录WSL2 with Clash “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代理:

mail-archive.com/squid-

参考上述方法,首先,ipconfig /all 查询宿主机IP(非vEthernet (WSL) IP),替代下述prox.srv.world,所用clash端口为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


其他方法

对我无效,可能存在clash代理的原因,而不是DNS的问题。

#创建wsl.conf文件
sudo vim /etc/wsl.conf
#粘贴如下代码,保存退出
[network]
generateResolvConf = false


#修改resolve.conf文件
sudo vim /etc/resolve.conf
#更改nameserver,保存退出
nameserver = 8.8.8.8


1671585dc74035d34ac554d5f2ae42fc.jpg

推荐阅读

>>>新手必备-Linux入门之云计算是什么

>>>红帽认证入门-Linux系统介绍及企业版本选型

>>>新手必备-Linux系统安装配置+Xshell远程连接

>>>Linux常用命令行合集之绝对路径和相对路径

>>>软连接与硬连接