@@ -21,16 +21,47 @@ echo "Using interface: $IFACE"
2121echo  " Current configuration:" 
2222resolvectl status " $IFACE " |  grep -E ' Current DNS Server:|DNS Servers:' 
2323
24- echo  " Setting DNS to $LOCAL_DNS  for $IFACE " 
24+ #  Store the original DNS server for fallback
25+ ORIGINAL_DNS=$( resolvectl status " $IFACE " |  grep " DNS Servers:" |  sed ' s/.*DNS Servers: //' |  awk ' {print $1}' ) 
26+ echo  " Original DNS server: $ORIGINAL_DNS " 
2527
26- #  Reset interface configuration
28+ echo  " Setting DNS to $LOCAL_DNS  for $IFACE  (with fallback to $ORIGINAL_DNS )" 
29+ 
30+ #  Reset interface configuration first
2731resolvectl revert " $IFACE " 
2832
29- #  Set DNS to  local
30- resolvectl dns " $IFACE " " $LOCAL_DNS " 
33+ #  Set DNS with  local server FIRST (this makes it primary) 
34+ resolvectl dns " $IFACE " " $LOCAL_DNS "   " $ORIGINAL_DNS " 
3135
3236#  Confirm setup
3337echo  -e " \nUpdated configuration:" 
3438resolvectl status " $IFACE " |  grep -E ' Current DNS Server:|DNS Servers:' 
3539
40+ echo  -e " \nTesting DNS resolution..." 
41+ 
42+ #  Test if our local DNS is working
43+ echo  " Testing local BIND server directly:" 
44+ if  dig @127.0.0.1 www.basic.dnstest.php.net A +short;  then 
45+     echo  " ✓ Local BIND server is responding" 
46+ else 
47+     echo  " ✗ Local BIND server is not responding" 
48+     exit  1
49+ fi 
50+ 
51+ #  Test system DNS resolution
52+ echo  -e " \nTesting system DNS resolution:" 
53+ if  dig www.basic.dnstest.php.net A +short;  then 
54+     echo  " ✓ System DNS resolution is working" 
55+ else 
56+     echo  " ✗ System DNS resolution failed" 
57+ fi 
58+ 
59+ #  Test with nslookup as well
60+ echo  -e " \nTesting with nslookup:" 
61+ nslookup www.basic.dnstest.php.net ||  echo  " nslookup failed" 
62+ 
63+ #  Show which DNS server is actually being used
64+ echo  -e " \nFinal verification:" 
65+ resolvectl query www.basic.dnstest.php.net ||  echo  " resolvectl query failed" 
66+ 
3667echo  -e " \nDNS configuration has been updated." 
0 commit comments