# [solved] let dhcpcd retrieve hostname from DHCP server ?

## anigel

Hi,

I am using dhcpcd-5.2.12, compiled with zeroconf support, on a fresh amd64 install. I'll have to deploy a tarball of this system on a high number of hosts, so I need network auto-configuration. And more particularly, I need the DHCP client on each host to set the hostname according to whats supplies the DHCP server. It has been working for months with my last install, but I cannot manage to get it working today...

Maybe someone can tell me where is the mistake...

/etc/hosts has not been modified. And here is my dhcpcd.conf

```
# A sample configuration for dhcpcd.

# See dhcpcd.conf(5) for details.

# Inform the DHCP server of our hostname for DDNS.

hostname

# To share the DHCP lease across OSX and Windows a ClientID is needed.

# Enabling this may get a different lease than the kernel DHCP client.

# Some upstream DHCP servers may also require a ClientID, such as FRITZ!Box.

#clientid

# A list of options to request from the DHCP server.

option domain_name_servers, domain_name, domain_search, host_name

option classless_static_routes

# Most distributions have NTP support.

option ntp_servers

# Respect the network MTU.

option interface_mtu

# A ServerID is required by RFC2131.

require dhcp_server_identifier

# A hook script is provided to lookup the hostname if not set by the DHCP

# server, but it should not be run by default.

nohook lookup-hostname

env force_hostname=YES
```

I tried several options, but when I ask for hostname, my build box always tells me "localhost". Strange, since IP configuration from DHCP server is perfect. How can I manage to force dhcpcd to set the hostname according to the DHCP server ?

Thanks,

----------

## depontius

I'll look at one of my home systems tonight, if you don't have an answer before then.  On my normal client machines I'm running centrally-administered "static IP" from my DHCP server.  I have the MACs of all of my systems in dhcpd.conf mapped to their hostnames.  My clients are set up as dhcp clients, and receive their hostnames from the server.  Because of the MAC<->hostname mapping, it all ends up looking static.

The one client that's up at home right now really does have a static IP, because it's my mythbackend server.  But tonight I can fire up another client, and check its configuration for you.

----------

## anigel

Hi,

 *depontius wrote:*   

> I'll look at one of my home systems tonight, if you don't have an answer before then.  On my normal client machines I'm running centrally-administered "static IP" from my DHCP server.  I have the MACs of all of my systems in dhcpd.conf mapped to their hostnames.  My clients are set up as dhcp clients, and receive their hostnames from the server.  Because of the MAC<->hostname mapping, it all ends up looking static.
> 
> The one client that's up at home right now really does have a static IP, because it's my mythbackend server.  But tonight I can fire up another client, and check its configuration for you.

 

Thanks, that's exactly my network configuration. I used this topoly for ages without problem. But I can't manage to get it working... Probably a small mistake, but I was not able to find what...

----------

## depontius

I'll take a look tonight.

----------

## depontius

Oops, now I don't know why my system is working.

/etc/conf.d/net:

```
# This blank configuration will automatically use DHCP for any net.*

# scripts in /etc/init.d.  To create a more complete configuration,

# please review /etc/conf.d/net.example and save your configuration

# in /etc/conf.d/net (this file :]!).

config_eth0=( "dhcp" )

dhcp_eth0="nodns"

dns_domain_lo="????????.???"

dns_servers_lo="127.0.0.1 ???.???.???.???"

dns_search_lo="????????.???"
```

/etc/dhcpcd.conf:

```
# A sample configuration for dhcpcd.

# See dhcpcd.conf(5) for details.

# Inform the DHCP server of our hostname for DDNS.

#hostname

# To share the DHCP lease across OSX and Windows a ClientID is needed.

# Enabling this may get a different lease than the kernel DHCP client.

# Some upstream DHCP servers may also require a ClientID, such as FRITZ!Box.

#clientid

# A list of options to request from the DHCP server.

#option domain_name_servers, domain_name, domain_search, host_name

#option host_name

option classless_static_routes

# Most distributions have NTP support.

option ntp_servers

# Respect the network MTU.

option interface_mtu

# A ServerID is required by RFC2131.

require dhcp_server_identifier

# A hook script is provided to lookup the hostname if not set by the DHCP

# server, but it should not be run by default.

nohook lookup-hostname

# dhcpcd ebuild requested no zeroconf

noipv4ll
```

/etc/dhcpcd.exit-hook:

```
#!/bin/sh

LOGGER="/usr/bin/logger -t dhcpcd.exit-hook"

new_short_name=`echo ${new_host_name} | /usr/bin/cut -d'.' -f 1`

${LOGGER} "reason           =${reason}"

${LOGGER} "skip_hooks       =${skip_hooks}"

${LOGGER} "interface        =${interface}"

${LOGGER} "state_dir        =${state_dir}"

${LOGGER} "new_ip_address   =${new_ip_address}"

${LOGGER} "old_host_name    =${old_host_name}"

${LOGGER} "new_host_name    =${new_host_name}"

${LOGGER} "old_fqdn_name    =${old_fqdn_name}"

${LOGGER} "new_fqdn_name    =${new_fqdn_name}"

${LOGGER} "new_short_name   =${new_short_name}"

if [ "x${if_up}" = "xtrue" ] ; then

  local_host_name=`/bin/hostname`

  if [ "x${local_host_name:0:5}" = "xlocal" ] ; then

    remote_host_name=`/usr/bin/host ${new_ip_address}`

    remote_short_name=`echo ${remote_host_name} | /usr/bin/cut -d'.' -f 1`

  fi

fi

${LOGGER} "local_host_name  =${local_host_name}"

${LOGGER} "remote_host_name =${remote_host_name}"

${LOGGER} "remote_short_name=${remote_short_name}"
```

That last one is just a little ditty I added for debug purposes, and never got around to removing.  It gives me a bit better view of what dhcpcd has just done, as it exits.

The place where I have a problem is in dhcpcd.conf, "nohook lookup-hostname".  With that in place, I don't know how I'm getting my hostname, but somehow I am.

I need to look at this more.  I hope this at least helps a little - it's only confusing me, now.

----------

## anigel

Hi,

I finally understood what was causing this behaviour.

You can have a look at this bug.

Thanks for your help  :Wink: 

----------

## depontius

I get "not found" on that link or for that bug number.  What package is it against, and do you know the title?

----------

