NTP Service
NTP (Network Time Protocol) is a protocol for synchronizing the clocks of computer systems over a network.
Overview
VyOS uses chrony (starting from version 1.4) to implement the NTP client and server.
NTP provides:
- System time synchronization with millisecond accuracy
- Automatic time correction
- Leap second handling
- A hierarchical system of time servers (stratum)
- Simultaneous operation as both a client and a server
Protocol: UDP port 123
Current version: NTPv4 (RFC 5905)
Basic configuration
NTP client
Synchronization with public NTP 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
commitBy default, VyOS uses:
- time1.vyos.net
- time2.vyos.net
- time3.vyos.net
NTP server
Allowing clients to synchronize with VyOS:
set service ntp listen-address '192.168.1.1'
set service ntp allow-client address '192.168.1.0/24'
commitNTP server configuration
Adding a server
set service ntp server <hostname|IP>Examples:
set service ntp server pool.ntp.org
set service ntp server time.google.com
set service ntp server 216.239.35.0Server options
prefer - Preferred server
Server priority when selecting a time source:
set service ntp server 0.pool.ntp.org prefernoselect - Do not use for synchronization
The server is monitored but not used:
set service ntp server backup.ntp.org noselectpool - Pool mode
Automatic name resolution and addition of multiple servers:
set service ntp server pool.ntp.org poolA single DNS query can return multiple IP addresses, and all of them will be used.
nts - Network Time Security
Encrypted NTP connection:
set service ntp server time.cloudflare.com ntsNTS provides authentication and confidentiality for NTP traffic.
ptp - PTP Transport
Using the Precision Time Protocol transport:
set service ntp server ntp.example.com ptpinterleave - Interleaved Mode
Improved synchronization accuracy:
set service ntp server ntp.example.com interleaveNTP Pool
Public NTP Pools
NTP Pool Project (pool.ntp.org):
set service ntp server 0.pool.ntp.org
set service ntp server 1.pool.ntp.org
set service ntp server 2.pool.ntp.org
set service ntp server 3.pool.ntp.orgRegional pools:
# Russia
set service ntp server 0.ru.pool.ntp.org
set service ntp server 1.ru.pool.ntp.org
# Europe
set service ntp server 0.europe.pool.ntp.org
set service ntp server 1.europe.pool.ntp.org
# North America
set service ntp server 0.north-america.pool.ntp.orgVendor-specific:
# Debian
set service ntp server 0.debian.pool.ntp.org
# Ubuntu
set service ntp server ntp.ubuntu.comMajor providers
Google Public NTP:
set service ntp server time.google.com
set service ntp server time1.google.com
set service ntp server time2.google.com
set service ntp server time3.google.com
set service ntp server time4.google.comCloudflare NTP (with NTS):
set service ntp server time.cloudflare.com ntsFacebook NTP:
set service ntp server time.facebook.comNTP Server Configuration
Listen Address
Addresses to listen for NTP requests on:
set service ntp listen-address '192.168.1.1'
set service ntp listen-address '10.0.0.1'
set service ntp listen-address '2001:db8::1'By default, it listens on all interfaces.
Allow Client
Allowing clients to synchronize:
set service ntp allow-client address '192.168.1.0/24'
set service ntp allow-client address '10.0.0.0/8'
set service ntp allow-client address '2001:db8::/32'Without allow-client, the server will only synchronize itself but will not serve clients.
Leap Second
Handling leap seconds:
set service ntp leap-second <mode>Modes:
- ignore - ignore the leap second
- smear - spread the correction over several hours
- system - use the system’s handling
- timezone - use timezone data
Recommended:
set service ntp leap-second smearHardware Timestamping
Hardware timestamps for improved accuracy:
set service ntp timestamp interface eth0Filter options:
set service ntp timestamp interface eth0 receive-filter allFilter modes:
- all - all packets
- ntp - NTP only
- ptp - PTP only
- none - no hardware timestamps
VRF Support
Running NTP in a specific VRF:
set service ntp vrf MGMTConfiguration examples
Basic NTP client
# Synchronization with public servers
set service ntp server 0.pool.ntp.org
set service ntp server 1.pool.ntp.org
set service ntp server time.google.com prefer
commitNTP server for a local network
# Upstream 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
# Listen on the LAN interface
set service ntp listen-address '192.168.1.1'
# Allow clients from the LAN
set service ntp allow-client address '192.168.1.0/24'
commitEnterprise configuration
# Corporate NTP servers
set service ntp server ntp1.corp.local prefer
set service ntp server ntp2.corp.local
set service ntp server ntp3.corp.local
# Public fallbacks
set service ntp server time.google.com
set service ntp server time.cloudflare.com nts
# Server for subnets
set service ntp listen-address '192.168.10.1'
set service ntp listen-address '192.168.20.1'
# Allow corporate networks
set service ntp allow-client address '192.168.0.0/16'
set service ntp allow-client address '10.0.0.0/8'
# Leap second
set service ntp leap-second smear
commitHigh-precision NTP
# Stratum 1 servers
set service ntp server ntp1.example.com interleave
set service ntp server ntp2.example.com interleave
set service ntp server ntp3.example.com interleave
# Hardware timestamping
set service ntp timestamp interface eth0
set service ntp timestamp interface eth0 receive-filter ntp
commitRegional configuration (Russia)
# Russian NTP servers
set service ntp server 0.ru.pool.ntp.org pool
set service ntp server 1.ru.pool.ntp.org pool
set service ntp server ntp.ix.ru
set service ntp server ntp1.vniiftri.ru
set service ntp server ntp2.vniiftri.ru
# Global fallbacks
set service ntp server time.google.com
# Local server
set service ntp listen-address '192.168.1.1'
set service ntp allow-client address '192.168.1.0/24'
commitMulti-site with VRF
# Management VRF
set service ntp vrf MGMT
# Upstream in the management network
set service ntp server 10.0.0.10
set service ntp server 10.0.0.11
# Listen in management
set service ntp listen-address '10.0.1.1'
set service ntp allow-client address '10.0.0.0/8'
commitSecure NTP with NTS
# NTS-only servers
set service ntp server time.cloudflare.com nts
set service ntp server ntppool1.time.nl nts
set service ntp server nts.ntp.se nts
# Leap second
set service ntp leap-second smear
commitOperational commands
Viewing synchronization status
show ntpThe output shows:
- The current synchronization state
- The list of servers and their status
- The stratum level
- Offset (time offset)
- Jitter
NTP information
show ntp infoDetailed information about the NTP daemon.
Time sources
show ntp sourcesA list of all upstream NTP servers.
Statistics
show ntp activityNTP activity statistics.
Restarting the service
restart ntpMonitoring and diagnostics
Checking synchronization
show ntpPay attention to:
- The
*symbol in front of a server indicates the current synchronization source - Offset should be close to zero (< 10ms under normal conditions)
- Jitter should be low (< 5ms is good)
Logs
show log | grep ntp
monitor log | grep chronydChecking server availability
From the client:
ntpdate -q 192.168.1.1or
chronyc -h 192.168.1.1 trackingChecking the firewall
Make sure UDP port 123 is open:
show firewall ipv4 input filterTroubleshooting
Time is not synchronizing
Check the status:
show ntpCheck the availability of upstream servers:
ping 0.pool.ntp.orgCheck the firewall on the WAN:
show firewall ipv4 output filterRestart NTP:
restart ntpLarge time offset
If the offset is > 1 second, a manual time setting may be required:
set system time-zone UTCOr use ntpdate for the initial synchronization.
The NTP server does not respond to clients
Check allow-client:
show service ntpCheck the firewall:
set firewall ipv4 input filter rule 50 action accept
set firewall ipv4 input filter rule 50 destination port 123
set firewall ipv4 input filter rule 50 protocol udp
set firewall ipv4 input filter rule 50 source address 192.168.1.0/24
commitCheck listen-address:
show service ntpConflict with systemd-timesyncd
chrony conflicts with systemd-timesyncd. Make sure only one service is running.
Security
Restricting clients
Always use allow-client:
set service ntp allow-client address '192.168.1.0/24'Firewall rules
# Incoming NTP requests
set firewall ipv4 input filter rule 50 action accept
set firewall ipv4 input filter rule 50 destination port 123
set firewall ipv4 input filter rule 50 protocol udp
set firewall ipv4 input filter rule 50 source address 192.168.1.0/24
# Outgoing for synchronization
set firewall ipv4 output filter rule 50 action accept
set firewall ipv4 output filter rule 50 destination port 123
set firewall ipv4 output filter rule 50 protocol udpRate limiting
Protection against NTP amplification attacks:
set firewall ipv4 input filter rule 50 limit rate 10/secondNTS
Use Network Time Security wherever possible:
set service ntp server time.cloudflare.com ntsBest practices
- Multiple sources - use at least 3-4 NTP servers
- Geographic proximity - choose servers close to your location
- Stratum diversity - use servers of different stratum levels
- prefer server - choose the most reliable one as preferred
- Redundancy - combine local and public servers
- Firewall - restrict access to the NTP service
- Monitoring - track offset and jitter regularly
- NTS - use it where available for security
- Leap second - configure handling for critical systems
- Hardware timestamping - enable it for high accuracy
Stratum hierarchy
- Stratum 0 - Atomic clocks, GPS (reference clocks)
- Stratum 1 - Servers directly connected to Stratum 0
- Stratum 2 - Servers synchronized with Stratum 1
- Stratum 3-15 - Subsequent levels
VyOS typically operates as Stratum 3-4 when synchronizing with public servers.
Performance
Typical accuracy:
- LAN: ±1ms
- WAN: ±10ms
- Internet: ±50ms
- With hardware timestamping: ±10μs (microseconds)
Next steps
- System Time Zone - configuring the time zone
- Firewall - protecting the NTP service
- Monitoring - monitoring NTP metrics