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 mkdir /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 ' | awk '{print $2}' | sed -e 's/.*://'`
HOST=`hostname -f`
DNSSERVER=`systemd-resolve --status | grep 'DNS Servers: ' -m 1 | sed -e 's/.*: //'`
DNSZONE=`systemd-resolve --status | grep 'DNS Domain: ' -m 1 | sed -e 's/.*: //'`

echo "server $DNSSERVER" > ./nsupdate.txt
echo "zone $DNSZONE" >> ./nsupdate.txt
echo "update delete $HOST A" >> ./nsupdate.txt
echo "update add $HOST 600 A $ADDR" >> ./nsupdate.txt
echo "show" >> ./nsupdate.txt
echo "send" >> ./nsupdate.txt

#cat ./nsupdate.txt
nsupdate ./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/