Register a hostname’s static ip with your corporate dns server

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

About these ads

One Response to Register a hostname’s static ip with your corporate dns server

  1. Pingback: /dev/blog » How to send a client’s hostname to the DHCP server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: