RHCSA Rapid Track
Course update
An updated version of this course is available that uses a newer version of Red Hat Enterprise Linux in the lab environment. Therefore, the RHEL 9.0 version of the lab environment will retire on December 31, 2024. Please complete any work in this lab environment before it is removed on December 31, 2024. For the most up-to-date version of this course, we recommend moving to the RHEL 9.3 version.
In this exercise, you manually configure the system's static hostname, the /etc/hosts file, and the DNS name resolver.
Outcomes
Set a customized hostname.
Configure name resolution settings.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that all required resources are available.
[student@workstation ~]$ lab start net-hostnames
Instructions
Log in to
serveraas thestudentuser and switch torootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@testa ~]$sudo -i[sudo] password for student:student[root@testa ~]#View the current hostname settings.
Display the current hostname.
[root@testa ~]#
hostnametestaDisplay the hostname status. The persistent, locally configured hostname is displayed in the
Static hostnamefield. The current runtime hostname, which is obtained from DHCP or DNS network services, is displayed in theTransient hostnamefield.[root@testa ~]#
hostnamectl statusStatic hostname:servera.lab.example.comTransient hostname:testaIcon name: computer-vm Chassis: vm 🖴 Machine ID: ace63d6701c2489ab9c0960c0f1afe1d Boot ID: 03bf1d5518bd43b4a25cfe9a18d5a46a Virtualization: kvm Operating System: Red Hat Enterprise Linux 9.0 (Plow) CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos Kernel: Linux 5.14.0-70.13.1.el9_0.x86_64 Architecture: x86-64 Hardware Vendor: Red Hat Hardware Model: OpenStack Compute
Set a static hostname to match the current static hostname.
Change the hostname and the hostname configuration file.
[root@testa ~]#
hostnamectl hostname \servera.lab.example.comView the content of the
/etc/hostnamefile, which provides the hostname at network start.[root@testa ~]#
cat /etc/hostnameservera.lab.example.comLog out and log in to
serveraas thestudentuser. Switch to therootuser to change the command prompt to show the updated hostname.[root@testa ~]#
exitlogout [student@testa ~]$exitlogout Connection to servera closed. [student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Display the hostname status. The transient hostname is not shown, now that a static hostname is configured.
[root@servera ~]#
hostnamectl statusStatic hostname: servera.lab.example.com Icon name: computer-vm Chassis: vm Machine ID: 63b272eae8d5443ca7aaa5593479b25f Boot ID: ef299e0e957041ee81d0617fc98ce5ef Virtualization: kvm Operating System: Red Hat Enterprise Linux 9.0 (Plow) CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos Kernel: Linux 5.14.0-70.el9.x86_64 Architecture: x86-64 Hardware Vendor: Red Hat Hardware Model: OpenStack Compute
Temporarily change the hostname to
testname.Change the hostname.
[root@servera ~]#
hostname testnameDisplay the current hostname.
[root@servera ~]#
hostnametestnameView the content of the
/etc/hostnamefile, which provides the hostname at network start.[root@servera ~]#
cat /etc/hostnameservera.lab.example.comReboot the system.
[root@servera ~]#
systemctl rebootConnection to servera closed by remote host. Connection to servera closed. [student@workstation ~]$Log in to
serveraas thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Display the current hostname.
[root@servera ~]#
hostnameservera.lab.example.com
Add
classas a local nickname for the classroom server, and ensure that you can ping the server with that nickname.Look up the IP address of the
classroom.example.comserver.[root@servera ~]#
host classroom.example.comclassroom.example.com has address 172.25.254.254Update the
/etc/hostsfile to add theclassserver to access the172.25.254.254IP address. The following example shows the expected content of the/etc/hostsfile.[root@servera ~]#
vim /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.25.254.254 classroom.example.com classroom classLook up the IP address of the
classserver.[root@servera ~]#
host classHost class not found: 3(NXDOMAIN) [root@servera ~]#getent hosts class172.25.254.254 classroom.example.com classroom classUse the
pingcommand to send packets to theclassserver.[root@servera ~]#
ping -c3 classPING classroom.example.com (172.25.254.254) 56(84) bytes of data. 64 bytes from classroom.example.com (172.25.254.254): icmp_seq=1 ttl=63 time=1.21 ms 64 bytes from classroom.example.com (172.25.254.254): icmp_seq=2 ttl=63 time=0.688 ms 64 bytes from classroom.example.com (172.25.254.254): icmp_seq=3 ttl=63 time=0.559 ms --- classroom.example.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2046ms rtt min/avg/max/mdev = 0.559/0.820/1.214/0.283 msReturn to the
workstationsystem as thestudentuser.[root@servera ~]#
exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
This concludes the section.