iTranslated by AI
Fixing WSL2 internet connectivity issues when VPN is enabled
Introduction
WSL2 is convenient, but I was troubled by an issue where the internet became unusable (DNS could not be resolved) when a VPN was enabled.
I found a way to fix it, so I will summarize the method here.
Microsoft's Official Method
To summarize, it seems to suggest rewriting /etc/resolv.conf every time you connect to or disconnect from a VPN.
This is tedious, so I don't want to do it.
An Easier Way
First, log in to WSL2 (Ubuntu 20.04.1), create a file named /etc/wsl.conf, and write the following settings.
[network]
generateResolvConf = false
Next, restart WSL2 on the Windows side.
> wsl -l
> wsl -t Ubuntu
Log in to WSL2 again and delete /etc/resolv.conf.
It should likely be a broken symbolic link.
$ rm /etc/resolv.conf
Recreate /etc/resolv.conf with the following content. Any DNS server that works both when the VPN is enabled and disabled will do.
nameserver 8.8.8.8
Go back to the Windows side once more and restart WSL2.
> wsl -l
> wsl -t Ubuntu
Now, the internet should be accessible both when the VPN is enabled and disabled.
Summary
WSL2 is so convenient!
Discussion