Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadmiller/d3c2c949c4c70861bd0e to your computer and use it in GitHub Desktop.
Save chadmiller/d3c2c949c4c70861bd0e to your computer and use it in GitHub Desktop.
#!/bin/bash
# on ubuntu, /etc/network/if-up.d/nxdomain-discovery
set -e -u
test -x /usr/bin/host || exit 0
case "$ADDRFAM" in
inet|inet6) : ;;
*) exit 0 ;;
esac
change_test=$(run-parts --list /etc/NetworkManager/dnsmasq.d |md5sum)
host=does-not-exist-${RANDOM}.example.com.
t=$(tempfile)
test -f "$t"
trap "rm -f \"$t\"" EXIT
if host -t A "${host}" >"$t"; then
cat "$t" |while read host has xaddress address; do
if test "$address" == "${address/[^0-9.]/x}"; then
echo "bogus-nxdomain=${address/[^0-9.]/x}" >/etc/NetworkManager/dnsmasq.d/nxdomain-automatically-discovered-"${address//[^0-9.]/x}"
else
test ! -x /usr/bin/logger || echo "lookup of ${host} yields unexpected answer: $host $has $xaddress $address" |logger --priority daemon.warning
fi
done
fi
if "${change_test}" != "$(run-parts --list /etc/NetworkManager/dnsmasq.d |md5sum)"; then
test ! -x /usr/sbin/service || echo "service network-manager restart" |at "now + 1 minute"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment