See also NTP client / NTP server
NTP provides time synchronization based on a network of reference clocks located around the world. OpenWrt supports both NTP client protocol (to synchronize local time with a distant clock) and NTP server protocol (to deliver time to your local network).
The ntp configuration is located in system uci subsystem, and found in file /etc/config/system.
The NTP configuration is found in timeserver section of system uci subsystem.
# uci show system system.ntp=timeserver system.ntp.enabled='1' system.ntp.enable_server='0' system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org' '2.openwrt.pool.ntp.org' '3.openwrt.pool.ntp.org'
These are the options defined for the timeserver ntp section:
|server||list of hostnames||no||(openwrt ntp servers)|| Pool of NTP servers to poll the time from.
If empty, ntpd disables client mode, and system time won't be set automatically.
|enable_server||boolean||no||0|| setting this to 1 enables the time server on this device, ntpd will answer with the time of the router.
(busybox-ntpd listens to UDP 123 by default)
|use_dhcp||boolean||no||1||setting this to 0 disables the use of DHCP-provided NTP servers.|
In /etc/config/system busybox-rdate (was invoked by scripts) has been replaced with busybox-nptd (can run as a daemon) to avoid race condition and also to use current NTP. The remote time is since configured in /etc/config/system and not in /etc/config/timeserver any longer.
By default, NTP client is enabled and NTP server is disabled. Enable server mode:
uci set system.ntp.enable_server="1" uci commit system /etc/init.d/sysntpd restart
In theory, OpenWrt pull zone provide the closest available servers. Practically, this may result in distant connections. To make sure to use NTP servers located in your country, it is possible to use regional pull zone. For example, in France, here is a sample configuration (notice the 'fr' for France and adapt it):
uci -q delete system.ntp.server uci add_list system.ntp.server="0.fr.pool.ntp.org" uci add_list system.ntp.server="1.fr.pool.ntp.org" uci add_list system.ntp.server="2.fr.pool.ntp.org" uci add_list system.ntp.server="3.fr.pool.ntp.org" uci commit system /etc/init.d/sysntpd restart
By default, NTP server analysis tools are not installed (and not needed). You may want to install ntp-utils package, which is a collection of tools used to synchronize the system clock with remote NTP time servers and run/monitor local NTP servers. This package contains ntpdc, ntpq and ntptime.
opkg install ntp-utils
Enter 'ntpq' to query the NTP subsystem and 'peers' to display NTP peers used by your OpenWrt appliance:
# ntpq ntpq> peer remote refid st t when poll reach delay offset jitter ============================================================================== 0.fr.pool.ntp.o .POOL. 16 p - 64 0 0.000 0.000 0.000 1.fr.pool.ntp.o .POOL. 16 p - 64 0 0.000 0.000 0.000 2.fr.pool.ntp.o .POOL. 16 p - 64 0 0.000 0.000 0.000 3.fr.pool.ntp.o .POOL. 16 p - 64 0 0.000 0.000 0.000 +ntp-3.arkena.ne 18.104.22.168 2 u 134 256 375 11.838 -1.119 1.194 nsr2.neoserveur 22.214.171.124 2 u 1520 512 2 17.462 -0.064 2.688 +126.96.36.199 ( 188.8.131.52 4 u 222 256 377 12.241 1.094 1.620 -time1.agiri.nin 184.108.40.206 3 u 28 256 377 12.385 2.388 0.767 *ns3.stoneartpro 220.127.116.11 2 u 107 256 377 11.448 0.467 1.243
Type 'q' to exit this display.