Ubuntu getting wrong hostname from DHCP

Posted by sam on Super User See other posts from Super User or by sam
Published on 2014-08-21T15:42:50Z Indexed on 2014/08/21 16:22 UTC
Read the original article Hit count: 268

Filed under:
|
|
|

When provisioning new Ubuntu Precise (12.04) servers, the hostname they're getting seems to be generated from the DNS search path, not a reverse lookup on the hostname.

Take the following configuration

BIND is configured with the hostname, and reverse name

Normal zone $TTL 600 $ORIGIN srv.local.net.

@ IN SOA ns0.local.net.  hostmaster.local.net. (
        2014082101
        10800
        3600
        604800
        600 )

@               IN      NS      ns0.local.net.
@               IN      MX      5   mail.local.net.

my-new-server           IN      A       10.32.2.30

And reverse @ IN SOA ns0.local.net. hostmaster.local.net. ( 2014082101 10800 3600 604800 600 )

@ IN NS ns0.local.net.

$ORIGIN 32.10.in-addr.arpa.

30.2  IN  PTR my-new-server.srv.local.net.

Then DHCPD is configured to hand out static leases based on mac addresses like so

subnet 10.32.2.0 netmask 255.255.254.0 {
    option subnet-mask 255.255.254.0;
    option routers 10.32.2.1;
    option domain-name-servers 10.32.2.1;
    option domain-name "util.of1.local.net of1.local.net srv.local.net";

    site-option-space "pxelinux";
    option pxelinux.magic f1:00:74:7e;
    if exists dhcp-parameter-request-list {
        option dhcp-parameter-request-list = concat(option dhcp-parameter-request-list,d0,d1,d2,d3);
    }

    group {

        option pxelinux.configfile "pxelinux.cfg/pxeboot";

        host my-new-server {
            fixed-address my-new-server.srv.local.net;
            hardware ethernet aa:aa:aa:bb:bb:bb;
        }
    }
}

So the hostname should be my-new-server.srv.local.net, however when building a Ubuntu 12.04 node, the hostname ends up as my-new-server.util.of1.local.net

When building Lucid (10.04) hosts, the hostname will be correct, it's only on Precise/12.04 nodes we have the problem.

Doing a normal and reverse lookup on the host and IP returns the correct result

Sams-MacBook-Pro:~ sam$ host my-new-server
my-new-server.srv.local.net has address 10.32.2.30
Sams-MacBook-Pro:~ sam$ host my-new-server.srv.local.net
my-new-server.srv.local.net has address 10.32.2.30
Sams-MacBook-Pro:~ sam$ host 10.32.2.30
30.2.32.10.in-addr.arpa domain name pointer my-new-server.srv.local.net.

The contents of the hosts file is incorrect too

127.0.0.1       localhost
127.0.1.1       my-new-server.util.of1.local.net of1.local.net srv.local.net       my-new-server

So it looks like when it creates the hosts file, it puts the entire contents of the DNS search path into the local address so the FQDN according to the server is the short hostname as defined, then the first domain in the search path.

Is there a way to get around this behaviour, or fix this so it gets the hostname correctly? It's picking up the first part of the hostname, then the rest is wrong.

© Super User or respective owner

Related posts about networking

Related posts about ubuntu