Making a linux VM running in Windows Azure auto-register in internal DNS.

Friday fun with other operating systems! Being a Windows guy with limited knowledge in Linux these things always burns a fuse it seems. Well, I have a customer spawning Linux vm:s in Windows Azure wanting these to automatically register their A-records in DNS just like Windows does. Well, seems there’s no easy way for this, but I’ve found a solution. Keep in mind that there might be an easier solution but for a Windows admin this at least works.

Prereqs for this to work:

  1. Your DNS-zone must accept unsecure updates.
  2. Your Linux machine must have its hostname updated with the FQDN.
  3. You must have a gateway to your internal network configured, not included in this article, no need to look for it. Look under “TV” for a guide on how to set that up.

Solution 1

Make sure your zone allows unsecure updates. Start DNS MMC, right-click your zone, select properties, edit your zone to allow Nonsecure and secure updates.









Solution 2

Edit /etc/hostname and add your unqualified hostname:


Edit /etc/hosts:

sudo vi /etc/hosts

Add an entry of your desired hostname by replacing ns-ub01 where is the fully qualified hostname and ns-ub01 is hostname. ns-ub01

Test your configuration by opening a terminal and enter the below commands:
“hostname<enter”>: This should output ns-ub01

“hostname -f”: This should output


You could also update it with the command hostname servernamn.fqdn which updates it but only lasts until reboot.


The script:


_IP=$(ifconfig eth0 | grep ‘inet addr:’ | cut -d: -f2 | awk ‘{ print $1}’)

nsupdate << EOF
server dnsservername.fqdn (
zone fqdn (
update delete $_HOST A
update add $_HOST 86400 A $_IP


The easiest way is to schedule the script with cron so that it runs periodically, this also updates the DNS in case the ip changes. The script is only tested on Ubuntu, but should at least get you started on other distros as well.

Leave a Reply

Your email address will not be published. Required fields are marked *