Skip to content

Instantly share code, notes, and snippets.

@domanchi
Created December 10, 2021 06:05
Show Gist options
  • Save domanchi/5cb3eb8253779521be3bd07b9a3717db to your computer and use it in GitHub Desktop.
Save domanchi/5cb3eb8253779521be3bd07b9a3717db to your computer and use it in GitHub Desktop.
WSL VPN DNS Fix

WSL VPN DNS Fix

Problem

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.

Solution

1. Disable the auto-generation of /etc/resolv.conf

/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

2. Restart WSL

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

3. Override Old Link with New Content

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
# Default to using Cloudflare DNS over HTTPS when not using VPN
# https://developers.cloudflare.com/1.1.1.1/
nameserver 1.1.1.1
nameserver 1.0.0.1
# Specify the VPN DNS servers, based on the VPN provider that you use.
# These values were obtained from https://www.privateinternetaccess.com/helpdesk/kb/articles/next-generation-dns-custom-configuration
nameserver 10.0.0.243
nameserver 10.0.0.242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment