Hostname and IP address during kickstart

Pete Nesbitt pete at linux1.ca
Thu Jul 15 02:53:40 UTC 2004


On July 14, 2004 09:30 am, Ryan Golhar wrote:
> I have a bunch of machines that I kickstart.  They all use DHCP to
> obtain their hostname and IP address.  The names are address are all
> static (in dhcpd.conf).
>
> Currently, in /etc/hosts on these machines, their hostname is set to
> 127.0.0.1 and this interferes with PVM.  I need to set their host name
> to their correct IP address in /etc/hosts.  What is the easiest way of
> doing this during %post in kickstart?
>
> Ryan


Hi Ryan,
Here is a little shell script that will overwrite the existing /etc/hosts file 
with the new IP/hostname (as well as 127...). I have tested it in a dummy 
file. It needs to be run as root.

If you have static entries, you need to add them into the script or you will 
lose them.


#!/bin/bash
# this ONLY WORKS IF there are no other entries in hosts!!
# it will overwrite anything in the hosts file!

HOSTS="/etc/hosts"
TEMP_HOSTS="/tmp/hosts.tmp"
NIC="eth0"
IP="`ifconfig $NIC | grep inet | cut -d : -f 2 | cut -d \  -f 1`"
FULL_NAME="`uname -n`"
SHORT_NAME="`uname -n|cut -d. -f1`"

echo "127.0.0.1 localhost.localdomain   localhost" > $TEMP_HOSTS
echo "$IP       $FULL_NAME      $SHORT_NAME" >> $TEMP_HOSTS
# add more static entries if needed like this:
#echo "xxx.xxx.xxx.xxx	somehost.domain.com	somehost" >> $TEMP_HOSTS

cat $TEMP_HOSTS > $HOSTS
#end

Hope that helps
-- 
Pete Nesbitt, rhce





More information about the redhat-list mailing list