How to syncronize time in Linux (using ntp, openntpd, systemd-timesyncd and chrony)

Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks. The protocol is usually described in terms of a client-server model, but can as easily be used in peer-to-peer relationships where both peers consider the other to be a potential time source. There are a number of implementations.

  • ntpd@man deamon implementation of NTP which sets and maintains the system time of day in synchronism with Internet standard time servers.
## install
$ sudo yum install ntp | sudo apt-get install ntp

## configure NTP server, add servers from
$ cat /etc/ntp.conf

## start service
$(el7) systemctl start ntpd ; systemctl enable ntpd ; sytemctl status ntp
$(el6) service ntpd start ; chkconfig ntpd on
$(deb) /etc/init.d/ntp start

## check logs '/var/log/ntp.log', verify date
$ ntpq -p ; date -R

## manually sync
$ ntpdate -u

from ntp@centos and ntp@debian

  • OpenNTPD/OpenNTPD@wiki is an attempt by the OpenBSD team to produce an NTP daemon implementation that is secure, simple to security audit, trivial to set up and administer, and has small memory requirement that synchronizes local clock on the computer with remote NTP server with reasonable accuracy. It’s an alternative to default default NTPD client/server.
## install (from source)
$ wget -O - | tar -xz
$ cd $1 ; ./configure ; make ; sudo make install
$ groupadd _ntp
$ useradd -g _ntp -s /sbin/nologin -d /var/empty -c 'OpenNTP daemon' _ntp
$ cp contrib/redhat/ntpd /etc/init.d/openntpd
$ chmod +x /etc/init.d/openntpd
$ cat /etc/init.d/openntpd

## or install (from repo)
$ sudo apt-get install openntpd (deb/ubuntu)

## configure
$ cat /usr/local/etc/ntpd.conf
listen on
# Use a random selection of 8 public stratum 2 servers
$ chkconfig openntpd on ; service openntpd start
$ tail -f /var/log/messages
$ netstat -tulpn | grep :123

from CentOS / Redhat Linux: Install OpenNTPD To Synchronize The Local Clock

  • systemd-timesyncd is a daemon that has been added for synchronizing the system clock across the network. It implements an SNTP client. In contrast to NTP implementations such as chrony or the NTP reference server this only implements a client side, and does not bother with the full NTP complexity.
## systemd-timesyncd service is available with systemd >= 213 (el7 uses 208), to start and enable it
$ timedatectl set-ntp true

## configuration
# to add time servers or change the provided ones, uncomment the relevant line and list their host name or IP separated by a space
$ cat /etc/systemd/timesyncd.conf

from systemd-timesyncd@arch

  • chrony@arch is an alternative NTP client and server roaming friendly and designed specifically for systems that are not online all the time.
## install
$ sudo yum install chrony | sydo apt-get install chrony

## configure
'offline' only poll when chronyc is online
'auto_offline' assume server gone offline when 2 requests without reply
'iburst' on start make four measurements over short period (rather than the usual periodic measurements)
'minstratum' increase stratum of the source to a minimum, to avoid being selected; chronyd preferes lower stratum sources
'polltarget' num of measurements used in regression algorithm; higher target means shorter polling intervals
'prefer' prefer this source over sources without prefer option.
'noselect' never select this source

$ cat /etc/chrony.conf
server offline
server offline
server offline
driftfile /etc/chrony.drift
keyfile /etc/chrony.keys
commandkey 1
$ systemctl restart chronyd

# show current sources
$ chronyc sources -v
# show rate and offset estimation performance of sources
$ chronyc sourcestats
# show system clock performance
$ chronyc tracking
# set offline/activity; also done automatically by 'networkmanager-dispatcher-chrony' or 'netctl-dispatcher-chrony'
$ chronyc -a activity

from Maintaining System clock using chrony


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s