web-dev-qa-db-ja.com

Windows10 WSL2 Ubuntu / Debian#apt-get update failed#no network

WSLからWSL2にアップグレードした後

Sudo apt-get update

もう機能しない

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.

WSL1に戻った後、問題は再び消えます。 Debianでも同じで、CentOSでも同様です。WSL2にはバグがあるはずです。

Windows10ビルドバージョンは19041で、今日インストールされました。

WSL2の回避策はありますか?よろしく

1
Jundl

ほとんどの場合、Distributionは独自の仮想アダプターを取得します。まず、いくつかの手順を試してみます。

  1. パケットが本当にWindowsファイアウォールを通過しているかどうかを確認する必要があります enter image description hereenter image description here 次に、%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")));
print inet_ntoa((sockaddr_in(getsockname(S)))[1]);'

またはWindows WSL2ホストマシンでipconfigを選択して、マシンがWSLアダプタとどのIPを使用しているかを確認します

  1. Windows IP経由でインターネットにアクセスする必要がある場合は、次の問題を確認してください: https://github.com/Microsoft/WSL/issues/415

回避策は、次のことを行うスクリプトを使用することです。

a。 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";
  }

代替ソリューションは、Hyper-Vマネージャーに移動し、物理にバインドされている仮想スイッチを変更することですNIC enter image description here

1

生成されたファイル/etc/resolv.confは次のとおりです。

ネームサーバー172.24.0.1

..変更する必要があった

ネームサーバー8.8.8.8

問題を解決します

10
Jundl