Introduction and Concepts
Why is Timezone Important?
Correct timezone configuration is essential for:
- System logs and traceability
- Scheduled tasks (cron jobs)
- SSL/TLS certificates
- Database synchronization
- Automated backups
┌─────────────────────────────────────────────────────────────────────────────┐
│ IMPORTANCE OF TIMEZONE │
└─────────────────────────────────────────────────────────────────────────────┘
LINUX SERVER
│
┌─────────────────────┼─────────────────────┐
│ │ │
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│ LOGS │ │ CRON │ │ SSL │
│ │ │ JOBS │ │ CERTS │
│ Accurate │ │ Execution │ │ Validity │
│ timestamps│ │ on time │ │ correct │
└───────────┘ └───────────┘ └───────────┘
│ │ │
└─────────────────────┼─────────────────────┘
│
▼
┌─────────────────┐
│ CORRECT │
│ TIMEZONE │
│ │
│ = Reliable │
│ system │
└─────────────────┘
Understanding UTC and Timezones
┌─────────────────────────────────────────────────────────────────────────────┐
│ WORLD TIMEZONE MAP │
└─────────────────────────────────────────────────────────────────────────────┘
-12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 UTC +1 +2 +3
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
═══════════════════════════════════════════════════════════════════════════
│
Los │ New │ London Paris
Angeles │ York │ │ │
│ │ │ │ │ │
UTC-8 UTC-7 UTC-5 UTC-3 UTC+0 UTC+1
│
═══════════════════════════════════════════════════════════════════════════
┌─────────────────────────┐
│ UTC │
│ (Coordinated │
│ Universal Time) │
│ │
│ = World reference │
│ = No daylight saving │
└─────────────────────────┘
Time Offset Example
┌─────────────────────────────────────────────────────────────────────────────┐
│ EXAMPLE: 12:00 UTC │
└─────────────────────────────────────────────────────────────────────────────┘
UTC (London) 12:00
│
┌───────────────┼───────────────┬───────────────┬───────────────┐
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐
│ Los │ │ New │ │ Paris │ │ Moscow │ │ Tokyo │
│ Angeles│ │ York │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ 04:00 │ │ 07:00 │ │ 13:00 │ │ 15:00 │ │ 21:00 │
│ (UTC-8)│ │ (UTC-5)│ │ (UTC+1)│ │ (UTC+3)│ │ (UTC+9)│
└────────┘ └────────┘ └────────┘ └────────┘ └────────┘
Time Architecture in Linux
The Two System Clocks
┌─────────────────────────────────────────────────────────────────────────────┐
│ LINUX CLOCK ARCHITECTURE │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ HARDWARE │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ RTC CLOCK (Real Time Clock) │ │
│ │ │ │
│ │ • Powered by CMOS battery │ │
│ │ • Runs even when PC is off │ │
│ │ • Can be in UTC or local time │ │
│ │ • Command: hwclock │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
│ At boot
│ (synchronization)
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ SOFTWARE │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ SYSTEM CLOCK │ │
│ │ │ │
│ │ • Managed by Linux kernel │ │
│ │ • Counts seconds since January 1, 1970 (Unix Epoch) │ │
│ │ • Always stored in UTC internally │ │
│ │ • Commands: timedatectl, date │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
│ Network synchronization (NTP)
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ NETWORK │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ NTP SERVERS │ │
│ │ │ │
│ │ • pool.ntp.org (worldwide pool) │ │
│ │ • us.pool.ntp.org (US pool) │ │
│ │ • Accuracy: few milliseconds │ │
│ │ • Service: systemd-timesyncd or chrony │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
Configuration Files
┌─────────────────────────────────────────────────────────────────────────────┐
│ TIME SYSTEM FILES │
└─────────────────────────────────────────────────────────────────────────────┘
/etc/
├── localtime ← Symbolic link to current timezone
│ └── → /usr/share/zoneinfo/America/New_York
│
├── timezone ← Timezone name (text file)
│ └── Contents: "America/New_York"
│
└── systemd/
└── timesyncd.conf ← NTP configuration
/usr/share/zoneinfo/ ← Timezone database
├── Africa/
│ └── ...
├── America/
│ ├── New_York ← US Eastern timezone
│ ├── Los_Angeles ← US Pacific timezone
│ └── ...
├── Europe/
│ ├── London
│ └── ...
└── UTC ← Universal time
Prerequisites
┌─────────────────────────────────────────────────────────────────┐
│ PREREQUISITES │
├─────────────────────┬───────────────────────────────────────────┤
│ Element │ Required │
├─────────────────────┼───────────────────────────────────────────┤
│ System │ Ubuntu 18.04+ / Debian 9+ / CentOS 7+ │
│ Access │ root or sudo │
│ Package │ systemd (included by default) │
│ Network │ Internet connection (for NTP) │
└─────────────────────┴───────────────────────────────────────────┘
Check Current Configuration
timedatectl Command
# Display all time information
timedatectl
┌─────────────────────────────────────────────────────────────────────────────┐
│ timedatectl OUTPUT │
└─────────────────────────────────────────────────────────────────────────────┘
$ timedatectl
Local time: Sat 2025-01-25 09:30:45 EST
Universal time: Sat 2025-01-25 14:30:45 UTC
RTC time: Sat 2025-01-25 14:30:45
Time zone: America/New_York (EST, -0500)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
┌─────────────────────────────────────────────────────────────────────────────┐
│ EXPLANATION: │
│ │
│ Local time → Local time (according to your timezone) │
│ Universal time → UTC time (world reference) │
│ RTC time → Hardware clock time │
│ Time zone → Configured timezone │
│ System clock synchronized → NTP synchronization active │
│ NTP service → Synchronization service status │
│ RTC in local TZ → Is RTC clock in local time? │
└─────────────────────────────────────────────────────────────────────────────┘
Other Verification Methods
# Display current date and time
date
# Display only timezone
timedatectl show --property=Timezone
# View /etc/localtime symbolic link
ls -la /etc/localtime
# Read /etc/timezone file (Debian/Ubuntu)
cat /etc/timezone
Change Timezone
Method 1: With timedatectl (Recommended)
┌─────────────────────────────────────────────────────────────────────────────┐
│ TIMEZONE CHANGE PROCESS │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ List │ │ Choose │ │ Apply │ │ Verify │
│ available │────▶│ timezone │────▶│ config │────▶│ result │
│ timezones │ │ │ │ │ │ │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
│ │ │ │
▼ ▼ ▼ ▼
list-timezones grep/filter set-timezone timedatectl
Step 1: List Available Timezones
# List all timezones
timedatectl list-timezones
# Filter by region (America)
timedatectl list-timezones | grep America
# Filter by city (New York)
timedatectl list-timezones | grep New_York
┌─────────────────────────────────────────────────────────────────────────────┐
│ COMMON TIMEZONES │
└─────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────┬────────────┬─────────────────────────────────────┐
│ Timezone │ Offset │ Cities / Countries │
├──────────────────────────┼────────────┼─────────────────────────────────────┤
│ America/New_York │ UTC-5/-4 │ New York, Miami, Washington DC │
│ America/Chicago │ UTC-6/-5 │ Chicago, Houston, Dallas │
│ America/Denver │ UTC-7/-6 │ Denver, Phoenix, Salt Lake City │
│ America/Los_Angeles │ UTC-8/-7 │ Los Angeles, San Francisco, Seattle │
│ America/Toronto │ UTC-5/-4 │ Canada (Toronto, Ottawa) │
├──────────────────────────┼────────────┼─────────────────────────────────────┤
│ Europe/London │ UTC+0/+1 │ United Kingdom, Portugal │
│ Europe/Paris │ UTC+1/+2 │ France, Belgium, Netherlands │
├──────────────────────────┼────────────┼─────────────────────────────────────┤
│ Asia/Tokyo │ UTC+9 │ Japan │
│ Asia/Shanghai │ UTC+8 │ China │
├──────────────────────────┼────────────┼─────────────────────────────────────┤
│ UTC │ UTC+0 │ Universal Time (servers) │
└──────────────────────────┴────────────┴─────────────────────────────────────┘
Step 2: Set the Timezone
# Set timezone to New York (US Eastern)
sudo timedatectl set-timezone America/New_York
# Other examples
sudo timedatectl set-timezone America/Los_Angeles
sudo timedatectl set-timezone Europe/London
sudo timedatectl set-timezone UTC
Step 3: Verify the Change
# Verify new configuration
timedatectl
# Display date with new timezone
date
Method 2: With dpkg-reconfigure (Debian/Ubuntu)
# Interactive interface
sudo dpkg-reconfigure tzdata
Method 3: Manual Symbolic Link
# Remove current link
sudo rm /etc/localtime
# Create new link to desired timezone
sudo ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
# Update /etc/timezone (Debian/Ubuntu)
echo "America/New_York" | sudo tee /etc/timezone
NTP Synchronization
NTP Synchronization Diagram
┌─────────────────────────────────────────────────────────────────────────────┐
│ NTP SYNCHRONIZATION │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────┐
│ NTP SERVERS STRATUM 0 │
│ (Atomic clocks) │
└──────────────┬──────────────┘
│
▼
┌─────────────────────────────┐
│ NTP SERVERS STRATUM 1 │
└──────────────┬──────────────┘
│
┌────────────────────┼────────────────────┐
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ pool.ntp.org │ │us.pool.ntp.org │ │ time.google.com │
│ (Worldwide) │ │ (US Pool) │ │ (Google) │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │
└────────────────────┼────────────────────┘
│
│ UDP Port 123
▼
┌─────────────────────────────┐
│ YOUR SERVER │
│ systemd-timesyncd │
└─────────────────────────────┘
Enable/Disable NTP Synchronization
# Check NTP status
timedatectl show | grep NTP
# Enable NTP synchronization
sudo timedatectl set-ntp true
# Disable NTP synchronization
sudo timedatectl set-ntp false
Configure NTP Servers
# Edit configuration
sudo nano /etc/systemd/timesyncd.conf
[Time]
NTP=0.us.pool.ntp.org 1.us.pool.ntp.org 2.us.pool.ntp.org
FallbackNTP=0.pool.ntp.org 1.pool.ntp.org
# Restart service
sudo systemctl restart systemd-timesyncd
Manual Configuration
┌─────────────────────────────────────────────────────────────────────────────┐
│ ⚠️ WARNING │
│ │
│ Manual modification requires DISABLING NTP first! │
└─────────────────────────────────────────────────────────────────────────────┘
# Step 1: Disable NTP
sudo timedatectl set-ntp false
# Step 2: Change time
sudo timedatectl set-time "15:30:00"
# Step 3: Change date
sudo timedatectl set-time "2025-01-25"
# Step 4: Change date AND time
sudo timedatectl set-time "2025-01-25 15:30:00"
# Step 5: Re-enable NTP (recommended)
sudo timedatectl set-ntp true
Hardware Clock (RTC)
System Clock vs RTC Clock Diagram
┌─────────────────────────────────────────────────────────────────────────────┐
│ SYSTEM CLOCK vs RTC CLOCK │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────┐ ┌─────────────────────────────┐
│ SYSTEM CLOCK │ │ RTC CLOCK │
│ │ │ (Real Time Clock) │
├─────────────────────────────┤ ├─────────────────────────────┤
│ │ │ │
│ • Managed by kernel │ │ • Chip on motherboard │
│ • Volatile RAM │ │ • Powered by CMOS battery │
│ • Lost at shutdown │ │ • Persists when PC off │
│ • Synchronized via NTP │ │ • Drifts over time │
│ │ │ │
│ Command: date │ │ Command: hwclock │
│ timedatectl │ │ │
└─────────────┬───────────────┘ └─────────────┬───────────────┘
│ │
│ SYNCHRONIZATION │
│◀────────────────────────────────────▶│
│ │
│ hwclock --systohc (System → RTC) │
│ hwclock --hctosys (RTC → System) │
hwclock Commands
# Display hardware clock time
sudo hwclock --show
# Sync system clock to RTC
sudo hwclock --systohc
# Set RTC to UTC (recommended)
sudo hwclock --systohc --utc
Practical Examples
Case 1: US East Coast Server
sudo timedatectl set-timezone America/New_York
sudo timedatectl set-ntp true
timedatectl
Case 2: Multi-Regional Server in UTC
┌─────────────────────────────────────────────────────────────────────────────┐
│ MULTI-REGIONAL SERVER │
└─────────────────────────────────────────────────────────────────────────────┘
CENTRAL SERVER
(Timezone: UTC)
│
┌─────────────────────┼─────────────────────┐
│ │ │
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│ Client │ │ Client │ │ Client │
│ New York │ │ London │ │ Tokyo │
│ (UTC-5) │ │ (UTC+0) │ │ (UTC+9) │
└───────────┘ └───────────┘ └───────────┘
Advantage: All logs are in UTC
→ Easy comparison across regions
sudo timedatectl set-timezone UTC
sudo timedatectl set-ntp true
Troubleshooting
Decision Tree
┌─────────────────────────────────────────────────────────────────────────────┐
│ TROUBLESHOOTING DECISION TREE │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────┐
│ Time is incorrect │
└────────────┬────────────┘
│
┌──────────────────┴──────────────────┐
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Wrong timezone? │ │ Time offset by │
│ │ │ X hours? │
└────────┬────────┘ └────────┬────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ timedatectl │ │ timedatectl │
│ set-timezone │ │ set-ntp true │
└─────────────────┘ └─────────────────┘
Diagnostic Commands
# Check complete configuration
timedatectl
# Check timesyncd service
systemctl status systemd-timesyncd
# View timesyncd logs
journalctl -u systemd-timesyncd
# Force synchronization
sudo systemctl restart systemd-timesyncd
Command Reference
┌─────────────────────────────────────────────────────────────────────────────┐
│ COMMAND CHEAT SHEET │
└─────────────────────────────────────────────────────────────────────────────┘
┌───────────────────────────────────────┬─────────────────────────────────────┐
│ Command │ Description │
├───────────────────────────────────────┼─────────────────────────────────────┤
│ timedatectl │ Display current configuration │
│ timedatectl list-timezones │ List available timezones │
│ timedatectl list-timezones | grep X │ Filter timezones │
├───────────────────────────────────────┼─────────────────────────────────────┤
│ sudo timedatectl set-timezone X │ Set timezone │
│ sudo timedatectl set-ntp true │ Enable NTP synchronization │
│ sudo timedatectl set-ntp false │ Disable NTP │
├───────────────────────────────────────┼─────────────────────────────────────┤
│ sudo timedatectl set-time "HH:MM:SS" │ Set time (NTP disabled) │
│ sudo timedatectl set-time "YYYY-MM-DD"│ Set date │
├───────────────────────────────────────┼─────────────────────────────────────┤
│ timedatectl timesync-status │ NTP synchronization status │
│ date │ Display date/time │
│ sudo hwclock --show │ Display RTC time │
│ sudo hwclock --systohc │ Sync system → RTC │
└───────────────────────────────────────┴─────────────────────────────────────┘
Best Practices
┌─────────────────────────────────────────────────────────────────────────────┐
│ BEST PRACTICES CHECKLIST │
└─────────────────────────────────────────────────────────────────────────────┘
✅ Always use timedatectl (modern and reliable method)
✅ Enable NTP synchronization on all servers
✅ Use UTC for multi-regional production servers
✅ Use local timezone for local servers
✅ Configure RTC clock in UTC (not local time)
✅ Verify UDP port 123 is open for NTP
✅ Document the chosen timezone

















