How to set hostname.domainname from dhcp

13,416

Solution 1

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";
}

Solution 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.

Share:
13,416
Bình Nguyễn
Author by

Bình Nguyễn

Updated on September 18, 2022

Comments

  • Bình Nguyễn
    Bình Nguyễn over 1 year

    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?

  • Bình Nguyễn
    Bình Nguyễn about 11 years
    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.
  • Philip
    Philip about 11 years
    Are you running CentOS on the client as well? Did you install a different DHCP Client than the one that comes with the OS?
  • Bình Nguyễn
    Bình Nguyễn about 11 years
    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.
  • Napster_X
    Napster_X about 11 years
    Would be great if you can accept it as an answer. will help others who are looking for same thing :)
  • Freedom_Ben
    Freedom_Ben over 3 years
    Where does this code go? does it go in dhcpd.conf ?