Force Linux system to set dynamic hostname provided by DHCP server

DHCP is the Dynamic host configuration protocol server provides automatic or dynamic IP configuration on the client system. DHCP can also be configured to provide dynamic hostname service to client system which means all client systems will get a hostname along with an IP address from the DHCP server. Sometimes client system doesn’t set the dynamic hostname offered by the DHCP server. Refer to the solution section for more information.

Topic

  • How to froce Linux system to get assignment of hostname offered by DHCP server?
  • Set hostname on Linux system offered by a DHCP server.
  • How to set hostname on Linux system offered by a DHCP server?

apt

  • Linux

Solution


  • When dhclient script is executed on the client system, it runs all scripts present inside /etc/dhcp/dhclient-exit-hooks.d directory.

  • Here we’ll create a custom script that will take care of setting hostname offered by the DHCP server.

  • Create a file inside /etc/dhcp/dhclient-exit-hooks.d directory, for example /etc/dhcp/dhclient-exit-hooks.d/hostset.sh with the following content.

 $ cat /etc/dhcp/dhclient-exit-hooks.d/hostset.sh
    hostname $new_host_name

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

Note: Make sure DHCP server has been configured to provide Dynamic DNS with the help of a DNS server.

You May Also Like

avatar

About the Author: TekFik

TekFik is a technical blogging site helps techies and engineers to solve their day to day issues and also allows everyone to share knowledge and feedback. Please feel free to contact us at tekfik.rd@gmail.com if there is anything.

Leave a Reply

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