Difference between revisions of "Chrony"

From ArchWiki
Jump to: navigation, search
m (Starting chronyd)
(dial-up -> roaming)
Line 1: Line 1:
[[Category:Daemons and system services]]
[[Category:Daemons and system services]]
This article describes how to set up and run Chrony, an alternative NTP client and server that is dial-up friendly and designed specifically for systems that are not online all the time.
This article describes how to set up and run Chrony, an alternative NTP client and server that is roaming friendly and designed specifically for systems that are not online all the time.

Revision as of 15:10, 4 October 2012

This article describes how to set up and run Chrony, an alternative NTP client and server that is roaming friendly and designed specifically for systems that are not online all the time.


chrony is available from the official repositories.


The first thing you define in your /etc/chrony.conf is the servers your machine will synchronize to. NTP servers are classified in a hierarchical system with many levels called strata: the devices which are considered independent time sources are classified as stratum 0 sources; the servers directly connected to stratum 0 devices are classified as stratum 1 sources; servers connected to stratum 1 sources are then classified as stratum 2 sources and so on.

It has to be understood that a server's stratum cannot be taken as an indication of its accuracy or reliability. Typically, stratum 2 servers are used for general synchronization purposes: if you do not already know the servers you are going to connect to, you should use the pool.ntp.org servers (alternate link) and choose the server pool that is closest to your location.

The following lines are just an example:

server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

If your computer is not connected to the internet on startup, it is recommended to use the offline option, to tell chrony not to try and connect to the servers, until it has been given the go:

server 0.pool.ntp.org offline
server 1.pool.ntp.org offline
server 2.pool.ntp.org offline
server 3.pool.ntp.org offline

It may also be a good idea to either use IP addresses instead of host names, or to map the hostnames to IP addresses in your /etc/hosts file, as DNS resolving won't be available until you've made a connection.

To tell chronyd that a connection has been established, you need to be able to log in with chronyc. You will have to configure chronyd with an administrator password to be able to do this. Setting up an administrator password is as simple as creating the file /etc/chrony.keys with a single line:

1 xyzzy

as well as adding the following line somewhere in /etc/chrony.conf:

commandkey 1

The smallest useful configuration file (using IP addresses instead of a hostname) would look something like:

server offline
server offline
server offline
keyfile /etc/chrony.keys
commandkey 1
driftfile /etc/chrony.drift

Telling chronyd an internet connection has been made

For this to work, you'll need to configure the commandkey option in /etc/chrony.conf as shown above. If you've done this, start chronyc and enter the following commands if you are connected to the internet:

chronyc> password xyzzy
200 OK
chronyc> online
200 OK
chronyc> exit

Chrony should now connect to the configured time servers and update your clock if needed.

To tell chrony that you are not connected to the internet anymore, execute the following:

chronyc> password xyzzy
200 OK
chronyc> offline
200 OK
chronyc> exit

In conclusion, don't forget the user guide at /usr/share/doc/chrony/chrony.txt, which is likely to answer any doubts you could still have. It is also available online. See also the related man pages: man {chrony|chronyc|chronyd|chrony.conf}).


Starting chronyd

chronyd runs as a daemon in the background, keeping track of the clock, and waiting for it to be told to go online and synchronize the time with the servers.

Stop the hwclock daemon (if it is running):

# rc.d stop hwclock

Start the chrony daemon:

# rc.d start chrony

Add chrony to your DAEMONS array so it starts automatically on boot and make sure hwclock is disabled:

DAEMONS=(... !hwclock chrony ...)

If you are using systemd instead of initscripts then you can enable the daemon by starting the chrony service using:

# systemctl enable chrony

Then chrony service should start after the next boot. You can start or stop the chrony service at any time using:

# systemctl start/stop chrony

Synchronising chrony hardware clock from the system clock

During boot the initial time is read from the hardware clock (RTC) and the system time is then set, and synchronised over a period of minutes once the chrony daemon has been running for a while. If the hardware clock is out of sync then the initial system time can be some minutes away from the true time. If that is the case it may be necessary to reset the hardware clock. There are two methods. You can set the clock using the hwclock command but in order to do so you must temporarily stop the chrony service:

# systemctl stop chrony

Then set the clock eg:

# hwclock --set --date="12/9/12 18:48:01"

or to set the system clock time into the RTC use:

# hwclock --systohc

Then restart chrony service:

# systemctl start chrony

It is also possible to set the RTC whilst chronyd is running by using the command line chronyc - once at the chronyc prompt use:

# chronyc> password zyxxy
200 OK
chronyc> trimrtc
200 OK
chronyc> quit

Then exit from chronyc and the RTC and system time should be within a few microseconds of each other and should then be approximately correct on boot and fully synchronise a short time later.

Using NetworkManager to let chronyd go online

chronyd can be go into online/offline mode along with a network connection through the use of NetworkManager's dispatcher scripts. You can install networkmanager-dispatcher-chronyAUR from the AUR.


Alternatives to the Chrony, are NTPd, the standard NTP client/daemon for Linux, and OpenNTPD, part of the OpenBSD project and currently not maintained for Linux.

See also

  • Time (for more information on computer timekeeping)

External links