-
-
Save adripo/0b65877d4b2a08baf268d05625ea9c99 to your computer and use it in GitHub Desktop.
Revisions
-
ThePlenkov revised this gist
Sep 6, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ There are tons of gists available for this problem: - [Fix DNS resolution in WSL2](https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6) However even solution is there - I was not satisfied that this problem always persists and I had to do same steps again from time to time. Also using a static DNS like 8.8.8.8 was not the option for me because we use pool of enterprise DNS servers and those are controlled by our IT on our Windows machines. So I wanted to find the way to get those DNS servers dynamically from Windows. This guide describes the permanent solution using brand-new WSL boot [command](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings). -
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ #!/bin/bash # Remove existing "nameserver" lines from /etc/resolv.conf sed -i '/nameserver/d' /etc/resolv.conf # Run the PowerShell command to generate "nameserver" lines and append to /etc/resolv.conf # we use full path here to support boot command with root user /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '(Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses | ForEach-Object { "nameserver $_" }' | tr -d '\r'| tee -a /etc/resolv.conf > /dev/null -
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ There are tons of gists available for this problem: - [Fix DNS resolution in WSL2](https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6) However even solution is there - I was not satisfied that this problem alaways persists and I had to do same steps again from time to time This guide describes the permanent solution using brand-new WSL boot [command](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings). -
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ However even solution is there - I was not satisfied that this probalem alaways This guide describes the permanent solution using brand-new WSL boot [command](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings). > This gist removes nameservers every time your WSL starts and adds newly from powershell results. If it doesn't work for you - please feel free to adjust the script according to your needs. ## Prepare boot config -
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,8 @@ However even solution is there - I was not satisfied that this probalem alaways This guide describes the permanent solution using brand-new WSL boot [command](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings). > This gist removes nameservers every time you boot your WSL loads and adds newly from powershell results. If it doesn't work for you - please feel free to adjust the script according to your needs. ## Prepare boot config - login to your wsl and run `sudo bash`. It's important that you do this with a root user because it's a user which executes this command during boot -
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # How to resolve DNS issue in WSL once and forever There are tons of gists available for this problem: - [Fix DNS resolution in WSL2](https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6) -
ThePlenkov revised this gist
Aug 7, 2023 . 2 changed files with 30 additions and 11 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,36 @@ # How to resolve DNS issue in WSL once and foreever There are tons of gists available for this problem: - [Fix DNS resolution in WSL2](https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6) However even solution is there - I was not satisfied that this probalem alaways persists and I had to do same steps again from time to time This guide describes the permanent solution using brand-new WSL boot [command](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings). ## Prepare boot config - login to your wsl and run `sudo bash`. It's important that you do this with a root user because it's a user which executes this command during boot - change to ~ folder ( or use any folder you like ) - create a new file for example `boot.sh` and update it with a content from [boot.sh](#file-boot-sh) gist - make it executable with `chmod +x boot.sh` - create a symbolic link in one of PATH folders ( keep in mind, that for root user number of path folders is very limited by default ) ``` /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin ``` - i have used `ln -s ~/boot.sh /usr/local/bin/boot.sh` - having such a limited list of folders makes root not aware of powershell.exe and rest of window utilities. I have preferred to use an absolute path like `/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` in my script - but you may think of creating a symlink for powershell too. - now let's add boot command to `/etc/wsl.conf` file. In my case it looks like this: ``` [network] generateResolvConf=false [boot] systemd=true command=boot.sh ``` - now just `exit` from bash, from wsl as well. Terminate your wsl with a command like `wsl -t Ubuntu` and start again - if everything went well `cat /etc/resolv.conf` should have nameservers from your Windows -
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 1 addition and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,14 @@ # powershell script - create file [resolve_wsl_dns.sh](#file-resolve_wsl_dns-sh) with content and save. You can use `nano resolve_wsl_dns.sh` for example - make it executable ``` chmod +x resolve_wsl_dns.sh ``` - Move it to any of PATH folders, if you have a plan to run it during ``` mv resolve_wsl_dns.sh ~/bin/ echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc ``` -
ThePlenkov revised this gist
Aug 7, 2023 . No changes.There are no files selected for viewing
-
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # powershell script - create file [resolve_wsl_dns.sh](#file-resolve_wsl_dns-sh) with content and save. You can use `nano resolve_wsl_dns.sh` for example ``` #!/bin/bash -
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # powershell script - create file [resolve_wsl_dns.sh](raw/resolve_wsl_dns.sh) with content and save. You can use `nano resolve_wsl_dns.sh` for example ``` #!/bin/bash -
ThePlenkov revised this gist
Aug 7, 2023 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,4 +4,5 @@ sudo sed -i '/nameserver/d' /etc/resolv.conf # Run the PowerShell command to generate "nameserver" lines and append to /etc/resolv.conf # we use full path here to support boot command with root user /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '(Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses | ForEach-Object { "nameserver $_" }' | sudo tee -a /etc/resolv.conf > /dev/null -
ThePlenkov created this gist
Aug 7, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ # powershell script - create file resolve_wsl_dns.sh with content and save. You can use `nano resolve_wsl_dns.sh` for example ``` #!/bin/bash # Remove existing "nameserver" lines from /etc/resolv.conf sudo sed -i '/nameserver/d' /etc/resolv.conf # Run the PowerShell command to generate "nameserver" lines and append to /etc/resolv.conf powershell.exe -Command '(Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses | ForEach-Object { "nameserver $_" }' | sudo tee -a /etc/resolv.conf > /dev/null ``` - make it executable ``` chmod +x resolve_wsl_dns.sh ``` - Move it to any of PATH folders or create a new one, for example ``` mkdir ~/bin mv resolve_wsl_dns.sh ~/bin/ echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc ``` - if you have Windows 11 - you can try to use [boot](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings) command nan This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ #!/bin/bash # Remove existing "nameserver" lines from /etc/resolv.conf sudo sed -i '/nameserver/d' /etc/resolv.conf # Run the PowerShell command to generate "nameserver" lines and append to /etc/resolv.conf powershell.exe -Command '(Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses | ForEach-Object { "nameserver $_" }' | sudo tee -a /etc/resolv.conf > /dev/null