Set a hostname in image mode for RHEL
You can set a custom hostname for your image mode for RHEL system by modifying the /etc/hostname file. Setting a hostname identifies the system on the network and simplifies management in multi-host environments.
Before you begin
- You have a base
bootccontainer image to extend, for example,registry.redhat.io/rhel10/rhel-bootc:latest. - The
container-toolsmeta-package is installed if you are building or running containers locally.
Procedure
- At build time in a
Containerfile -
- Add the following instruction to your
Containerfileto embed the hostname in the image:FROM registry.redhat.io/rhel10/rhel-bootc:latest RUN echo "<hostname>" > /etc/hostnameReplace
myhostnamewith the required hostname for the system.
- Add the following instruction to your
- By using Anaconda with a Kickstart file
-
- Add the following directive to your Kickstart file to set the hostname during installation:
network --hostname=<hostname>Replace
myhostnamewith the required hostname for the system.
- Add the following directive to your Kickstart file to set the hostname during installation:
- At runtime with a privileged container or on the booted system
-
- On the running system, write the required hostname to the
/etc/hostnamefile:# echo "<hostname>" > /etc/hostnameReplace
myhostnamewith the required hostname for the system.Note Because
/etcis persistent and mutable by default in image mode for RHEL, changes to/etc/hostnameon a running system persist across reboots. However, if/etcis configured as transient, the hostname reverts on reboot.
- On the running system, write the required hostname to the
Results
- Change the hostname:
# hostnamectl set-hostname <hostname> - Reboot the system:
# reboot - Verify the hostname by running the following command:
$ hostnamectlThe output displays the configured hostname under
Static hostname.