# How to set Hostname & Dnsdomain via DHCP?

## trawi

My company is using dhcpd with "deny unknown clients" address pools (every computer name and mac address has to be registered in DHCP before it gets a lease).

Most Linux Distribution use this information to set the hostname automatically via DHCP. This is a nice feature, because it allows you to easily duplication of a Linux Configuration (Just duplicate the disk or VmWare image and set a new hostname via DHCP).

How can this be done in Gentoo?

[/b]

----------

## UberLord

Do you mean settings the local box's hostname by DHCP or informing the DHCP server of the local box's hostname?

----------

## trawi

It always nice to find a solution faster than writing your problem report   :Very Happy: 

The solution is to add the following lines to /etc/conf.d/net:

iface_eth1="dhcp"

dhcpcd_eth0="-HD"

-H tells dhcpcd to set your hostname -D sets your domainname.

Sometimes you have smart ideas like: Probably I should read the man pages   :Rolling Eyes: 

----------

## UberLord

 *trawi wrote:*   

> Sometimes you have smart ideas like: Probably I should read the man pages  

 

RTFM   :Laughing:   :Twisted Evil:   :Rolling Eyes: 

----------

## trawi

Reading one manual is easy   :Smile: 

Problems start when you have more than 10   :Crying or Very sad: 

To tune your DHCP Configuration you have to read both the dhcpcd man page AND the Gentoo Installation Handbook.

That would be easy if one of them would reference to the other. If you are a newbee it takes some time till you match /etc/conf.d/net and dhcpcd   :Wink: 

----------

## Luud

Great, searching through the forums does work   :Laughing:  .

I have setup a (caching) DNS for my local lan and a DHCP server.

What I want is to give each machine a unique IP address based on its ethernet MAC address. Based on this address the machine should get a unique hostname. Machines that are not known in the MAC address list will get a unique IP and corresponding hostname from a specified pool.

I use the periodic system of elements to name my machines where each IP number corresponds with the element number. E.g Vanadium should get 192.168.1.23.

Now I see here how to setup the Linux dhcp client to work with this, i.e. how to get both the IP address and the corresponding hostname and domain name. I will try this at home in a few days.

Question 1: Do I need to add specific options to the dhcp server configuration file in order to let the dhcp client determine the correct hostname, or will the client use a DNS lookup to find this information?

Question 2: Does anybody here know how to make Windows XP (ohhh the shame   :Embarassed:  ) clients to behave the same as the linux ones? As I sometimes need to go back to windows and others in my network use windows (yeah, not everybody uses linux yet   :Rolling Eyes:   :Wink:  ). DHCP works, but I think I still have to set the machine's hostname by hand.

Thanks

----------

## trawi

Hey, looks like Reply Notification does work too   :Very Happy: 

Problem with setting hostnames via DHCP is that Linux and Windows behave totally different:

Windows:

It simply doesn't work. The computer name is used for domain authentication and you aren't allowed to change it (without loosing your computer domain account).

Linux:

Does work fine. Dhcpd uses either the dns name (for unknown client) or the defined host name  (for known client).

If you use dhcpd only for handing out leases you shouldn't have any problem. But if you want to use dyndns for dynamic dns updating your running into problems. Because for Windows you have to use the computer name of the machine, for Linux you have to provide that name.

I will post an example dhcp.conf later today. (I first have to do a bit of declassifing and MAC & IP Address scrambling so I won't post any security related information of my company).

----------

## Luud

Well, I got this working now, but there is one problem.

The hostname becomes something like

```
vanadium.mendelejev.net
```

Which results in a welcome message

```
This is vanadium.mendelejev.net.mendelejev.net (Linux i686 2.4.25-gentoo) 22:45:04

vanadium.mendelejev.net login:
```

This is obviously not correct. But I do not know where the problem comes from. Is it the dhcp client setup, or is it something in the DNS? The latter doesn't seem likely as the DNS works fine for normal lookups (but then it does give the fully qualified domain names in reverse lookups...)

Anyone that knows the solution?

Thanks

----------

## Luud

Hi, 

Found the solution myself.

I needed to set the following option:

```
use-host-decl-names on;
```

Now it is all fine.

Next I'm thinking of using the ddns option to automatically sync host names with IP address in named.

Cheers.

----------

