numminorih
Occasional Visitor
Hi to all,
I'm trying to make an automatic DNS change when the main one is unavailable. My current setup:
192.168.0.1 - router address
Settings:
WAN - Internet Connection
DNS Server - 192.168.0.10
LAN - DHCP Server - Enhanced by YazDHCP
DNS Server 1 - 192.168.0.1
192.168.0.10 - Pi-hole + dns DOH (claudfare) server
I need to make an automatic change of DNS to 8.8.8.8 when pi-hole is not available.
What I have found out so far:
- nvram set wan0_dns="8.8.8.8"; nvram set wan0_dns1_x="8.8.8.8"; nvram set wan_dns="8.8.8.8"; nvram set wan_dns1_x="8.8.8.8"; nvram commit
- work, but applying only after service restart_net (this take a lot of time, compared to change in GUI)
- service restart_dnsmasq - has no effect
- Not sure if I need to change:
/etc/resolv.conf
/tmp/resolv.conf
something else......
Also, please advise how to properly make the script track the availability of 192.168.0.10 and back to them after "UP"
/jffs/scripts/check_pihole
I'm trying to make an automatic DNS change when the main one is unavailable. My current setup:
192.168.0.1 - router address
Settings:
WAN - Internet Connection
DNS Server - 192.168.0.10
LAN - DHCP Server - Enhanced by YazDHCP
DNS Server 1 - 192.168.0.1
192.168.0.10 - Pi-hole + dns DOH (claudfare) server
I need to make an automatic change of DNS to 8.8.8.8 when pi-hole is not available.
What I have found out so far:
- nvram set wan0_dns="8.8.8.8"; nvram set wan0_dns1_x="8.8.8.8"; nvram set wan_dns="8.8.8.8"; nvram set wan_dns1_x="8.8.8.8"; nvram commit
- work, but applying only after service restart_net (this take a lot of time, compared to change in GUI)
- service restart_dnsmasq - has no effect
- Not sure if I need to change:
/etc/resolv.conf
/tmp/resolv.conf
something else......
Also, please advise how to properly make the script track the availability of 192.168.0.10 and back to them after "UP"
/jffs/scripts/check_pihole
Code:
#!/bin/sh
IP1=192.168.0.10
IP2=8.8.8.8
#start first ping, remember its pid
ping -W 1 -c 1 $IP1 >/dev/null&
PID1=$!
# start second ping, remember its pid
ping -W 1 -c 1 $IP2 >/dev/null&
PID2=$!
# wait for pings to finish
if wait $PID1
then
logger "$IP1 is UP";
nvram set wan0_dns="8.8.8.8"; nvram set wan0_dns1_x="8.8.8.8"; nvram set wan_dns="8.8.8.8"; nvram set wan_dns1_x="8.8.8.8"; nvram commit; service restart_net
fi
if wait $PID2
then
logger "$IP2 is UP"
???
fi