Skip to content

Instantly share code, notes, and snippets.

@souhaiebtar
Last active October 26, 2021 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save souhaiebtar/1a968cc9c1ba4152ddd246f29eedb65f to your computer and use it in GitHub Desktop.
Save souhaiebtar/1a968cc9c1ba4152ddd246f29eedb65f to your computer and use it in GitHub Desktop.
[fix connection on wsl2 behind vpn] fix connection on wsl2 behind vpn #wsl2 #vpn #dns

on PowerShell, run

Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses (on the result returned you have to detect which dns address is used for your vpn, in my case, 3 result are returned, 2 are internal to my local network than it should be the third (for sake of example: 11.9.8.7).

than i used wsl --list --verbose to list wsl2 installation that i had, i had one called Debian (correspond to debian installed from windows store)

than i applied the below command in Debian Shell (thanks goes to 1)

# steps explanations
1 cd /etc go to etc folder in WSL
2 echo "[network]" | sudo tee wsl.conf Create wsl.conf file and add the first line.
3 echo "generateResolvConf = false" | sudo tee -a wsl.conf Append wsl.conf the next line.
4 wsl --terminate Debian Terminate WSL in Windows cmd.
5 cd ~/../../etc go to etc folder in WSL
6 echo "nameserver 11.9.8.7" | sudo tee resolv.conf Create or override resolv.conf and append the line.
7 wsl --terminate Debian Terminate WSL in Windows cmd.

N.B: sometime file creation won't work (it happened for me for /etc/resolv.conf), you can just created under a user directory and move it to another folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment