Setting hostname and dnsdomainname from DHCP lease info (wheezy)
Dear Gurus,
I have several desktop boxes running debian (new image with wheezy is
in the oven right now). I got those boxes networking configured via
DHCP, and the addresses are reserved by MAC address.
To get the hostname/IP/MAC info in a single place, I configured the
windows based DHCP server so that it also delivers DHCP option 12 -
hostname info. Then, I included the script below into
/etc/dhcp/dhclient-enter.d/
This arrangement appears do be working fine - my debian box (the
staging one) does gets its hostname and dnsdomainname from DHCP lease
at boot time.
Now, my questions:
1. Dou you gurus out there have any comments on this arrangement? Does
it look nice? Am I missing anything?
2. I would like to include exim4 configuration in my script (to avoid
the generic "From: xyz@localhost.localdomain in mail header, seen
below), but I have not started to do my homework on that. Any tips?
Best regards,
Joao
---------- Forwarded message ----------
From: Joao Carlos de Lima Roscoe <roscoe@localhost.localdomain>
Date: Thu, May 16, 2013 at 2:59 PM
Subject: Hostname/Domainname setter
To: joao.roscoe@gmail.com
#
# The purpose of this script is setting /etc/hostname and /etc/hosts
files according to new hostname from DHCP
# To enable this script set the following variable to "yes"
RUN="yes"
# Touch config files only if all needed data is available (keep old
files, otherwise)
if [[ -n "${new_host_name}" && -n "${new_domain_name}" && -n
"${new_ip_address}" ]]; then
if [ "$RUN" = "yes" ]; then
# Remove old hostname file, if any
if [ -s "/etc/hostname" ]; then
chmod 777 /etc/hostname
rm /etc/hostname
fi
# Create new hostname file
echo ${new_host_name} > /etc/hostname
# Remove old "hosts" file, if any
if [ -s "/etc/hosts" ]; then
chmod 777 /etc/hosts
rm /etc/hosts
fi
# Create new hosts file
echo "# Created by /etc/dhcp/dhclient-enter-hooks.d/hostname" > /etc/hosts
echo "127.0.0.1 localhost" >> /etc/hosts
echo ${new_ip_address}" "${new_host_name}"."${new_domain_name}"
"${new_host_name} >> /etc/hosts
echo "" >> /etc/hosts
echo "# The following lines are desirable for IPv6 capable hosts"
>> /etc/hosts
echo "::1 localhost ip6-localhost ip6-loopback" >> /etc/hosts
echo "ff02::1 ip6-allnodes" >> /etc/hosts
echo "ff02::2 ip6-allrouters" >> /etc/hosts
fi
fi
Reply to: