Register Linux (Ubuntu) server with Windows DNS

If you are looking for a script to help register your linux box with a windows DNS sever than you have come to the right place.

Note: For this to work you need to have enabled Windows DNS to allow unsecure updates

Note: This script ASSUMES that your /etc/network/interfaces is setup for static IP and has dns-nameservers and dns-search setup


# The primary network interface
auto eth0
iface eth0 inet static
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers #my Windows DNS server
        dns-search corp.local # my DNS zone that I want to update

Step 1: create a folder calls /var/scripts

sudo vi /var/scripts

Step 2: create a script file called

sudo vi /var/scripts/

Step 3: paste the following into the script file

ADDR=`/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e s/.*://`
HOST=`hostname -f`
DNSSERVER=`grep '[^#]dns-nameservers' /etc/network/interfaces | awk '{print $2}' | head -1`
DNSZONE=`grep '[^#]dns-search' /etc/network/interfaces | awk '{print $2}' | head -1`
echo "server $DNSSERVER" > /var/scripts/nsupdate.txt
echo "zone $DNSZONE" >> /var/scripts/nsupdate.txt
echo "update delete $HOST A" >> /var/scripts/nsupdate.txt
echo "update add $HOST 600 A $ADDR" >> /var/scripts/nsupdate.txt
echo "show" >> /var/scripts/nsupdate.txt
echo "send" >> /var/scripts/nsupdate.txt
nsupdate /var/scripts/nsupdate.txt

Step 4: Enable the script for execution

sudo chmod +x /var/scripts/

Step 5: Run the script (or schedule it via cron)

sudo /var/scripts/dns-update.sh1