Skip to content

Instantly share code, notes, and snippets.

@ahmetozer
Created May 18, 2024 16:09
Show Gist options
  • Save ahmetozer/7209e8213303238d2123660e0e2bc392 to your computer and use it in GitHub Desktop.
Save ahmetozer/7209e8213303238d2123660e0e2bc392 to your computer and use it in GitHub Desktop.
dnsmasq dhcp fallback
#!/usr/bin/env bash
ON_BACKUP=0
while true; do
if netcat -zuvn 10.0.1.2 67 > /dev/null 2>&1 ; then
if [[ $ON_BACKUP != false ]]; then
echo "Switching to primary"
ON_BACKUP=false
service dnsmasq stop > /dev/null 2>&1
fi
else
if [[ $ON_BACKUP != true ]]; then
echo "Switching to backup"
ON_BACKUP=true
service dnsmasq start > /dev/null 2>&1
fi
fi
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment