LoginSignup
20
18

More than 1 year has passed since last update.

【WSL2】WSL2でUbuntuを動かしたらハマった件(sudo apt-get updateできない)

Last updated at Posted at 2021-06-19

2021/06/19 土曜日

Intrduction

WSL2でUbuntu-20.04をうごかしてみました。
その際にハマった事について記事にしておきます。
お役にたてれば幸いです。

What to do?

つぎの作業をおこないました。

  1. Windows 10 アップデート(20H1)
  2. WSL2インストール
  3. Ubuntu-20.04インストール
  4. Docker Desktop for Windowsインストール
  5. Ubuntu-20.04で sudo apt-get update ←問題発生

(事象1)Ubuntu-20.04起動直後にsudo apt-get update出来ない

(前提)Windows 10はWi-Fiアクセスポイント経由でインターネットへ接続していた。

原因

WSL2の仮想ネットワークアダプvEthernet (WSL)がインターネットに接続出来ていなかった。

解決

Wi-Fiネットワークアダプタの共有を有効にする。

  • ネットワークのほかのユーザーに、このコンピューターのインターネット接続をとおしての接続を許可する

2021-06-16_1623837555.png

(事象2)名前解決が出来ない

host google.com

事象1を解決したのだが。。
上記のコマンドで名前解決出来ない。

原因

Linuxコンテナー(Ubuntu)のresolv.confでコンテナー内のIPアドレスが設定されていた。
そのため、名前解決が出来ずにapt-getが失敗していた。

解決

/etc/resolv.comfnameserver 8.8.8.8を追加する

sudo rm /etc/resolv.conf
sudo sh -c "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"
host google.com

(事象3)sudo apt-get updateErr:が表示される。

事象1、事象2を解決したのだが。。
fetchが失敗する。

$ sudo apt-get update
Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.142), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out
Err:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable)
Err:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable)
Err:4 http://security.ubuntu.com/ubuntu focal-security InRelease
  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.39), connection timed out
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.142), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed outW: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable)
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable)
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.39), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.

原因

ウィルスソフトのファイアウォールが邪魔をしていた。

  • わたしの場合、Symantec Endpoint Protectionが邪魔をしていた。

解決

ファイアウォール機能を一時的に無効にする。

2021-06-19_1624107649.png

Conclusion

WSL2のUbuntu-20.04コンテナーのネットワークの仕組みは、Linuxほど素直ではなさそうです。
UbuntuマシンでLinuxコンテナーを設定した際はなにも問題なく動作しました。

何かのお役に立てれば幸いです。👍

(了)

20
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
18