Time Zone Configuration in VyOS

Configuring the time zone correctly in VyOS is critical for the proper operation of logging, the task scheduler, timestamps in logs, and time synchronization with external systems.

Key Capabilities

  • Setting the time zone: Configuring local time for the system
  • NTP integration: Automatic time synchronization
  • Timestamps: Correct timestamps in logs and configuration files
  • Task scheduling: Precise execution of scheduled tasks
  • Coordination with external systems: Time synchronization with SIEM, monitoring, and backup systems

Basic Configuration

Setting the Time Zone

# Set the time zone (Moscow)
set system time-zone Europe/Moscow

commit
save

Verification:

# Show the current time and time zone
show date

# Result:
# Wed Oct 14 15:30:45 MSK 2025

List of Available Time Zones

# Show all available time zones
ls /usr/share/zoneinfo/

# Time zones of Russia
ls /usr/share/zoneinfo/Europe/ | grep -E "Moscow|Samara|Yekaterinburg|Omsk|Krasnoyarsk|Irkutsk|Yakutsk|Vladivostok|Magadan|Kamchatka"

# Other regions
ls /usr/share/zoneinfo/Europe/
ls /usr/share/zoneinfo/America/
ls /usr/share/zoneinfo/Asia/
ls /usr/share/zoneinfo/Africa/
ls /usr/share/zoneinfo/Australia/

Time Zones of Russia

Main time zones of the Russian Federation:

  • Europe/Kaliningrad - MSK-1 (UTC+2)
  • Europe/Moscow - MSK (UTC+3) - Moscow, Saint Petersburg
  • Europe/Samara - MSK+1 (UTC+4) - Samara, Izhevsk, Ulyanovsk
  • Asia/Yekaterinburg - MSK+2 (UTC+5) - Yekaterinburg, Chelyabinsk, Perm
  • Asia/Omsk - MSK+3 (UTC+6) - Omsk
  • Asia/Krasnoyarsk - MSK+4 (UTC+7) - Krasnoyarsk, Novosibirsk, Kemerovo
  • Asia/Irkutsk - MSK+5 (UTC+8) - Irkutsk, Ulan-Ude
  • Asia/Yakutsk - MSK+6 (UTC+9) - Yakutsk, Chita
  • Asia/Vladivostok - MSK+7 (UTC+10) - Vladivostok, Khabarovsk
  • Asia/Magadan - MSK+8 (UTC+11) - Magadan, Sakhalin
  • Asia/Kamchatka - MSK+9 (UTC+12) - Petropavlovsk-Kamchatsky
# Set for various regions of Russia
set system time-zone Europe/Moscow      # Moscow
set system time-zone Asia/Yekaterinburg # Yekaterinburg
set system time-zone Asia/Vladivostok   # Vladivostok

commit
save

NTP Integration

# Configure NTP for automatic time synchronization
set service ntp server 0.ru.pool.ntp.org
set service ntp server 1.ru.pool.ntp.org
set service ntp server 2.ru.pool.ntp.org

# Set the time zone
set system time-zone Europe/Moscow

commit
save

Verifying synchronization:

# NTP status
show ntp

# Output:
#      remote           refid      st t when poll reach   delay   offset  jitter
# ==============================================================================
# *ntp1.example.com .GPS.            1 u   64   64  377    1.234   -0.123   0.045
# +ntp2.example.com .GPS.            1 u   32   64  377    2.345    0.234   0.067

# Show the current time
show date

Advanced Configuration

Configuration for Distributed Infrastructure

When you have routers in different time zones:

# Router in Moscow
set system host-name vyos-msk
set system time-zone Europe/Moscow
set service ntp server ntp1.yandex.ru
set service ntp server ntp2.yandex.ru

# Router in Yekaterinburg
set system host-name vyos-ekb
set system time-zone Asia/Yekaterinburg
set service ntp server ntp1.yandex.ru
set service ntp server ntp2.yandex.ru

# Router in Vladivostok
set system host-name vyos-vvo
set system time-zone Asia/Vladivostok
set service ntp server ntp1.yandex.ru
set service ntp server ntp2.yandex.ru

commit
save

UTC for Centralized Logging

For centralized logging and monitoring systems, using UTC is recommended:

# Set UTC (Coordinated Universal Time)
set system time-zone UTC

# NTP servers
set service ntp server 0.pool.ntp.org
set service ntp server 1.pool.ntp.org

commit
save

Advantages of UTC:

  • No confusion with the switch to daylight saving/standard time
  • Simplifies correlation of logs from different time zones
  • A standard for distributed systems

Disadvantages of UTC:

  • Inconvenient for local administrators
  • Requires time conversion when analyzing logs

Automatic Time Zone Configuration from DHCP

# Enable receiving NTP servers from DHCP (if it is a WAN interface)
set interfaces ethernet eth0 address dhcp

# DHCP option 42 (NTP servers) will be applied automatically
# But the time zone still needs to be configured manually
set system time-zone Europe/Moscow

commit
save

Configuration Examples

1. Corporate Network with a Local NTP Server

Task: Configure routers in offices to synchronize with the corporate NTP.

Head office (Moscow):

set system host-name vyos-hq-msk
set system time-zone Europe/Moscow

# Corporate NTP server + public ones as fallback
set service ntp server ntp.corp.local prefer
set service ntp server 0.ru.pool.ntp.org
set service ntp server 1.ru.pool.ntp.org

# NTP server for the local network (the router serves time to clients)
set service ntp listen-address 192.168.1.1

commit
save

Branch office (Yekaterinburg):

set system host-name vyos-branch-ekb
set system time-zone Asia/Yekaterinburg

# Synchronization with the head office over VPN
set service ntp server ntp.corp.local prefer
set service ntp server 0.ru.pool.ntp.org

# NTP server for the branch office local network
set service ntp listen-address 10.10.1.1

commit
save

Verification:

# At the head office
show ntp

# At the branch office - should be synchronized with ntp.corp.local
show ntp | grep ntp.corp.local

2. Data Center with UTC and Centralized Logging

Task: Configure data center routers with UTC for log correlation.

set system host-name vyos-dc-core01
set system time-zone UTC

# Stratum 1 NTP servers (high accuracy)
set service ntp server time.nist.gov
set service ntp server time.google.com
set service ntp server ntp.yandex.ru

# Centralized syslog with UTC timestamps
set system syslog host 10.0.0.100 facility all level info
set system syslog host 10.0.0.100 protocol tcp
set system syslog host 10.0.0.100 port 514

commit
save

Syslog server configuration (rsyslog):

# Set UTC on the syslog server
sudo timedatectl set-timezone UTC

# Use UTC timestamps in the rsyslog configuration
sudo tee -a /etc/rsyslog.conf > /dev/null <<'EOF'
# Use UTC for timestamps
$ActionFileDefaultTemplate RSYSLOG_FileFormat
$template FileFormat,"%timegenerated% %HOSTNAME% %syslogtag%%msg:::drop-last-lf%\n"
EOF

sudo systemctl restart rsyslog

ELK Stack with UTC:

# Logstash filter for parsing VyOS logs with UTC
filter {
  if [type] == "syslog" {
    date {
      match => [ "timestamp", "MMM dd HH:mm:ss", "MMM  d HH:mm:ss" ]
      timezone => "UTC"
    }
  }
}

3. Multi-site Network with Different Time Zones

Task: Manage a network with offices in Moscow, Novosibirsk, and Vladivostok.

Moscow (MSK, UTC+3):

set system host-name vyos-msk
set system time-zone Europe/Moscow
set service ntp server 0.ru.pool.ntp.org
set service ntp server ntp1.yandex.ru

# Task scheduler (backup at 3:00 local time)
set system task-scheduler task backup-config interval '0 3 * * *'
set system task-scheduler task backup-config executable path '/config/scripts/backup.sh'

commit
save

Novosibirsk (MSK+4, UTC+7):

set system host-name vyos-nsk
set system time-zone Asia/Krasnoyarsk
set service ntp server 0.ru.pool.ntp.org
set service ntp server ntp1.yandex.ru

# Backup at 3:00 local time (same as 23:00 MSK)
set system task-scheduler task backup-config interval '0 3 * * *'
set system task-scheduler task backup-config executable path '/config/scripts/backup.sh'

commit
save

Vladivostok (MSK+7, UTC+10):

set system host-name vyos-vvo
set system time-zone Asia/Vladivostok
set service ntp server 0.ru.pool.ntp.org
set service ntp server ntp1.yandex.ru

# Backup at 3:00 local time (same as 20:00 MSK of the previous day)
set system task-scheduler task backup-config interval '0 3 * * *'
set system task-scheduler task backup-config executable path '/config/scripts/backup.sh'

commit
save

Centralized monitoring:

#!/usr/bin/env python3
# Script for monitoring the time on all routers

import paramiko
from datetime import datetime

routers = [
    {'host': 'vyos-msk.corp.local', 'tz': 'Europe/Moscow'},
    {'host': 'vyos-nsk.corp.local', 'tz': 'Asia/Krasnoyarsk'},
    {'host': 'vyos-vvo.corp.local', 'tz': 'Asia/Vladivostok'},
]

def check_router_time(router):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(router['host'], username='admin', key_filename='/home/admin/.ssh/id_rsa')

    stdin, stdout, stderr = ssh.exec_command('date +"%Y-%m-%d %H:%M:%S %Z"')
    router_time = stdout.read().decode().strip()

    print(f"{router['host']}: {router_time}")

    ssh.close()

for router in routers:
    check_router_time(router)

4. High-Precision Synchronization for Financial Applications

Task: Ensure time accuracy for trading applications (accuracy <1ms).

set system host-name vyos-trading
set system time-zone Europe/Moscow

# Use stratum 1 NTP servers (GPS/atomic clocks)
set service ntp server time.nist.gov iburst
set service ntp server time.google.com iburst
set service ntp server ntp.yandex.ru iburst

commit
save

Additional settings for accuracy:

# Configure chrony for more precise synchronization (an alternative to ntpd)
sudo apt-get update
sudo apt-get install chrony

# chrony configuration
sudo tee /etc/chrony/chrony.conf > /dev/null <<'EOF'
# Stratum 1 servers
server time.nist.gov iburst minpoll 4 maxpoll 6
server time.google.com iburst minpoll 4 maxpoll 6
server ntp.yandex.ru iburst minpoll 4 maxpoll 6

# Make steps for large clock errors
makestep 0.1 3

# Enable hardware timestamps
hwtimestamp *

# Use RTC
rtcsync

# Log
logdir /var/log/chrony
log measurements statistics tracking
EOF

sudo systemctl restart chrony

# Check the accuracy
chronyc tracking
# Output:
# Reference ID    : C0A80001 (time.google.com)
# Stratum         : 2
# Ref time (UTC)  : Wed Oct 14 12:30:45 2025
# System time     : 0.000000123 seconds fast of NTP time
# Last offset     : +0.000000045 seconds
# RMS offset      : 0.000000089 seconds
# ...

Accuracy monitoring:

# Script for monitoring the offset
sudo tee /config/scripts/ntp-accuracy-monitor.sh > /dev/null <<'EOF'
#!/bin/bash
THRESHOLD=0.001  # 1ms

OFFSET=$(chronyc tracking | grep "System time" | awk '{print $4}')

# Convert to absolute value
OFFSET_ABS=$(echo "$OFFSET" | awk '{print ($1 < 0) ? -$1 : $1}')

if (( $(echo "$OFFSET_ABS > $THRESHOLD" | bc -l) )); then
    echo "WARNING: NTP offset too high: $OFFSET seconds"
    logger -t ntp-monitor "WARNING: NTP offset too high: $OFFSET seconds"
    # Send an alert
fi
EOF

chmod +x /config/scripts/ntp-accuracy-monitor.sh

# Schedule a check every 5 minutes
set system task-scheduler task ntp-accuracy-check interval '*/5 * * * *'
set system task-scheduler task ntp-accuracy-check executable path '/config/scripts/ntp-accuracy-monitor.sh'

commit
save

5. Time Zone Isolation for MSPs

Task: An MSP manages clients in different time zones, and each client wants to see their own local time in the logs.

Solution using VRF and separate syslog:

# Client 1 (Moscow)
set vrf name CLIENT1 table 100
set interfaces ethernet eth1 vrf CLIENT1
set interfaces ethernet eth1 address 192.168.1.1/24

# Client 2 (Vladivostok)
set vrf name CLIENT2 table 200
set interfaces ethernet eth2 vrf CLIENT2
set interfaces ethernet eth2 address 192.168.2.1/24

# Main system in UTC
set system time-zone UTC

# NTP
set service ntp server 0.pool.ntp.org
set service ntp server 1.pool.ntp.org

commit
save

Script for converting logs to the client’s local time:

sudo tee /config/scripts/convert-logs-timezone.sh > /dev/null <<'EOF'
#!/bin/bash
# Convert logs from UTC to the client's local time

CLIENT_TZ=$1
LOG_FILE=$2

if [ -z "$CLIENT_TZ" ] || [ -z "$LOG_FILE" ]; then
    echo "Usage: $0 <timezone> <logfile>"
    exit 1
fi

# Read the logs and convert the timestamp
while IFS= read -r line; do
    # Extract the timestamp (format: Oct 14 12:30:45)
    timestamp=$(echo "$line" | awk '{print $1, $2, $3}')

    # Convert to the client's local time
    local_time=$(TZ="$CLIENT_TZ" date -d "$timestamp" "+%b %d %H:%M:%S")

    # Replace the timestamp in the line
    echo "$line" | sed "s/$timestamp/$local_time/"
done < "$LOG_FILE"
EOF

chmod +x /config/scripts/convert-logs-timezone.sh

# Usage:
# ./convert-logs-timezone.sh Europe/Moscow /var/log/messages
# ./convert-logs-timezone.sh Asia/Vladivostok /var/log/messages

6. Automatic Time Correction After a Failure

Task: Automatically correct the time after a power outage.

set system time-zone Europe/Moscow

# NTP with aggressive synchronization
set service ntp server 0.ru.pool.ntp.org
set service ntp server 1.ru.pool.ntp.org
set service ntp server ntp1.yandex.ru

commit
save

Script for checking and correcting the time at boot:

sudo tee /config/scripts/boot-time-check.sh > /dev/null <<'EOF'
#!/bin/bash
# Check the time at boot and force synchronization if it differs significantly

MAX_OFFSET=300  # 5 minutes

# Wait for the network
sleep 10

# Query the time from the NTP server
NTP_TIME=$(ntpdate -q 0.ru.pool.ntp.org | grep "offset" | head -1 | awk '{print $6}')

if [ -z "$NTP_TIME" ]; then
    logger -t boot-time-check "ERROR: Cannot reach NTP server"
    exit 1
fi

# Get the absolute value of the offset
OFFSET=$(echo "$NTP_TIME" | awk '{print ($1 < 0) ? -$1 : $1}')

if (( $(echo "$OFFSET > $MAX_OFFSET" | bc -l) )); then
    logger -t boot-time-check "WARNING: Time offset too large ($NTP_TIME sec), forcing sync"

    # Stop ntpd
    systemctl stop ntp

    # Force setting the time
    ntpdate -s 0.ru.pool.ntp.org

    # Start ntpd
    systemctl start ntp

    logger -t boot-time-check "Time synchronized successfully"
else
    logger -t boot-time-check "Time offset acceptable ($NTP_TIME sec)"
fi
EOF

chmod +x /config/scripts/boot-time-check.sh

# Add to startup via systemd
sudo tee /etc/systemd/system/boot-time-check.service > /dev/null <<'EOF'
[Unit]
Description=Boot Time Check and Correction
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/config/scripts/boot-time-check.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable boot-time-check.service

Monitoring and Diagnostics

Operational Commands

# Show the current time and time zone
show date

# Show the current time zone
show configuration system time-zone

# NTP status
show ntp

# Detailed NTP information
ntpq -p

# NTP statistics
ntpstat

# Check the system time
date

# Show the hardware time (RTC)
sudo hwclock

# Check the difference between system time and hardware clock
sudo hwclock --compare

Verifying NTP Synchronization

# Quick NTP check
ntpq -c peers

# Output:
#      remote           refid      st t when poll reach   delay   offset  jitter
# ==============================================================================
# *ntp1.yandex.ru  .GPS.            1 u   32   64  377    2.345   -0.123   0.045
# +ntp2.yandex.ru  .GPS.            1 u   64   64  377    3.456    0.234   0.067

# Symbols:
# * - current time source
# + - candidate source
# - - rejected source
# x - false ticker

# Check the offset (time difference)
ntpq -c rv | grep offset

# Tracking information
ntpq -c associations

Time and NTP Logs

# NTP logs
show log | match ntp

# System time logs
journalctl -u ntp

# Time correction logs
sudo grep "time" /var/log/syslog

# Logs of large time jumps
sudo grep "clock stepped" /var/log/syslog

Time Accuracy Monitoring

# Script for monitoring the NTP offset
sudo tee /config/scripts/ntp-monitoring.sh > /dev/null <<'EOF'
#!/bin/bash
# Monitoring NTP synchronization

# Get the offset
OFFSET=$(ntpq -c rv | grep offset | awk -F= '{print $2}' | awk '{print $1}')

# Get the jitter
JITTER=$(ntpq -c rv | grep jitter | awk -F= '{print $2}' | awk '{print $1}')

# Get the stratum
STRATUM=$(ntpq -c rv | grep stratum | awk -F= '{print $2}' | awk '{print $1}')

echo "NTP Status:"
echo "  Offset: $OFFSET ms"
echo "  Jitter: $JITTER ms"
echo "  Stratum: $STRATUM"

# Check the thresholds
OFFSET_THRESHOLD=100  # 100ms
JITTER_THRESHOLD=50   # 50ms

if (( $(echo "$OFFSET > $OFFSET_THRESHOLD" | bc -l) )); then
    echo "WARNING: NTP offset too high!"
    logger -t ntp-monitor "WARNING: NTP offset too high: $OFFSET ms"
fi

if (( $(echo "$JITTER > $JITTER_THRESHOLD" | bc -l) )); then
    echo "WARNING: NTP jitter too high!"
    logger -t ntp-monitor "WARNING: NTP jitter too high: $JITTER ms"
fi
EOF

chmod +x /config/scripts/ntp-monitoring.sh

# Schedule monitoring every 15 minutes
set system task-scheduler task ntp-monitor interval '*/15 * * * *'
set system task-scheduler task ntp-monitor executable path '/config/scripts/ntp-monitoring.sh'

commit
save

Troubleshooting

1. Time Does Not Synchronize with NTP

Symptoms: show ntp shows that there is no synchronization with the servers.

Verification:

# Check the NTP status
show ntp

# Check the availability of the NTP servers
ping 0.ru.pool.ntp.org

# Check UDP port 123
sudo tcpdump -i eth0 port 123

# Check the firewall
show firewall

Solution:

# Restart NTP
restart service ntp

# Check the NTP configuration
show configuration service ntp

# Allow NTP in the firewall (if it is being blocked)
set firewall name WAN_LOCAL rule 100 action accept
set firewall name WAN_LOCAL rule 100 protocol udp
set firewall name WAN_LOCAL rule 100 destination port 123

commit
save

# Force synchronization (stop ntpd, synchronize, start)
sudo systemctl stop ntp
sudo ntpdate 0.ru.pool.ntp.org
sudo systemctl start ntp

2. Incorrect Timestamps in Logs

Symptoms: The time in the logs does not match reality or is in the wrong time zone.

Verification:

# Check the system time
show date

# Check the time zone
show configuration system time-zone

# Check the logs
show log | tail 10

Solution:

# Set the correct time zone
set system time-zone Europe/Moscow

commit
save

# Check NTP synchronization
show ntp

# If the time is significantly behind, force synchronization
sudo ntpdate -s 0.ru.pool.ntp.org

3. Task Scheduler Runs Tasks at the Wrong Time

Symptoms: The task scheduler runs tasks at unexpected times.

Verification:

# Check the time zone
show configuration system time-zone

# Check the current time
show date

# Check the task-scheduler settings
show configuration system task-scheduler

Solution:

# Make sure the time zone is set correctly
set system time-zone Europe/Moscow

# Review the task schedule taking the time zone into account
# For example, for a backup at 3:00 MSK:
set system task-scheduler task backup interval '0 3 * * *'

commit
save

# Verify that cron uses the correct time
sudo cat /etc/crontab

4. Large Offset After a Reboot

Symptoms: After a reboot, the time differs significantly from the real time.

Cause: The hardware clock (RTC) is not synchronized or the battery is dead.

Verification:

# Check the system time
date

# Check the hardware time
sudo hwclock

# Difference between system and hardware clock
sudo hwclock --compare

Solution:

# Synchronize the time with NTP
sudo ntpdate -s 0.ru.pool.ntp.org

# Write the system time to the hardware clock
sudo hwclock --systohc

# Verify
sudo hwclock
date

# Enable automatic RTC synchronization
# Add to /etc/systemd/timesyncd.conf:
sudo tee -a /etc/systemd/timesyncd.conf > /dev/null <<'EOF'
[Time]
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048
EOF

sudo systemctl restart systemd-timesyncd

5. NTP Does Not Work Behind NAT

Symptoms: NTP cannot synchronize the time on a router behind NAT.

Cause: Some NAT gateways block or incorrectly handle NTP traffic (UDP 123).

Solution:

# Use an NTP pool instead of specific servers
set service ntp server 0.pool.ntp.org
set service ntp server 1.pool.ntp.org
set service ntp server 2.pool.ntp.org

# Add the iburst option for fast synchronization
# (requires manual editing of /etc/ntp.conf)
sudo sed -i 's/^server /server iburst /' /etc/ntp.conf

# Restart NTP
sudo systemctl restart ntp

commit
save

6. DST (Daylight Saving Time) Problems

Symptoms: The time is incorrect after the switch to daylight saving/standard time.

Note: Russia abolished the switch to daylight saving time in 2014. But the problem may occur in other countries.

Solution:

# Update tzdata (time zone data)
sudo apt-get update
sudo apt-get install --only-upgrade tzdata

# Check the tzdata version
dpkg -l | grep tzdata

# Reinstall the time zone
set system time-zone UTC
commit
set system time-zone Europe/Moscow
commit
save

# Restart NTP
restart service ntp

Best Practices

  1. Time zone selection

    • Use UTC for centralized logging systems
    • Use local time for administrator convenience
    • Document the selected time zone
    • Coordinate with the DevOps/NOC team
  2. NTP configuration

    • Use at least 3 NTP servers
    • Prefer local NTP servers for accuracy
    • Use stratum 1-2 servers for critical systems
    • Configure a fallback to public NTP pools
  3. Time monitoring

    • Monitor the NTP offset (threshold of 100ms for general systems, 1ms for financial ones)
    • Monitor the NTP jitter
    • Alert on loss of synchronization
    • Log all time corrections
  4. Hardware clock (RTC)

    • Synchronize the RTC with the system time regularly
    • Check the RTC battery once a year
    • Automatically correct the time at boot
  5. Task scheduling

    • Take the time zone into account when configuring cron
    • Avoid scheduling critical tasks during a potential DST transition
    • Document task execution times in comments
  6. Distributed systems

    • Synchronize all devices with a single time source
    • Use a centralized NTP server
    • The corporate NTP server must synchronize with a stratum 1 source
  7. Logging

    • Include the time zone in log timestamps
    • Use the ISO 8601 format for log export
    • Convert the time when analyzing logs from different time zones
  8. Backup and Recovery

    • Check the time before performing a backup
    • Include a timestamp in backup file names
    • Do not rely solely on file modification time
  9. Compliance and Audit

    • Document the time source
    • Retain time synchronization logs
    • Prove time accuracy for auditors
    • Comply with regulatory requirements (PCI DSS, SOX)
  10. Troubleshooting

    • Always check the time when problems occur
    • Compare the time across all system components
    • Use UTC for event correlation
    • Document time anomalies

Conclusion

Correctly configuring the time zone and time synchronization in VyOS is critical for the proper operation of logging, task scheduling, coordination with external systems, and compliance with audit requirements. Using NTP for automatic synchronization, selecting an appropriate time zone for your infrastructure, and regularly monitoring time accuracy ensure reliable operation of network equipment and simplify troubleshooting in distributed systems.

Reviewed by OpenNix LLC · Last updated on