I have an internal dns server for my lan (eg. pihole, adguard, technitium, nextdns, etc) and sometimes the server is down (it's too noisy, down for maintenaince, turning it off to save power, etc).
Since the server is down, none of the other clients can resolve dns.
The dns setting is set using dhcp option 6
#/etc/config/dhcp
config dhcp 'lan'
option interface 'lan'
option start '100'
option limit '150'
option leasetime '12h'
option dhcpv4 'server'
option dhcpv6 'hybrid'
option ra 'hybrid'
list ra_flags 'managed-config'
list ra_flags 'other-config'
option dhcp_option '6,192.168.100.10'
I was thinking to check if host is down (eg. 192.168.100.10
with ping
), using uci
to change dhcp.lan.dhcp_option
(change value or delete), restart dnsmasq
and network
services and force clients to renew dhcp leases (hoping the clients pick up the new config)
I would like to use a script and a cronjob for this
#!/bin/sh
# Host to check
HOST="192.168.100.10"
CONFIG_OPTION="dhcp.lan.dhcp_option"
CONFIG_VAL="6,192.168.100.10"
# Ping the host and check the exit status
CURRENT_DHCP_OPTION=$(uci get $CONFIG_OPTION)
if ping -c 1 $HOST > /dev/null 2>&1; then
echo "Host $HOST is up"
if [ "$CURRENT_DHCP_OPTION" != "$CONFIG_VAL" ]; then
echo "Change DHCP servers to good DHCP servers"
uci set $CONFIG_OPTION="$CONFIG_VAL"
uci commit dhcp
/etc/init.d/dnsmasq restart
echo "Restart network (1)"
/etc/init.d/network stop
sleet 3
/etc/init.d/network start
sleep 2
PID=$(pidof udhcpc) && kill -SIGUSR1 "$PID"
else
echo "won't change dhcp option value (1)"
fi
else
echo "Host $HOST is down"
if [ "$CURRENT_DHCP_OPTION" = "$CONFIG_VAL" ]; then
echo "Delete dhcp option"
uci delete dhcp.lan.dhcp_option
uci commit dhcp
/etc/init.d/dnsmasq restart
echo "Restart network (2)"
# /etc/init.d/network restart
/etc/init.d/network stop
sleet 3
/etc/init.d/network start
sleep 2
PID=$(pidof udhcpc) && kill -SIGUSR1 "$PID"
else
echo "won't change dhcp option value (2)"
fi
fi
I've verified the script does its job but clients won't pickup the change. The client (eg. windows) has to manually disconnect and reconnect for dns settings to take effect.
Is there anything that can be done (from openwrt side) to force clients to renew dhcp settings or reconnect?
Are there better ways to archieve the same task?