Skip to content

Instantly share code, notes, and snippets.

@meeuw
Forked from anonymous/dnsmasq.sh
Created November 28, 2013 19:48
Show Gist options
  • Save meeuw/7697261 to your computer and use it in GitHub Desktop.
Save meeuw/7697261 to your computer and use it in GitHub Desktop.
Hookscript for dhclient (place in /etc/dhcp/dhclient.d) to configure dnsmasq (using dbus) with the supplied nameserver. Add enable-dbus to dnsmasq
#!/bin/bash
function inet_aton () {
local count=3
local int=0
for num in $(echo $1 | sed -e 's/\./ /g'); do
let "int+=$num*256**$count"
let "count-=1"
done
echo $int
}
if [ "$new_domain_name_servers" ] ; then
SetServers=$new_domain_name_servers
elif [ "$DHCP4_DOMAIN_NAME_SERVERS" ] ; then
SetServers=$DHCP4_DOMAIN_NAME_SERVERS
else
SetServers="8.8.8.8 8.8.4.4"
fi
dnsmasq_config() {
echo uint32:$(inet_aton $SetServers) > /var/lib/dnsmasq/SetServers
dbus-send --system --dest='uk.org.thekelleys.dnsmasq' /uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetServers $(< /var/lib/dnsmasq/SetServers)
}
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment