Last active
December 8, 2021 21:43
-
-
Save bandogora/369609661abba2c61e66a1a785b9f009 to your computer and use it in GitHub Desktop.
Script to recreate resolve.conf in WSL2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# First create /etc/wsl.conf as sudo if it doesn't exist. Then add the following lines and restart wsl. | |
# [network] | |
# generateResolvConf = false | |
# Next run `sudo rm /etc/resolv.conf` then execute this script. | |
# Finally run `sudo ln -s $HOME/.resolv.conf /etc/resolv.conf` | |
nameservers=$(powershell.exe -Command "Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses") | |
echo -e nameserver $nameservers | sed -z 's/\r/\nnameserver/g' | head -n -1 > $HOME/.resolv.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment