Static IP on Kickstart
Daniel Theisen
dtheisen at nexcess.net
Thu Jan 13 01:27:58 UTC 2011
Hello all,
I've been struggling with an issue with my kickstart configuration for a while now.
My current installation procedure:
1. Insert kickstart CD into server and boot
2. Select which kickstart to config from menu
3. Server grabs a DHCP address off a local LAN, gets install data off of a local mirror
4. Coffee while it installs
5. Server reboots
6. Log in and manually run network configuration script (written in %post section) to configure new static IP
What I would like to do is move step 6 to after step 4. I want to be able to run some kind of network installation at the very end of the install process, but before the first reboot.
Our current situation is this. We do server installs on a daily basis, when we kickstart a machine, we plug it into our office VLAN and boot it. It then grabs a DHCP address from our office router and proceeds with a network installation.
Setting a static IP at the beginning of the install is not an option, because we have many different VLAN's for each of our subnets. Some of the VLAN's are offsite and going to our othr site to install a server is not ideal.
Static DHCP is also not an option for multiple reasons. Firtly, we have over 1000 servers already configured with static IP addresses. Although there's no conflict issues, we'd just like to keep IP addresses purely static for consistancy reasons. Secondly, there's the previous VLAN issue. Finally, there's the issue that we have some servers with 20+ IP addresses.
Baasically, it'd just be very nice to be able to configure a static IP address on a server during the actual install process.
Here is my current kickstart script:
auth --useshadow --enablemd5
bootloader --location=mbr
zerombr
clearpart --all --initlabel
text
firewall --enabled --port=22:tcp
firstboot --disable
keyboard us
lang en_US
logging --level=info
url --url=http://mirror.nexcess.net/CentOS/5.5/os/x86_64/
reboot --eject
rootpw --iscrypted xx
selinux --enforcing
skipx
timezone --isUtc America/Detroit
install
part /boot --bytes-per-inode=4096 --fstype="ext3" --size=512 --ondisk=sda
part swap --bytes-per-inode=4096 --fstype="swap" --size=2048 --ondisk=sda
part / --bytes-per-inode=4096 --fstype="ext3" --grow --size=1 --ondisk=sda
part /backup --bytes-per-inode=4096 --fstype="ext3" --grow --size=1 --ondisk=sdb
network --bootproto=dhcp --device=eth0
%packages --nobase
@core
system-config-network-tui
%post
echo "nameserver 4.2.2.1" > /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
# write netconfig script
cat << EOF > /bin/netconfig
#!/bin/bash
# check if user is root
if [[ \$EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# run system-config-network-tui
/usr/sbin/system-config-network-tui
# set variables
eth0f="/etc/sysconfig/network-scripts/ifcfg-eth0"
eth1f="/etc/sysconfig/network-scripts/ifcfg-eth1"
netcfg="/etc/sysconfig/network"
# turn on eth1 if it has an address, remove gateway.. shouldn't be set here
# anyways
if [ -f "\$eth1f" ]; then
if grep -q "IPADDR" \$eth1f; then
sed -i 's/ONBOOT=no/ONBOOT=yes/' \$eth1f
sed -i '/^GATEWAY/d' \$eth1f
sed -i '/^HOTPLUG/d' \$eth1f
fi
fi
# move gateway from ifcfg-eth0 to /etc/sysconfig/network
if [ -f "\$eth0f" ]; then
e0gw=\$(grep "GATEWAY" \$eth0f)
sed -i '/^GATEWAY/d' \$eth0f
# check to see if the gateway is already set. if it is, delete it first
if ! grep -q "GATEWAY" /etc/sysconfig/network; then
echo \$e0gw >> \$netcfg
else
sed -i '/^GATEWAY/d' \$netcfg
echo \$e0gw >> \$netcfg
fi
fi
EOF
chmod +x /bin/netconfig
At the moment, I have a not-so-elegant script written to the server to be run manually after install. I began using system-config-network-tui vanilla, but realized it had some differences from the network configuration tool in anaconda (net.c?) I tried my best to correct those differences with my netconfig script. I've already tried running system-config-network-tui in the %post section, but it doesn't seem to work.
If anyone has had experience in dealing with a scenario such as this, any help would be greatly appreciated.
Thanks,
Daniel Theisen <dtheisen at nexcess.net>
More information about the Kickstart-list
mailing list