Last active
August 10, 2020 20:17
-
-
Save hachesilva/90783e63c384c5778486f971a1f16d9c to your computer and use it in GitHub Desktop.
Route WSL1 network to use anyconnect VPN
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 characters
| #!/bin/bash | |
| # Source: https://github.com/microsoft/WSL/issues/1350 | |
| tmp=`mktemp` | |
| powershell="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" | |
| trap ctrlC INT | |
| removeTempFiles() { | |
| rm -f $tmp | |
| } | |
| ctrlC() { | |
| echo | |
| echo "Trapped Ctrl-C, removing temporary files" | |
| removeTempFiles | |
| stty sane | |
| } | |
| echo "Current resolv.conf" | |
| echo "-------------------" | |
| cat /etc/resolv.conf | |
| echo | |
| echo "Creating new resolv.conf" | |
| echo "------------------------" | |
| { | |
| head -1 /etc/resolv.conf | grep '^#.*generated' | |
| nameservers=$($powershell \ | |
| -Command "Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses" \ | |
| ) | |
| for i in $nameservers; do | |
| echo nameserver $i | |
| done | |
| tail -n+2 /etc/resolv.conf | grep -v '^nameserver' | |
| } | tr -d '\r' | tee $tmp | |
| (set -x; sudo cp -i $tmp /etc/resolv.conf) | |
| removeTempFiles | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment