How to Set Hostname, Timezone, and Date on RHEL, CentOS, Rocky, Alma Linux
How to Set Hostname, Timezone, and Date on RHEL, CentOS, Rocky, Alma Linux (Step-by-Step Guide)
Introduction
Configuring your server’s hostname, timezone, and system date is an essential first step for Linux server administration. Whether you use RHEL, CentOS, Rocky Linux, or Alma Linux, these settings ensure logs are accurate and networking works as expected. This guide walks you through each configuration—fast and secure.
Prerequisites
- Root or sudo access
- Linux system (RHEL, CentOS, Rocky, or Alma Linux)
- Internet connection (for time sync)
Step 1: Set or Change Hostname
Check the current hostname:
hostnamectl
Set a new hostname (replace yourserver.example.com
):
sudo hostnamectl set-hostname yourserver.example.com
To make sure it’s set, re-run hostnamectl
or reboot.
Update /etc/hosts
for local resolution (recommended):
sudo nano /etc/hosts
# Add or edit this line:
127.0.0.1 yourserver.example.com yourserver localhost
Step 2: Set the Timezone
See available timezones:
timedatectl list-timezones | less
Set your preferred timezone (e.g. Europe/Stockholm
):
sudo timedatectl set-timezone Europe/Stockholm
Verify the change:
timedatectl status
Step 3: Set or Sync System Date and Time
To sync date and time with NTP servers:
sudo timedatectl set-ntp true
If you need to set manually (not recommended):
sudo date --set="2025-07-27 10:30:00"
Check the current date/time:
date
Step 4: (Optional) Install chrony
for Robust NTP Sync
sudo dnf install -y chrony
sudo systemctl enable --now chronyd
timedatectl status
Conclusion
Setting your hostname, timezone, and system date is foundational for Linux administration. These quick commands will ensure your server is ready for production and easy troubleshooting. For more guides, visit Holhol24!