4

Running Centos 6.x using dhcp, we want to set the hostname to be FQDN that's obtained from a combination of dhcp options. As an example if I have two dhcp options option host-name "foobar"; option domain-name "mydomain.com";

When a client obtains those options via dhcp I would like the hostname to show "foobar.mydomain.com". Any idea on how to accomplish this?

Eugene
  • 41
  • 1
  • 1
  • 2

3 Answers3

4

For that you need to define this "ddns-hostname"

Like this:

host foobar {
  hardware ethernet c0:18:85:e3:13:31;
  fixed-address 10.1.1.129;
  option domain-name "example.org";
  option host-name "foobar";
  ddns-hostname "foobar.mydomain.com";
}
Napster_X
  • 3,373
  • 18
  • 20
2

Assuming you're using ISC DHCPd (the most popular on *nix platforms by far)

For each host add:

host workstation101 {
    hardware ethernet 01:02:03:04:05:06;
}

To configure the domain name:

option domain-name "example.org";

These can go in a subnet directive, or out in the global configuration, in your dhcpd.conf file.

Chris S
  • 77,945
  • 11
  • 124
  • 216
  • 1
    Looking in the file /var/lib/dhclient/dhclient-eth0.leases I see that both the host-name and domain-name are set, but when I type the command 'hostname' on the dhcp client, all I see is the hostname. The only place where I see the domain setting is in my /etc/resolve.conf as a search domain. This still doesn't answer the question on how to make the hostname command respond with the hostname.domainname. – Eugene Mar 07 '13 at 02:49
  • Are you running CentOS on the client as well? Did you install a different DHCP Client than the one that comes with the OS? – Chris S Mar 07 '13 at 03:03
  • The server and the client are on a different flavor of linux, but what difference does that make if the client picks up the option domain-name. – Eugene Mar 07 '13 at 18:34
0

Beware, isc dhcpclient (at least on Linux Mint 18) does not appear to be able to be forced in to setting the hostname from the server. I've spent hours trying to convince it to do so, and even when the server sends the hostname (and dhclient prints it in syslog!) dhclient ignores it.

Solution: Install dhcpcd5 and run dhcpcd instead. That's what I just did, and it worked perfectly.

RustyCar
  • 101