How do I make hostname -f return the FQDN for a dynamic IP address (on the non-bootable network interface)?
This comes in useful for some SGE configurations.
The following code should be added to /etc/dhcp/dhclient-enter-hooks (the exact path of the hook script may be different):
if [[ $interface == $INTERFACE_NAME ]]; then
grep $HOSTNAME.$DOMAIN /etc/hosts
if [ $? -eq 1 ]; then
echo $new_ip_address $HOSTNAME.$DOMAIN $HOSTNAME >> /etc/hosts
sed -i s/.*$HOSTNAME.$DOMAIN.*/$new_ip_address\ $HOSTNAME.$DOMAIN\ $HOSTNAME/g /etc/hosts
Now, each time the dynamic IP is bound to $INTERFACE_NAME, the line in /etc/hosts that has this form:
<IP> <HOSTNAME>.<DOMAIN> <HOSTNAME>
will be added if it doesn't exist, or replaced if it does exist.
The result of this is that hostname -f will now return the FQDN...