Tested on Ubuntu-20.04, Windows 11
Create a script that will be executed at WSL boot and that will use the default routing table as DNS (which is the host's ip).
The solution consists in using the host (Windows) as DNS. It will then use its own configuration.
- First gain root privileges:
sudo bash
- Go to root home to work:
cd ~
- Create the file
reset-dns.sh
with the content of reset-dns.sh - Make this file executable:
chmod +x reset-dns.sh
- Either create a symlink or move this script to
/usr/local/bin
(or in any other folder that is in root's$PATH
) - From now on you can try the script to make sure this works:
reset-dns.sh
ping www.github.com
See Boot settings
- Still with root access, change WSL configuration in
/etc/wsl.conf
:
- Under
[network]
, addgenerateResolvConf=false
to make sure WSL will not try to generate it itself - Under
[boot]
, addcommand=reset-dns.sh
to launch the script you created earlier when booting You can see my wsL.conf to compare.
- Stop WSL using another terminal (like
cmd
):wsl --terminate Ubuntu-20.04
or more brutalwsl --shutdown
- Now when you launch a new Ubuntu terminal, you will be able to join the whole World Wide Web 😁 You can try to change network to make sure the solution fits your case.
- Usually, you should not need to use the script again, but you can use
sudo reset-dns.sh
to reset the DNS again at any time.