Setting up a DNS server in WSL2
· One min read
Disabling automatic generation of /etc/resolv.conf
Edit /etc/wsl.conf as follows:
[network]
generateResolvConf = false
Creating /etc/resolv.conf
For example, if the DNS server is 1.1.1.1, edit /etc/resolv.conf as follows:
nameserver 1.1.1.1
Preventing Deletion
/etc/resolv.conf is deleted when WSL2 is restarted. To prevent this:
sudo chattr +i /etc/resolv.conf
