Skip to main content
Back to Category

Timezone and NTP Settings: Server Time Synchronization

Guide to setting timezones with timedatectl, configuring NTP with chrony and systemd-timesyncd, server time synchronization and verification steps on Linux servers.

Read time: 10 min Server Management
ntptimezonetimedatectlchronytimesyncdtime syncclock

Table of Contents

Timezone and NTP Settings: Server Time Synchronization

Correct server time configuration is critical for log consistency, SSL certificate validation, database operations, and scheduled tasks. Incorrect time settings can lead to security vulnerabilities and application errors. This guide covers timezone and NTP configuration on Linux servers.

Checking Current Time Status

hljs bash
# View system time, hardware clock, and NTP status
timedatectl

# Example output:
# Local time: Tue 2024-01-15 14:30:00 TRT
# Universal time: Tue 2024-01-15 11:30:00 UTC
# RTC time: Tue 2024-01-15 11:30:00
# Time zone: Europe/Istanbul (TRT, +0300)
# System clock synchronized: yes
# NTP service: active

# Show current date and time
date

# Show UTC time
date -u

# Show hardware clock
sudo hwclock --show

Setting the Timezone

Changing Timezone with timedatectl

hljs bash
# View current timezone
timedatectl | grep "Time zone"

# List all available timezones
timedatectl list-timezones

# Filter by region
timedatectl list-timezones | grep Europe
timedatectl list-timezones | grep America

# Set timezone
sudo timedatectl set-timezone Europe/Istanbul
sudo timedatectl set-timezone UTC
sudo timedatectl set-timezone Europe/Berlin
sudo timedatectl set-timezone America/New_York
sudo timedatectl set-timezone Asia/Dubai
hljs bash
# Alternative method (for older systems)
sudo ln -sf /usr/share/zoneinfo/Europe/Istanbul /etc/localtime

# Update /etc/timezone
echo "Europe/Istanbul" | sudo tee /etc/timezone

# Verify the change
date

REXE servers come with UTC timezone by default. For Turkey, use Europe/Istanbul (UTC+3). Keeping servers in UTC is also a good practice for log analysis.

NTP Time Synchronization

NTP (Network Time Protocol) synchronizes the server clock with time servers on the internet.

systemd-timesyncd (Lightweight Solution)

The default lightweight NTP client on Ubuntu and Debian.

hljs bash
# Check status
sudo systemctl status systemd-timesyncd

# View NTP sync status
timedatectl show-timesync --all

# Enable NTP
sudo timedatectl set-ntp true

# Disable NTP
sudo timedatectl set-ntp false

timesyncd Configuration

hljs bash
# Edit configuration file
sudo nano /etc/systemd/timesyncd.conf
hljs ini
[Time]
# Primary NTP servers
NTP=0.pool.ntp.org 1.pool.ntp.org time.cloudflare.com
# Fallback NTP servers
FallbackNTP=2.pool.ntp.org 3.pool.ntp.org time.google.com
# Maximum root distance (seconds)
RootDistanceMaxSec=5
hljs bash
# Restart the service
sudo systemctl restart systemd-timesyncd

# Check sync status
timedatectl

Chrony (Advanced Solution)

Chrony offers better performance for intermittently connected or virtualized environments.

hljs bash
# Install chrony (Ubuntu/Debian)
sudo apt install chrony -y

# Install chrony (RHEL/CentOS/AlmaLinux)
sudo dnf install chrony -y

# Start and enable the service
sudo systemctl enable --now chronyd

Chrony Configuration

hljs bash
# Edit configuration file
sudo nano /etc/chrony/chrony.conf  # Ubuntu/Debian
# or
sudo nano /etc/chrony.conf  # RHEL/CentOS
hljs bash
# NTP pool servers
pool 0.pool.ntp.org iburst
pool 1.pool.ntp.org iburst

# Cloudflare NTP (high precision)
server time.cloudflare.com iburst

# Google NTP
server time.google.com iburst

# Drift file
driftfile /var/lib/chrony/drift

# Log directory
logdir /var/log/chrony

# Allow large time steps on startup
makestep 1.0 3

# Sync RTC
rtcsync
hljs bash
# Restart the service
sudo systemctl restart chronyd

# Check chrony status
chronyc tracking

# List NTP sources
chronyc sources -v

# View source statistics
chronyc sourcestats
ServerDescriptionUse Case
pool.ntp.orgGlobal NTP poolGeneral use
time.cloudflare.comCloudflare NTPHigh precision
time.google.comGoogle NTPHigh reliability
time.windows.comMicrosoft NTPWindows compatible

Hardware Clock (RTC) Synchronization

hljs bash
# Write system time to hardware clock
sudo hwclock --systohc

# Read hardware clock to system time
sudo hwclock --hctosys

# Set hardware clock to UTC
sudo hwclock --systohc --utc

# Show hardware clock
sudo hwclock --show

Verification

hljs bash
# Check NTP sync status
timedatectl | grep synchronized

# Check sync with chrony
chronyc tracking | grep "System time"

# Quick check with ntpdate (if installed)
ntpdate -q pool.ntp.org

Don't run chrony and systemd-timesyncd at the same time. When installing chrony, disable timesyncd: sudo systemctl disable --now systemd-timesyncd

Troubleshooting

Clock Not Synchronizing

hljs bash
# Check NTP port (UDP 123)
sudo ufw allow 123/udp

# Check chrony log
sudo tail -f /var/log/chrony/tracking.log

# Test connectivity
ntpdate -q pool.ntp.org

# Force chrony to sync
sudo chronyc makestep

Large Time Offset

hljs bash
# Set time manually (with NTP disabled)
sudo timedatectl set-ntp false
sudo timedatectl set-time "2024-01-15 14:30:00"
sudo timedatectl set-ntp true

# Quick fix with chrony
sudo chronyc makestep

Conclusion

Proper timezone and NTP configuration is a fundamental requirement for reliable server infrastructure. On REXE servers, you can keep your clock synchronized at all times using chrony or systemd-timesyncd, ensuring log consistency and application reliability.