Jun*_*ndl 45 ubuntu debian apt windows-subsystem-for-linux wsl-2
从 WSL 升级到 WSL2 后
sudo apt-get update
Run Code Online (Sandbox Code Playgroud)
不再起作用。后:
wsl --set-version Ubuntu-18.04 2
输出是:
> sudo apt-get update
Err:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Run Code Online (Sandbox Code Playgroud)
回到 WSL1 后,问题再次消失。在 Debian 上和在 CentOS 上类似......所以 WSL2 一定有一个错误。
Windows10 构建版本是 19041,今天安装。
WSL2 的任何解决方法?问候
Jun*_*ndl 99
生成的文件 /etc/resolv.conf 是:
名称服务器 172.24.0.1
..不得不把它改成
名称服务器 8.8.8.8
这解决了问题
Jes*_*sta 22
就我而言,我在 Windows 中使用了 VPN,当与 VPN 断开连接时,问题解决了。
然而,这正在成为一个更广泛的问题,它再次发生在我身上,我通过删除 Hyper-V 虚拟交换机扩展适配器解决了它。
目前针对此问题最广泛使用的两种解决方案是:
/etc/wsl.conf
.[network]
generateResolvConf = false
Run Code Online (Sandbox Code Playgroud)
cmd
窗口中,运行wsl --shutdown
/etc/resolv.conf
. 如果存在,用这个新文件替换现有文件。nameserver 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
git
现在工作正常。感谢在GitHub 上分享的Jaysonsantos
我遇到了同样的问题。
做cat /etc/resolv.conf
,看看输出是否有这样的东西:
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.X.X.X
Run Code Online (Sandbox Code Playgroud)
您需要将名称服务器更改为8.8.8.8
,因此运行sudo nano /etc/resolv.conf
、编辑并保存文件。
但是,这或多或少是一个临时解决方案,因为每次 WSL 启动时您都需要这样做。您可能想要运行一个脚本来检查名称服务器并在每次重新启动 wsl 时将其更新为 8.8.8.8。此更改确实适用于我的 WSL2-Debian。但我不需要重新启动 WSL。
最有可能的是,发行版有自己的虚拟适配器,首先你可以尝试一些步骤:
需要检查数据包是否真的通过了 Windows 防火墙
然后检查
%systemroot%\system32\LogFiles\Firewall\pfirewall.log
如果数据包没有通过防火墙,很可能分发获得了它自己的虚拟适配器,请检查从 Debian 内部获得的 IP 分发:
ifconfig
或者如果你没有ifconfig
:
perl -MSocket -le 'socket(S, PF_INET, SOCK_DGRAM, getprotobyname("udp"));
connect(S, sockaddr_in(1, inet_aton("8.8.8.8")));
print inet_ntoa((sockaddr_in(getsockname(S)))[1]);'
Run Code Online (Sandbox Code Playgroud)
或ipconfig
在 Windows WSL2 主机上,查看哪些 IP 占用了 WSL 适配器下的机器
解决方法是使用执行以下操作的脚本:
一种。获取 WSL 2 机器的 IP 地址
湾 删除之前的端口转发规则
C。添加端口转发规则
d. 删除之前添加的防火墙规则
e. 添加新的防火墙规则
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
#[Ports]
#All the ports you want to forward separated by coma
$ports=@(80,443,10000,3000,5000);
#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";
#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";
for( $i = 0; $i -lt $ports.length; $i++ ){
$port = $ports[$i];
iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectpor t=$port connectaddress=$remoteport";
}
Run Code Online (Sandbox Code Playgroud)
另一种解决方案是转到 Hyper-V 管理器并更改绑定到物理 NIC 的虚拟交换机
我解决了问题改为/etc/resolv.conf
:
nameserver 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
进而
$ sudo chattr -f +i /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)
实际上用该属性“锁定”文件+i==immutable
,因此操作系统无法重新生成。这样用户修改的内容/etc/resolv.conf
就会被持久化。
我发现创建/etc/wsl.conf
不起作用,但还是留下了它:
[network]
generateResolvConf = false
Run Code Online (Sandbox Code Playgroud)
在 cmd 上运行这些命令:
$ wsl --shutdown
$ netsh winsock reset
$ netsh int ip reset all
$ netsh winhttp reset proxy
$ ipconfig /flushdns
$ netsh winsock reset
$ shutdown /r
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
37904 次 |
最近记录: |