On Windows Subsystem for Linux (WSL), I noticed a perculiar thing when I connected to VPN -- the network connections stopped working. This problem was consistent across devices, and based on my SRE experience, I knew that it was probably a DNS problem. I just didn't know how to resolve it.
Then, I came across this thread, which kicked off the appropriate rabbit hole to search in to resolve my long standing problem.
/etc/resolv.conf
allows the user to specify DNS servers in unix machines (source). It is similar to /etc/hosts
but instead of specifying the mapping between a hostname and an IP, it specifies DNS servers itself.
In WSL, this file is auto-generated (perhaps to maintain some compatibility between Windows and Linux). To disable this, we need to configure the appropriate file as instructed by the default content in /etc/resolv.conf
.
$ sudo vim /etc/wsl.conf
[network]
generateResolvConf = false
With the auto-generation of /etc/resolv.conf
disabled, we can now restart WSL to remove the link that the original /etc/resolv.conf
was pointing to. We can do this by opening Powershell as an Administrator, and running:
PS C:\Users> wsl --shutdown
Re-open WSL and verify that the link is gone by doing:
$ ls -lA /etc/resolv.conf
You should notice that this is a broken link. Once you have verified this, we can delete that broken link, and override it with our own configured /etc/resolv.conf
.
$ rm /etc/resolv.conf
$ sudo vim /etc/resolv.conf