Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

34
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSL2がネットワークに接続できない時の対処法

Last updated at Posted at 2020-11-11

ホストのWindowsでは問題なくネットワークに繋がっているのに、WSL2を起動してもネットワークに接続できないことがあります。

そのたびに色々検索することになるので、ここに備忘録として記します。

環境

・WSL2: Ubuntu 20.04 LTS
・OS: Windows 10 Home Insider Preview
 ・バージョン: 2004
 ・OSビルド: 20197.1000

WSL2がネットワークに繋がらない時の対処法

結論としては、Powershellを管理者権限で実行し、以下のコマンドを順に実行します。
・LxssManagerの再起動

Restart-Service LxssManager

・Host Network Serviceの再起動

Stop-Service -name "hns" 
Start-Service -name "hns"

・Hyper-Vアダプタの再起動

Get-NetAdapter -IncludeHidden | Where-Object `
    {$_.InterfaceDescription.StartsWith('Hyper-V Virtual Switch Extension Adapter')} `
    | Disable-NetAdapter -Confirm:$False
Get-NetAdapter -IncludeHidden | Where-Object `
    {$_.InterfaceDescription.StartsWith('Hyper-V Virtual Switch Extension Adapter')} `
    | Enable-NetAdapter -Confirm:$False

再起動は不要です。WSLで通信ができるようになっているはずです。

原因は分からないのですが、WSLが再起動するたびに内部のIPアドレスが変わることが関係してそうです。

何か分ったことがあれば追記したいと思います。

参考

34
29
2

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
34
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?