How to configure a Linux machine to get time from a Chrony server

Home > Search > How-to
  by

In this tutorial, we will configure one of our Linux machines to get time from a local Chrony Network Time Protocol (NTP) server.

Use the timedatectl command to verify that NTP is not enabled, you are not synchronized with your local NTP server, and that the local time may be incorrect.

[root@server1 ~]# timedatectl
Local time       : Mon 2016-01-01 00:01:01 CDT
. . .
NTP enabled      : yes
NTP synchronized : yes

 

Use apt-get or yum to install Chrony.

[root@server1 ~]# apt-get install chrony
[root@server1 ~]# yum install chrony

 

Configure chronyd to automatically start if the machine is rebooted.

[root@server1 ~]# systemctl enable chronyd.service

 

PIng the local NTP server, to ensure the client can communicate with the local NTP server. Replace "ntp.example.com" with the domain name or IP address of your local NTP server.

[root@server1 ~]# ping -c4 ntp.example.com
64 bytes from ntp.example.com (192.168.0.3): icmp_seq=1 ttl=64 time=0.321 ms
64 bytes from ntp.example.com (192.168.0.3): icmp_seq=2 ttl=64 time=0.234 ms
64 bytes from ntp.example.com (192.168.0.3): icmp_seq=3 ttl=64 time=0.261 ms
64 bytes from ntp.example.com (192.168.0.3): icmp_seq=4 ttl=64 time=0.306 ms

 

In the /etc/chrony.conf file, comment out the 4 pool NTP pool servers, and then add peer ntp_server (example: peer ntp.example.com). Peer configures the client to use the local NTP server for time.

#server 0.distro.pool.ntp.org iburst
#server1.distro.pool.ntp.org iburst
#server2.distro.pool.ntp.org iburst
#server3.distro.pool.ntp.org iburst
peer ntp.example.com

 

Restart the chronyd service, and ensure chronyd is active and running.

[root@server1 ~]# systemctl restart chronyd
[root@server1 ~]# systemctl status chronyd

 

Use the chronyc sources command to verify that the changes made to the /etc/chrony.conf file have taken effect. The NTP server should have a collection of external NTP servers. The client machines should only display the IP address of the internal NTP server.

[root@server1 ~]# chronyc sources
210 Number of sources = 4MS Nmae/IP address   Stratum  Poll  Reach  LastRx  Last sample
==============================================================================
? ntp.example.com         2    10    377     160  +5942us[-1824us] +/-  48ms

 

Use the chronyc tracking command to verify that the both VMs are synchronized.  If Leap status is “normal”, you are synchronized.  On the other hand, if leap status is “not synchronized”, you are not synchronized. After editing the /etc/chrony.conf file, it can take a few minutes for the client to synchronize with the NTP server.

[root@server1 ~]# chronyc tracking
. . .
Leap status : Normal

 

Use the timedatectl command to verify that NTP is enabled, you are synchronized with your local NTP server, and that the local time is correct.

[root@server1 ~]# timedatectl
Local time       : Mon 2016-01-01 00:01:01 CDT
. . .
NTP enabled      : yes
NTP synchronized : yes

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments