-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixdns
42 lines (33 loc) · 960 Bytes
/
fixdns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
[ "root" != "$USER" ] && exec sudo $0 "$@"
# https://github.com/microsoft/WSL/issues/1350#issuecomment-327862941
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' | awk '!seen[$0]++' | tee $tmp
(set -x; sudo cp $tmp /etc/resolv.conf)
removeTempFiles