How to make a linux machine with a static IP address dynamically add its hostname to DNS
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
By jrwsod at 2009-12-21 11:07
I had searched for this answer for hours and finally was able to cobble together enough pieces of the puzzle to compile this "how to" document. There are many references to adding the DHCP_HOSTNAME parameter to the ifcfg-ethX file. While that approach will work for DHCP it will not for statically assigned IP addresses.
Please note: This "how to" only addresses registering a statically assigned IP dynamically with DNS - WINS/NETBIOS is not used. In this example I am using non-secure dynamic updates to a Windows 2003 DNS server that is active directory enabled. I have not used this with a DNS server that requires secure dynamic updates although there are options in nsupdate to facilitate this functionality (man nsupdate is your friend). In this example I have the DNS server to be updated already entered in the /etc/resolv.conf so I am not specifying it explicitly but that can be done as well. I am creating a record with a 1 day TTL, change that to match you standard TTL if needed. I am running this as root to avoid any confusion in the example but this command can be run as a regular user as well.
I’ll get right to the commands to do this manually so you can see how it works. Basically this is done using the command nsupdate.
When you type nsupdate you get taken to a command prompt >. There are multiple commands available. The ones we will use are update add, update delete, send, answer and quit.
Code:
[root@testmachine1 ~]# nsupdate
> update delete testmachine1.domain1.local
> update add testmachine1.domain1.local 86400 A 10.1.1.1.1
> send
> answer
Outgoing update query:
;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id: 61616
;; flags: qr ; ZONE: 1, PREREQ: 0, UPDATE: 1, ADDITIONAL: 0
;; ZONE SECTION:
;domain1.local. IN SOA
;; UPDATE SECTION:
testmachine1.domain1.local. 86400 IN A 10.1.1.1
> quit
The first thing we want to do is remove any existing A records for the hostname we are using. Once that is done we want to register a new A record for this host. The commands will not be processed until a send command is entered. Lastly we run a answer command to see what the response was for the last command. You could, if you wanted to see what was happening at each step, use the send and answer commands after each update.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
You are using 4 applications when you do (single line):