WSL2 Notes and Tips

Oct 8, 2020, 98 words

Settings

/etc/resolv.conf is overwritten at launch [1]

When using ssh, the hostname could be resolved from /etc/resolv.conf, but WSL2 will overwrite this file everytime it restarts. To disable this feature, we first add the following to /etc/wsl.conf

[network]
generateResolvConf = false

Then exit Windows Terminal and restart WSL2 by wsl --shutdown in PowerShell. Open Windows Terminal again and write the desired content to /etc/resolv.conf. This file will not be overwritten anymore.

Reference

[1]. https://superuser.com/questions/1533291/how-do-i-change-the-dns-settings-for-wsl2