WSL2でhostsの書き換え


やりたいこと

LinuxやMacみたいに、Windows + WSL2 でも hostsファイルを書き換えて、色んなドメイン名をローカルで使いたい

How to

  1. WSL2からWindowsのIPを確認
    • cat /etc/resolv.conf | grep nameserver | cut -d ' ' -f 2
  2. C:\Windows\System32\drivers\etc\hosts を編集

    \Windows\System32\drivers\etc\hosts
    172.21.160.1 kuchitama.com
    172.21.160.1 test1.kuchitama.com
    
  3. WSL2を再起動

    • wsl --shutdown
  4. 完了

参考記事

how to associate windows hosts file entry with process running on WSL