At Mon, 22 Mar 2010 15:01:10 +1030,
Glen Turner <[email protected]> wrote:
>
> On 22/03/10 13:08, Peter Chubb wrote:
> >
> > Has anyone added scripts to dhcpd.conf to control DDNS AAAA records based
> > on MAC address?
>
> See ddns-hostname in dhcpd.conf(5). You can set it to an expression,
> see dhcp-eval(5). The vector "hardware" contains the MAC address.
I ended up shoving everything onto a shell script, and using execute().
It should be possible to do the bit-flipping directly in dhcpd though.
Here's what I ended up with:
In /etc/dhcp3/dhcpd.conf:
on commit {
if (not static) {
set ddns-fwd-name = option host-name;
execute ("/usr/local/bin/ddns-ipv6", ddns-fwd-name);
on expiry or release {
execute ("/usr/local/bin/ddns-ipv6", "-d", ddns-fwd-name);
}
}
}
And in /usr/local/bin/ddns-upv6:
#!/bin/sh
#
# Add or delete an IPv6 address record via DDNS
#
# Adjust these for your network.
PFX='2001:388:XXXX:YYYY'
DOMAIN=your.domain
KEYFILE=/etc/bind/Kyour.domain.+157+51932.private
# DEBUG
#exec 2> /tmp/ddns-ipv6-log >&2
#set -x
# Run the rest in an asynchronous subshell, to allow delays
# while the ARP cache is updated.
(
# May need /usr/local/[s]bin here too.
# But don't rely on the PATH handed in, because we may be
# run by a privileged user
PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH
# Get auto-allocated EUI-64 address via the ARP table.
ipv6addr()
{
# Ping to make sure the ARP table is populated.
until ping -c 1 "$2" > /dev/null 2>&1
do
sleep 1
done
MAC=`arp "$2" | sed -e 1d -e 's/[^ ]* * ether *\([^ ]*\) *C.*/\1/'`
# now flip bit 7 0-1 (GLOBAL not LOCAL address)
msb=`echo $MAC | sed 's/^\(..\):.*/\1/'`
NEWMSB=`echo "16i $msb 2 + 10op" | dc`
tail=`echo $MAC| sed
"s/\(..\):\(..\):\(..\):\(..\):\(..\):\(..\)/$NEWMSB\2:\3ff:fe\4:\5\6/"`
echo $1:$tail
}
Usage()
{
echo $1 [-d] prefix ddns-name
exit 1
}
case "$1" in
-d)
DELETE=1;
shift
;;
-*)
Usage $0
;;
*)
;;
esac
if [ "$DELETE" ]
then
IPADDR=`host -t aaaa "$1" | sed -n s'/.*address \(.*\)$/\1/p'`
[ "$IPADDR" ] || exit 1
nsupdate -k "$KEYFILE" <<-!
server localhost
update delete $1.$DOMAIN IN AAAA $IPADDR
send
!
else
IPADDR=`ipv6addr $PFX $1`
nsupdate -k "$KEYFILE" <<-!
server localhost
update add $1.$DOMAIN 86400 IN AAAA $IPADDR
send
!
fi
) &
exit 0
----
>
> In general though, I'd recommend against DHCPv6 outside of a residential
> ISP scenario (and even there the hosts will autoconf, it's the router
> which takes it's address from DHCPv6). Autoconf + stateles DHCPv6 seem
> to have much less difficulties.
I'm not using DHCPv6. I'm using autoconf for address and router
assignment, but I want hosts to be named, and to have consistent names across
IPv4 and IPv6. So DHCP for IPv4 (where hostnames are assigned) needs to add
the autoconfigured IPv6 address as well as the IPv4 address when doing ddns.
--
Dr Peter Chubb www.nicta.com.au peter DOT chubb AT nicta.com.au
http://www.ertos.nicta.com.au ERTOS within National ICT Australia
From Imagination to Impact Imagining the (ICT) Future
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html