isc-dhcpd server, HOSTNAME

Matthew Seaman m.seaman at
Sun May 10 07:55:45 UTC 2009

Pieter Donche wrote:
> FreeBSD7 with isc-dhcp30-server.
> It hands out an IP address, OK,
> but the BASH environment variable HOSTNAME is not set. Why?
> (A DNS server is active on the network and can succesfully be queried 
> from a FreeBSD bash command (nslookup or host) to see the hostname 
> associated with the IP-address)

Hostname is not one of the parameters usually requested from a DHCP server
by a Unix machine.  In fact, it's normally the other way round: the client
tells the DHCP server what it's hostname is and the DHCP server can then
inject an A record into the DNS dynamically.

However it is possible to operate in the way you want.  To tell the dhcp
server to look up names from the DNS based on the address supplied to a
host, search for the description of the 'get-lease-hostnames' flag in
the dhcpd.conf(5) man page.

To tell dhcp clients to fetch their hostname from DHCP, you need to add it
to a 'request' or 'require' block in dhclient.conf -- see dhclient.conf(5).

It's been a long time since I ran a setup anything like that, so I cannot
recall if that was all that was required, or if it was also necessary to
write a small dhclient-script(8) to actually set the hostname. 

Another alternative is to use a dhclient-script to take the IP number
allocated by the DHCP server, look up the corresponding address and then
set that as the hostname.

The bash HOSTNAME environment variable will be set from the output of the
hostname(1) command, which is usually set from the hostname variable in
/etc/rc.conf or from the output of '/bin/kenv' if that 
is set. Otherwise it uses a default hostname of 'amnesiac'. 



Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP:     Ramsgate
                                                  Kent, CT11 9PW

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
Url :

More information about the freebsd-questions mailing list