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
Author
REXE Teknoloji Network & Security Team
Editor
REXE Teknoloji Technical Editorial
First published
Last updated

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.

Frequently Asked Questions

Why should I keep my server in UTC?

UTC is a universal standard without daylight saving time. Keeping logs in UTC makes it easy to compare events across servers in different timezones. Timezone conversion for users can be handled at the application layer.

What is the difference between chrony and systemd-timesyncd?

systemd-timesyncd is lighter and simpler, sufficient for most use cases. chrony offers more advanced features: better performance with intermittent connections, faster synchronization, and more precise clock management. chrony is recommended for virtualized environments.

NTP synchronization isn't working, what should I do?

First check NTP status with 'timedatectl'. Make sure UDP port 123 is open ('sudo ufw allow 123/udp'). If using chrony, check NTP sources with 'chronyc sources -v'. For large time offsets, force sync with 'sudo chronyc makestep'.

Which NTP server should I use?

Use the regional pool from pool.ntp.org for your location. For high precision, add 'time.cloudflare.com' or 'time.google.com'. Defining multiple servers in chrony configuration increases reliability.

Does changing the timezone affect running applications?

Yes, running applications typically read the timezone at startup. You may need to restart applications for the timezone change to take effect. Especially for databases and web servers, run 'systemctl restart' after changing the timezone.

Related Articles

Network TrafficInbound GbpsOutbound Gbps