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.
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
# 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
# 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
Manual Configuration via Symlink
# 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.
# 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
# Edit configuration file
sudo nano /etc/systemd/timesyncd.conf
[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
# 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.
# 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
# Edit configuration file
sudo nano /etc/chrony/chrony.conf # Ubuntu/Debian
# or
sudo nano /etc/chrony.conf # RHEL/CentOS
# 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
# Restart the service
sudo systemctl restart chronyd
# Check chrony status
chronyc tracking
# List NTP sources
chronyc sources -v
# View source statistics
chronyc sourcestats
Recommended NTP Servers
| Server | Description | Use Case |
|---|---|---|
pool.ntp.org | Global NTP pool | General use |
time.cloudflare.com | Cloudflare NTP | High precision |
time.google.com | Google NTP | High reliability |
time.windows.com | Microsoft NTP | Windows compatible |
Hardware Clock (RTC) Synchronization
# 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
# 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
# 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
# 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.
Related Articles
How to Connect to Your VDS Server via SSH (Complete Guide)
Step-by-step SSH connection guide for Linux VDS: PuTTY, Terminal, key-based authentication, Path Panel firewall rules, and security best practices.
How to Connect to Windows VDS via RDP: Complete Guide
Complete guide to connecting to Windows Server VDS via Remote Desktop (RDP): setup steps, NLA security, Path Panel firewall rule, and troubleshooting tips.
How to Change VDS Server OS: Step-by-Step Reinstall Guide
Step-by-step guide to changing your VDS server OS via REXE panel: backup tips, supported Linux distributions and Windows Server versions explained.