Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Oct 2008 15:17:35 +0100
From:      Henri Hennebert <hlh@restart.be>
To:        Roberto de Sousa <r_de_sousa@yahoo.com>
Cc:        freebsd-net@freebsd.org
Subject:   Re: NSupdate from CLI
Message-ID:  <49071EFF.1010806@restart.be>
In-Reply-To: <723811.95360.qm@web45207.mail.sp1.yahoo.com>
References:  <723811.95360.qm@web45207.mail.sp1.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Roberto de Sousa wrote:
> Hello Henri,
> Thank you for your kindness to help me on this.. I have generated the 
> key and and edit my named.conf as per your instruction. I have also 
> tried your script which work great. What i would like to find out more 
> is that how to modify this script so that it provides flexibility 
> without having to specify the host in the script?
> what i mean is that.. i could select add or delete option from CLI and 
> able to add any host to forward & Reversing Zone of my DNS from my 
> freeBSD CLI?

<--- clip --->

What do you thing about the attached script ? Some more check of args 
may be usefull ...

Henri

[-- Attachment #2 --]
#!/bin/sh
usage () {
    echo 'Usage: dnsupdate -a|-d|-u <HostName>=<IP_Address>'
    echo '	-a	add DNS entry for <HostName>'
    echo '	-d	delete DNS entry for <HostName>'
    echo '	-u	update DNS entry<HostName>'
}
NSSERVER='xxx.xxx.xxx.xxx'
TSIG='host1.example.com.:XXXX...XXXX=='
#-------------------------
case $# in
    2)	;;
    *)  usage >&2;
	exit 1;;
esac
HOSTNAME=${2%%=*}
IPADDR=${2##*=}
if [ ${HOSTNAME} = $2 -o ${IPADDR} = $2 ]
then
   usage >&2;
   exit 1
fi
IPADDR1=${IPADDR%%.*}
IPADDRX=${IPADDR#*.}
IPADDR2=${IPADDRX%%.*}
IPADDRX=${IPADDRX#*.}
IPADDR3=${IPADDRX%%.*}
IPADDR4=${IPADDRX#*.}
if [ "${IPADDR1}.${IPADDR2}.${IPADDR3}.${IPADDR4}" != ${IPADDR} ]
then
    usage >&2;
    exit 1
fi
delete() {
echo update delete ${HOSTNAME}. IN A
echo update delete ${IPADDR4}.${IPADDR3}.${IPADDR2}.${IPADDR1}.in-addr.arpa. IN PTR
}
add() {
echo update add ${HOSTNAME}. 60 IN A ${IPADDR}
echo update add ${IPADDR4}.${IPADDR3}.${IPADDR2}.${IPADDR1}.in-addr.arpa. 60 IN PTR ${HOSTNAME}.
}
case $1 in
    -a|-d|-u) ;;
    *)  usage >&2;
	exit 1;;
esac
case $1 in
    -a)	echo server ${NSSERVER};
	add;
	echo send;;
    -d) echo server ${NSSERVER};
	delete;
	echo send;;
    -u) echo server ${NSSERVER};
	delete;
	add;
	echo send;;
esac | /usr/bin/nsupdate -y ${TSIG} 1>/dev/null

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49071EFF.1010806>