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 servera as the student user and switch to root user.
[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 ~]# hostname
testaDisplay the hostname status.
The persistent, locally configured hostname is displayed in the Static hostname field.
The current runtime hostname, which is obtained from DHCP or DNS network services, is displayed in the Transient hostname field.
[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.com
View the content of the /etc/hostname file, which provides the hostname at network start.
[root@testa ~]# cat /etc/hostname
servera.lab.example.comLog out and log in to servera as the student user.
Switch to the root user 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 status
Static 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 ComputeTemporarily change the hostname to testname.
Change the hostname.
[root@servera ~]# hostname testnameDisplay the current hostname.
[root@servera ~]# hostname
testnameView the content of the /etc/hostname file, which provides the hostname at network start.
[root@servera ~]# cat /etc/hostname
servera.lab.example.comReboot the system.
[root@servera ~]# systemctl reboot
Connection to servera closed by remote host.
Connection to servera closed.
[student@workstation ~]$Log in to servera as the student user and switch to the root user.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Display the current hostname.
[root@servera ~]# hostname
servera.lab.example.comAdd class as 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.com server.
[root@servera ~]# host classroom.example.com
classroom.example.com has address 172.25.254.254Update the /etc/hosts file to add the class server to access the 172.25.254.254 IP address.
The following example shows the expected content of the /etc/hosts file.
[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 class
Look up the IP address of the class server.
[root@servera ~]#host classHost class not found: 3(NXDOMAIN) [root@servera ~]#getent hosts class172.25.254.254 classroom.example.com classroom class
Use the ping command to send packets to the class server.
[root@servera ~]# ping -c3 class
PING 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 workstation system as the student user.
[root@servera ~]#exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
This concludes the section.