Hostname, /etc/hosts, chrony (time)
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
hostnamectl set-hostname srv-web01.itnuvo.local— a permanent name (written to/etc/hostname).- Write your own name and important neighbours in
/etc/hosts:10.20.0.15 srv-web01.itnuvo.local srv-web01. - RHEL's time service is chronyd; its configuration is
/etc/chrony.conf:server ntp.itnuvo.local iburst. - Checking:
chronyc sources -v(^*— the selected source),chronyc tracking,timedatectl. timedatectl set-timezone Asia/Baku;timedatectl set-ntp trueturns synchronisation on.
Hostname
[ali@srv-web01 ~]$ hostnamectl Static hostname: srv-web01.itnuvo.local Icon name: computer-vm Chassis: vm Machine ID: 4b1c0e2a9d7f4e3c8a6b5d2e1f0a9c8b Boot ID: 9c8b7a6f5e4d3c2b1a0f9e8d7c6b5a4f Virtualization: kvm Operating System: Red Hat Enterprise Linux 9.4 (Plow) Kernel: Linux 5.14.0-427.13.1.el9_4.x86_64 Architecture: x86-64 [ali@srv-web01 ~]$ sudo hostnamectl set-hostname srv-web01.itnuvo.local [ali@srv-web01 ~]$ cat /etc/hostname srv-web01.itnuvo.local
hostnamectl set-hostname takes effect immediately and is written to /etc/hostname — no reboot needed. The prompt shows the new name in a new session. In the simulator, the ITNuvo badge stays next to the name.
A change with the hostname command (hostname new-name) is temporary — in RHCSA always use hostnamectl.
/etc/hosts
[ali@srv-web01 ~]$ cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.20.0.15 srv-web01.itnuvo.local srv-web01 10.20.0.20 srv-db01.itnuvo.local srv-db01 10.20.0.50 client01.itnuvo.local client01 [ali@srv-web01 ~]$ getent hosts srv-db01 10.20.0.20 srv-db01.itnuvo.local srv-db01
Format: IP full_name short_name. Write the full name first, then the alias — hostname -f takes the full name from here. Useful so important servers can find each other until DNS is set up, or when DNS fails.
chrony: time synchronisation
On RHEL the NTP client and server is chronyd (the old ntpd is gone):
[ali@srv-web01 ~]$ timedatectl Local time: Tue 2026-12-01 15:42:10 +04 Universal time: Tue 2026-12-01 11:42:10 UTC RTC time: Tue 2026-12-01 11:42:10 Time zone: Asia/Baku (+04, +0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [ali@srv-web01 ~]$ grep -E "^(server|pool)" /etc/chrony.conf pool 2.rhel.pool.ntp.org iburst
In a company, servers usually connect to an internal NTP server rather than the internet pool. The RHCSA task: "the server must get its time from ntp.itnuvo.local":
[ali@srv-web01 ~]$ sudo sed -i 's/^pool /#pool /' /etc/chrony.conf [ali@srv-web01 ~]$ echo "server ntp.itnuvo.local iburst" | sudo tee -a /etc/chrony.conf [ali@srv-web01 ~]$ sudo systemctl restart chronyd [ali@srv-web01 ~]$ chronyc sources -v .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current best, '+' = combined, '-' = not combined, | / 'x' = may be in error, '~' = too variable, '?' = unusable. || .- xxxx [ yyyy ] +/- zzzz || Reachability register (octal) -. | xxxx = adjusted offset, || Log2(Polling interval) --. | | yyyy = measured offset, || \ | | zzzz = estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* ntp.itnuvo.local 2 6 17 12 -214us[ -310us] +/- 18ms
| Column | Meaning |
|---|---|
^* | A server, the currently selected source — synchronisation works |
^? | Unreachable — a DNS, firewall or server problem |
Stratum | The source's "depth": 1 — a server tied to an atomic clock |
Reach | Success of the last 8 queries (octal); 377 — all succeeded |
Last sample | The offset and error |
[ali@srv-web01 ~]$ chronyc tracking | grep -E "Reference ID|System time|Leap status" Reference ID : 0A14000A (ntp.itnuvo.local) System time : 0.000214 seconds slow of NTP time Leap status : Normal
iburst — send several queries quickly at the start so synchronisation is fast.
Making chrony an NTP server
One server can be the NTP server for the internal network:
[ali@srv-web01 ~]$ echo "allow 10.20.0.0/24" | sudo tee -a /etc/chrony.conf [ali@srv-web01 ~]$ sudo systemctl restart chronyd [ali@srv-web01 ~]$ sudo firewall-cmd --permanent --add-service=ntp && sudo firewall-cmd --reload
Without allow, chronyd is only a client.
Time zone
[ali@srv-web01 ~]$ timedatectl list-timezones | grep -i baku Asia/Baku [ali@srv-web01 ~]$ sudo timedatectl set-timezone Asia/Baku [ali@srv-web01 ~]$ sudo timedatectl set-ntp true
Some servers run in UTC (so logs are easy to compare) — that depends on company policy. What matters is that they are all in sync.
Lab: name and time
In the Red Hat simulator and on your own VM:
- Set
srv-web01's full name tosrv-web01.itnuvo.localand check withhostnamectl. - Write the three machines' lines in
/etc/hostsand check withgetent hosts srv-db01.
[ali@srv-web01 ~]$ sudo hostnamectl set-hostname srv-web01.itnuvo.local [ali@srv-web01 ~]$ hostnamectl | head -n 1 [ali@srv-web01 ~]$ getent hosts srv-db01
- (On your own VM) comment out the pool in
/etc/chrony.conf, addserver ntp.itnuvo.local iburst(or your company's NTP), runsystemctl restart chronydand see^*inchronyc sources. - Set the time zone to
Asia/Baku.
Check: hostname → srv-web01.itnuvo.local; ^* in chronyc sources; timedatectl → synchronized: yes.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1Which command changes the hostname permanently?
2Which service synchronises time on RHEL?
3What does ^* mean in chronyc sources?
4What does chronyd need to serve time to other servers?
5What is the right order of names in an /etc/hosts line?
Comments
Sign in to comment.