Register a hostname’s static ip with your corporate dns server
2012-07-17 1 Comment
My IT-administrator has reserved several ip-addresses for testing purposes. These addresses are statically assigned in /etc/networking/interfaces, like this:
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.1.38 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-nameservers 192.168.1.2 192.168.1.3 dns-search mydomain.local
One of the problems I faced was that when this address is assigned statically, the name of the host doesn’t get registered with the DNS server (when using dhcp it did get a proper hostname assigned to the ip)
With the help of our great friend Google, I found a solution. Put the following code in a shell script and call it from /etc/rc.local. Your machine gets registered each time it boots
#!/bin/bash HOST=`hostname -f` IP=`/sbin/ifconfig eth0 | sed -n '/inet addr:/s=[^:]*:\([^ ]*\).*=\1=;2p'` nsupdate < update delete $HOST A update add $HOST 86400 A $IP send EOF
Tested on Ubuntu 12.04 and a Windows Server based DHCP/DNS solution
Pingback: /dev/blog » How to send a client’s hostname to the DHCP server