Windows10 WSL2 Ubuntu/Debian#apt-get更新失败#没有网络 [英] Windows10 WSL2 Ubuntu / Debian # apt-get update failed # no network

查看:317
本文介绍了Windows10 WSL2 Ubuntu/Debian#apt-get更新失败#没有网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从WSL升级到WSL2后

  sudo apt-get更新 

之后不再起作用

wsl --set-version Ubuntu-18.04 2

输出:

 >sudo apt-get更新错误:1 http://security.ubuntu.com/ubuntu bionic-security InRelease解决"security.ubuntu.com"的临时故障错误:2 http://archive.ubuntu.com/ubuntu仿生InRelease解决"archive.ubuntu.com"的临时故障错误:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease解决"archive.ubuntu.com"的临时故障错误:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease解决"archive.ubuntu.com"的临时故障正在阅读包裹清单...完成W:无法获取http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease解决"archive.ubuntu.com"的临时故障W:无法获取http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease解决"archive.ubuntu.com"的临时故障W:无法获取http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease解决"archive.ubuntu.com"的临时故障W:无法获取http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease解决"security.ubuntu.com"的临时故障W:某些索引文件下载失败.它们已被忽略,或改用旧的. 

回到WSL1之后,问题再次消失.在Debian上也一样,在CentOS中也类似..因此WSL2必须有一个错误.

Windows10的内部版本为19041,并已于今天安装.

有人为WSL2解决吗?问候

解决方案

最有可能的是,分发版获得了自己的虚拟适配器,首先您可以尝试一些步骤:

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

  2. 如果数据包没有通过防火墙,最有可能的分发版本是它自己的虚拟适配器,请使用以下方法检查从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"))));打印inet_ntoa((sockaddr_in(getsockname(S)))[1]);' 

Windows WSL2主机上的

ipconfig ,并查看带IP的机器需要什么IP才能获得WSL适配器

  1. 如果您需要通过Windows IP访问互联网,请检查以下问题:

    After upgrading from WSL to WSL2

    sudo apt-get update
    

    not works any longer after

    wsl --set-version Ubuntu-18.04 2

    Output:

    > 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.
    

    After going back to WSL1 the problem disappears again. Same on Debian and analogous in CentOS .. so WSL2 must have a bug.

    The Windows10 build Version is 19041 and was installed today.

    Any work around for WSL2? Regards

    解决方案

    Most probably, the Distribution gets its own virtual adapter, first there are some steps you might try:

    1. Need to check if the packets really go through the Windows firewall Then check %systemroot%\system32\LogFiles\Firewall\pfirewall.log

    2. If packets are not going through firewall most likely the distribution gets it's own Virtual Adapter, check what IP gets distribution from inside Debian with:

      ifconfig

    or if you don't have 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]);'
    

    or ipconfig on the Windows WSL2 host machine and look what IP takes the machine unde WSL adapter

    1. If you need to have access to the internet through the Windows IP check this issue: https://github.com/microsoft/WSL/issues/4150

    The work around is to use a script that does :

    a. Get Ip Address of WSL 2 machine

    b. Remove previous port forwarding rules

    c. Add port Forwarding rules

    d. Remove previously added firewall rules

    e. Add new Firewall Rules

    $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";
      }
    

    An alternative solution is to go to Hyper-V Manager and change the Virtual Switch that is bound to the physical NIC

    这篇关于Windows10 WSL2 Ubuntu/Debian#apt-get更新失败#没有网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆