Set hostnames from dhcp-server with dhclient on *buntu systems

From Rsewiki
(Difference between revisions)
Jump to: navigation, search
(New page: To make *buntu based systems set the hostname supplied by the dhcp-server use the following script named hostname #!/bin/sh # Filename: /etc/dhcp/dhclient-exit-hooks.d/hostname # P...)
 
 
Line 1: Line 1:
To make *buntu based systems set the hostname supplied by the dhcp-server use the following script named hostname
+
To make *buntu based systems set the hostname supplied by the dhcp-server use the following script named <tt>hostname</tt>
  
 
  #!/bin/sh
 
  #!/bin/sh
Line 19: Line 19:
 
  echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname
 
  echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname
  
The script should be put in the folder /etc/dhcp/dhclient-exit-hooks.d
+
The script should be put in the folder <tt>/etc/dhcp/dhclient-exit-hooks.d</tt>

Latest revision as of 09:17, 20 July 2012

To make *buntu based systems set the hostname supplied by the dhcp-server use the following script named hostname

#!/bin/sh
# Filename:     /etc/dhcp/dhclient-exit-hooks.d/hostname
# Purpose:      Used by dhclient-script to set the hostname of the system
#               to match the DNS information for the host as provided by
#               DHCP.
#

if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
then
        return
fi

echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
hostname=$(host $new_ip_address | cut -d ' ' -f 5 | cut -d '.' -f 1)
echo $hostname > /etc/hostname
hostname $hostname
echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname

The script should be put in the folder /etc/dhcp/dhclient-exit-hooks.d

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox