Search

32.8. Kickstart Examples

download PDF

32.8.1. Set host name interactively during installation

The following example demonstrates how to interactively set the system's host name during installation. The %pre script asks to enter a host name for the installed system. The %post script configures the network according to the user's input.
%pre
chvt 3
exec </dev/tty3> /dev/tty3
clear
## Query for hostname, then write it to 'network' file
read -p "
What is my hostname (FQDN)? (This will be set on eth0)
" NAME /dev/tty3 2>&1
echo "NETWORKING=yes" > network
echo "HOSTNAME=${NAME}" >> network
echo "DEVICE=eth0" > ifcfg-eth0
echo "BOOTPROTO=dhcp" >> ifcfg-eth0
echo "ONBOOT=yes" >> ifcfg-eth0
echo "DHCP_HOSTNAME=${NAME} " >> ifcfg-eth0
cat ifcfg-eth0
chvt 1
exec < /dev/tty1 > /dev/tty1
%end

%post --nochroot
# bring in hostname collected from %pre, then source it
cp -Rvf network /mnt/sysimage/etc/sysconfig/network
# Set-up eth0 with hostname
cp ifcfg-eth0 /mnt/sysimage/etc/sysconfig/network-scripts/ifcfg-eth0
# force hostname change
/mnt/sysimage/bin/hostname $HOSTNAME
%end
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.