A DHCP server might be setup in such a way that it offers a hostname to its clients. By default, the Ubuntu hostname is set during installation and it disregards the one in the DHCP lease, but we can change this behaviour.

Create a file in the /etc/dhcp/dhclient-exit-hooks.d/ directory, for example /etc/dhcp/dhclient-exit-hooks.d/sethostname and give it the following content:

hostname $new_host_name

Now when the DHCP client gets a new lease, it will set the hostname to the one given to it by the DHCP server.

Setting Ubuntu hostname as offered by DHCP server
Tagged on:     

One thought on “Setting Ubuntu hostname as offered by DHCP server

  • 2019-01-16 at 20:02

    On Ubuntu18.04, this dhclient hook is not necessary anymore.

    The required modification is only on the following file:
    It shall contain “localhost”. Nothing more.
    Then, the name given by DHCP will be automatically set.


Leave a Reply

Your email address will not be published. Required fields are marked *