Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows10 WSL2 Ubuntu/Debian#apt获取更新失败#无网络_Ubuntu_Debian_Windows Subsystem For Linux_Apt_Wsl 2 - Fatal编程技术网

Windows10 WSL2 Ubuntu/Debian#apt获取更新失败#无网络

Windows10 WSL2 Ubuntu/Debian#apt获取更新失败#无网络,ubuntu,debian,windows-subsystem-for-linux,apt,wsl-2,Ubuntu,Debian,Windows Subsystem For Linux,Apt,Wsl 2,从WSL升级到WSL2后 sudo apt-get update 之后就不再工作了 wsl——设置版本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/ubun

从WSL升级到WSL2后

sudo apt-get update
之后就不再工作了

wsl——设置版本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.
返回WSL1后,问题再次消失。Debian上相同,CentOS上类似。。所以WSL2肯定有一个bug

Windows10构建版本为19041,已于今天安装

WSL2有什么解决办法吗?
生成的文件/etc/resolv.conf是:

名称服务器172.24.0.1

…不得不把它改成

名称服务器8.8.8.8


这解决了问题

最有可能的是,发行版有自己的虚拟适配器,首先您可以尝试以下步骤:

  • 需要检查数据包是否真的通过Windows防火墙 然后检查
    %systemroot%\system32\LogFiles\Firewall\pfirewall.log

  • 如果数据包未通过防火墙,则发行版很可能获得自己的虚拟适配器,请使用以下工具检查IP从Debian内部获得的发行版:

    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]);'
    
    或者在Windows WSL2主机上执行
    ipconfig
    ,然后查看WSL适配器下的IP占用机器的内容

  • 如果您需要通过Windows IP访问internet,请检查此问题:
  • 解决方法是使用一个脚本,该脚本可以:

    a。获取WSL2计算机的Ip地址

    b。删除以前的端口转发规则

    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";
      }
    
    另一种解决方案是转到Hyper-V管理器并更改绑定到物理NIC的虚拟交换机

    原始答案: 在我的例子中,我在Windows中使用VPN,当断开与VPN的连接时,问题得到了解决

    编辑: 然而,这正成为一个更广泛的问题,我再次遇到这种情况,我通过删除Hyper-V虚拟交换机扩展适配器解决了这个问题

    目前针对该问题最广泛使用的两种解决方案是:

    1防止/etc/resolfv.conf“损坏”
  • 创建一个文件:
    /etc/wsl.conf
  • 将以下行放入文件中
  • cmd
    窗口中,运行
    wsl--shutdown
  • 重新启动WSL2
  • 创建一个文件:
    /etc/resolv.conf
    。如果存在,请用此新文件替换现有文件
  • 将以下行放入文件中
  • 重复步骤3和4。您将看到
    git
    现在工作正常
  • 是谁在网上分享的

    2删除损坏的网络接口驱动程序(可能是永久的)
  • 首先转到设备管理器

  • 显示隐藏设备

  • 删除所有Hyper-V虚拟交换机扩展适配器

  • 是谁在网上分享的


    我也遇到了同样的问题

    执行
    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
    
    您需要将名称服务器更改为
    8.8.8.8
    ,因此运行
    sudo nano/etc/resolv.conf
    ,编辑并保存文件

    然而,这或多或少是一个临时解决方案,因为每次WSL启动时都需要这样做。 您可能希望运行一个脚本来检查名称服务器,并在每次重新启动wsl时将其更新为8.8.8.8。
    这一更改对我的WSL2 Debian有效。但是我不需要重新启动WSL。

    对于我来说,在安装apache并允许使用此命令创建apache概要文件之后,我有了一个新的Ubuntu 20.04 WSL实例

    sudo ufw allow in "Apache"
    
    那么

    我注意到这个问题已经触发,并且在使用

    sudo ufw disable && sudo service ufw stop
    

    一切都很好。

    对我来说很好,我正在使用CiscoAnyConnect进行VPN

    Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 4000
    
    获取NetIPInterface-InterfaceAlias“vEthernet(WSL)”;设置NetIPInterface-InterfaceMetric 1


    学分:

    在尝试任何其他答案之前,请尝试关闭系统并重新启动。 这肯定会解决连接问题

    我面临着同样的问题,尝试了不同的解决方案,但我睡了一觉,什么都没用
    通过关闭我的笔记本电脑,第二天我重新启动了连接到互联网的WSL Ubuntu,没有任何问题。

    检查您使用的防病毒软件。我启用了McAfee和端点安全性。如果断开端点连接,安全防火墙连接将立即工作(无需重新启动)


    删除
    /etc/resolv.conf
    文件。关闭WSL2虚拟机。重新启动WSL。检查是否可以ping远程IP和网站。否则,请检查任何network firewall.thx,/etc/resolv.conf是正确的文件,但如果将其删除,它将在下一个wsl startthx上重新生成,自定义防火墙设置似乎是一个可行的解决方案,但不幸的是,访问受到管理员的限制。WSL2在不启用hyper-v的情况下可用,因此替代解决方案不适用于我的情况。无论如何,ms应找到现成的解决方案:)您好,关于脚本,我是否需要将其存储到.sh扩展名。例如,wsl.sh?第二个投票最多的答案对我来说不起作用。但是,你提到的问题与我的问题有关。似乎很多开发者都遇到了同样的问题,这个问题仍然悬而未决。我打开了一个关于WSL的问题。你可能知道这个问题,如果你有时间可以帮我。我回到WSL 1。但我在这里发现了一个非常有用的问题,他们正在努力解决这个问题,谢谢。这是如此简单,但它像一个魅力)如果你使用VPN,你可能想避免使用谷歌的DNS服务器的答案提到。例如,Mullvad VPN改用10.8.0.1。这应该是公认的答案。很有魅力,谢谢!唯一的问题是,您必须在每次wsl2启动时重复它;)如果要永久使用外部DNS服务器,请将
    [network]generateResolvConf=false
    添加到/etc/wsl.conf:)创建
    resolv.conf
    工作
    sudo service ufw start && sudo ufw enable
    
    sudo ufw disable && sudo service ufw stop
    
    Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 4000