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.
- 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?
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.