aboutsummaryrefslogtreecommitdiff
path: root/chdns.sh
blob: 2d9a85a4fb09bba51f303e1ab1036e16aa1a7e0b (plain)
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
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/sh

dns_names="
    Default
	Quad9
    Google
    CloudFlare
"
dns_ips="
	0
	9.9.9.9,149.112.112.112
    8.8.8.8,8.8.4.4
    1.1.1.1,1.0.0.1
"

ssid=$(nmcli -t -f NAME connection show --active | sed q1)
default_dns=$(nmcli -g ipv4.dns connection show $ssid)

echo "Connection name: $ssid"
if [ -z $default_dns ]; then
	echo "DNS is not set!"
else
	echo "DNS set: $default_dns"
fi
echo

ind=0
for dns in $dns_names; do
	echo ${ind}. $dns
	ind=$((ind+1))
done

echo -n "enter the index: "
read ind
if [ $ind = 0 ]; then
	echo "nothing changed"
	exit
fi
ind=$((ind+1))

dns_name=$(echo $dns_names | cut -d ' ' -f$ind)
dns_ip=$(echo $dns_ips | cut -d ' ' -f$ind)

echo
echo "you selected: $dns_name"
echo "dns ips: $dns_ip"
echo

nmcli connection modify $ssid ipv4.dns $dns_ip
nmcli connection down $ssid > /dev/null
nmcli connection up $ssid > /dev/null
echo "dns changed successfully"