2
1

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 1 year has passed since last update.

(Ubuntu-20.04)WSL2でping google.comが通らなかった経緯と解決策

Last updated at Posted at 2022-09-23

環境

  • windows11
  • wsl2

ubuntuのインストール

$ wsl --install -d  Ubuntu-22.04

インストールされていることを確認

wsl -l -v
  NAME            STATE           VERSION
* Ubuntu          Running         2
  Ubuntu-22.04    Running         2

ubuntuの起動

wsl -d Ubuntu-22.04

pignが通らない

$ ping www.google.com
ping: www.google.com: Temporary failure in name resolution

原因

DNSサーバーの設定ができていない模様

対策

  • /etc/wsl.confにresolv.confを再生成しないよう記述
# /etc/wsl.conf
[network]
generateResolvConf = false
  • /etc/resolv.confにnameserverを指定
# /etc/resolv.conf
nameserver 8.8.8.8
  • このままだとwsl起動するたびに上で作ったresolv.confが削除されるので、ファイルの属性を変更
$ sudo chattr +i /etc/resolv.conf

結果

通りました!

$ ping google.com
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms

参考文献

WSL2でresolv.confが消える問題の解決方法

【chattr】ファイルの属性を変更する

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?