Update hostname from Debian machine with DHCP to a Windows 2008 DNS server

16
2014-04
  • Electric Monk

    I have a XenServer installation with Debian (lenny) machines created on a daily basis using a script which creates the machine from a template and assigns it with a new hostname.

    Our network has a Fortinet 60B appliance which servers as the DHCP server and a Microsoft Windows 2008 DC which also serves as a DNS server. I'd like to configure the VM template to send its hostname to the DNS server when it gets a leased IP from DHCP.

    Currently, Fortinet assigns the DC as the DNS server along with the IP lease. I tried adding a 'send host-name "my-host-name"' line to /etc/dhcp3/dhclient.conf, but nothing gets updated in the DC.

  • Answers
  • user9437

    So basically you want your client to send their hostname to your DNS server ?

    This works great with Windows clients, but for Linux machines, I would go the other way around : set your clients to ask the DHCP server for an IP and a hostname. Using the "request host-name" option, dhclient asks the DHCP server to send a hostname along with the IP address, then sets the hostname of the VM.

    Of course you'll need to prepare, in your DNS, a hostname for each IP address in the DHCP range.

    This way you don't have the DNS cache / propagation delay problem, and you may have a central place with all the IP and hostnames - your DNS server.

    I don't know wether your appliance's DHCP server supports sending hostnames - most does, but I think that's the easiest way for Linux clients.

    Note: If you configured your DHCP server so that the same machine always get the same IP address (e.g. using mac address) then it will, obviously, always get the same hostname too. On some DHCP server, you can use directly hostname instead of IP address in the config files.

  • Electric Monk

    I Ended up using a script which runs nsupdate after VM is created from template and upon each boot.

  • John Gardeniers

    This is somewhat similar to my own question. Have a look at my final comment to the one and only answer I received, where I refer to dhclient.conf.

  • joeqwerty

    Two things I've found that were required to get a non-domain joined machine to register and update it's DNS records on a Windows DC\DNS server:

    1. Configure the DC\DNS server to allow both secure and unsecure dynamic DNS updates.

    2. Configure the FQDN of the non-domain joined host to match your AD\DNS name: as in host.domain.com

  • James

    Hmm. Never tried this exact config - I've had this working with Linux clients to Windows DHCP servers, but in that setup the DHCP server does the update. Not sure if the Fortinet box does the same thing.

    You could try making the client talk to the DNS server directly; something like:

    send fqdn.server-update off;
    send fqdn.encoded on;
    send fqdn.fqdn "hostname.example.com.";  
    

    in /etc/dhcp3/dhclient.conf. Check man dhclient.conf for more info. I had to set at least send fqdn.fqdn to get it working in my setup.

    You'll have to enable insecure updates to your DNS zones as well.

  • RobM

    Many may consider this blatantly obvious, but be sure to specify your own request directive in dhclient.conf which does not request a hostname or domain-name. The default on my distro was:

    request subnet-mask, broadcast-address, time-offset, routers,
            domain-name, domain-name-servers, host-name,
            netbios-name-servers, netbios-scope, interface-mtu;
    

    Note that this requests both host and domain names from the server which nullifies a send host-name ... directive. My request and send-host directives look like this:

    send host-name "leaf.node.domain.com";
    request subnet-mask, broadcast-address, time-offset, routers,
            domain-name-servers,
            netbios-name-servers, netbios-scope, interface-mtu;
    

  • Related Question

    linux - How does my DHCP server know my machine's hostname when I didn't define one in dhclient.conf?
  • Mike Spross

    I'm trying to resolve some funky DNS issues related to DHCP on our network (I suspect we have more than one DHCP server running at the moment), and while trying to figure that out, I noticed something strange with a new server I just set up.

    The server in question is a Xen virtual machine running Ubuntu 9.10 Server. The physical Xen server is also on our network, and when I booted up the VM for the first time in Xen (I imported it from a local Virtualbox VM running on my machine, where it was running on a different network), it got a DHCP lease from our office network and everything was good.

    I checked the dhclient.eth0.leases file to see what got configured, and saw that the old DHCP lease from the previous network the machine was on was still there, as well as the new DHCP lease for the office network it's currently connected to. There are two things I noticed right away:

    1. The old DHCP lease information from the previous network doesn't have an options host-name line, which I take to mean the original VirtualBox version of the VM wasn't sending this option to the DHCP server. Or does this mean the old DHCP server didn't support the DHCP host name option? It was using VirualBox's internal DHCP server at the time...

    2. The new DHCP lease information does have an options host-name line, which includes the correct, current hostname for the server ("fozzie"). If I understand correctly, this means the server sent it's hostname to the DHCP server on our network.

    There are a number of things I don't understand about all this.

    First, I did not change dhclient.conf for the server at any point; it's using the default configuration. In fact it contains the following line verbatim:

    send host-name "<hostname>"

    So my first question is, how in the heck did it know to send the server's real hostname if the configuration isn't set up to send it in the first place?

    Second, why did the first DHCP lease (for the old network) not include option host-name, but the second DHCP lease (on the new network) did include it, if I haven't touched any of the configuration files?

    All I did was export the original VirtualBox machine as an OVF, and then import it into XenServer, so how did it magically configure my hostname via DHCP if it's not even configured with the actual hostname in dhclient.conf?

    Third: When I run hostname, the server returns fozzie.our.domain, but dhclient.eth0.leases says the hostname option was set to fozzie (no domain). How did it know to strip off the domain?


  • Related Answers
  • Mike Spross

    OK, after a long time trawling the Internet and trying to read through man pages, I mostly figured out what's going on:

    [H]ow in the heck did it know to send the server's real hostname if the configuration isn't set up to send it in the first place?

    Apparently, send host-name "<hostname>", and more specifically, <hostname>, has special significance on Ubuntu. It tells dhclient to send your machine's current hostname to the DHCP server. Note that this is case-sensitive (i.e. if you type <HOSTNAME>, dhclient will send the literal text <HOSTNAME> to the DHCP server). As reported here and here, this works on Ubuntu Feisty and above, being part of a patch to (ironically) fix a problem with dhclient not sending the machine's hostname by default.

    [W]hy did the first DHCP lease (for the old network) not include option host-name, but the second DHCP lease (on the new network) did include it, if I haven't touched any of the configuration files?

    This just seems to be because not all DHCP servers will echo the hostname back to the client. Yesterday we still using a Linux-based ClarkConnect router as our DHCP server, which echoed the hostname back to each client. Today we disabled DHCP on that server, and switched to using the built-in DHCP server on our primary domain controller. Our DHCP leases from the PDC don't include option host-name either, but it doesn't seem to affect anything. The machines get updated in DNS, and they can all find each other by hostname.

    When I run hostname, the server returns fozzie.our.domain, but dhclient.eth0.leases says the hostname option was set to fozzie (no domain). How did it know to strip off the domain?

    This is me not fully understanding the intricacies of DHCP. Our DHCP server was set to configure all of our clients with our domain. I'm guessing the DHCP server was smart enough to remove the domain name portion from the hostname sent by the client.

    Anyone have any corrections or clarifications to add to this answer? It still seems a bit "hand-wavy", so I won't accept it as-is.