How to check NTP status in RHEL 8

NTP stand for Network Time Protocol, which synchronizes the clock between computer systems over the network.

NTP server keep all the servers in-sync with accurate time to perform time based jobs in an organization. NTP client will synchronize its clock to the network time server.

We already wrote an article about NTP Server, Client installation and configuration. If you would like to check these articles, navigate to the following links:

I’m assuming that we have setup the NTP server and NTP client by referring to the above links. In this guide, we will show you how to verify whether the NTP setup is working or not?

NTP sync status can be verified using the following three commands:

  • ntpq: ntpq is standard NTP query program.
  • ntpstat: It shows network time synchronization status.
  • timedatectl: It controls the system time and date in systemd system.

Let’s understand each of the commands in detail.

Method-1: Checking the status of NTP using ntpq command

The ‘ntpq’ command is used to monitor NTP daemon and determine the performance, which can be identified by querying the NTP servers running on the host.

It runs either in interactive mode or by using command-line arguments. It prints a list of connected peers by sending multiple queries to the server.

If NTP is working properly, you should get the below output:

# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *CentOS7.2daygee 133.243.238.163 2 u 14 64 37 0.686 0.151 16.432

Details:

  • -p: Print a list of the peers known to the server as well as a summary of their state.
  • remote: Remote NTP server
  • st: The stratum of the remote peer
  • t: Type of the peer (local, unicast, multicast or broadcast)
  • when: Time the last packet was received, the polling interval (seconds)
  • poll: How frequently to query server (in seconds)
  • reach: Octal bitmask of success or failure of last 8 queries.
  • delay: Network round trip time (in milliseconds)
  • offset: Difference between local clock and remote clock (in milliseconds)
  • jitter: Difference of successive time values from server

Method-2: How to check NTP status using ntpstat command

ntpstat will report the synchronization state of the NTP daemon (ntpd) running on the local machine.

If the local system is found to be synchronized to a reference time source, ntpstat will report the approximate time accuracy.

The ntpstat command returns three types of status codes based on the NTP sync as mentioned below:

  • 0: It returns 0, if clock is synchronised.
  • 1: It returns 1, if clock is not synchronised.
  • 2: It returns 2, if clock state is indeterminant, for example if ntpd is not contactable.
# ntpstat synchronised to NTP server (192.168.1.8) at stratum 3 time correct to within 508 ms polling server every 64 s

Method-3: Checking NTP sync status with timedatectl command

timedatectl command is used to query and change the system clock and its settings in systemd system:

# timedatectl or # timedatectl status Local time: Thu 2019-05-30 05:01:05 CDT Universal time: Thu 2019-05-30 10:01:05 UTC RTC time: Thu 2019-05-30 10:01:05 Time zone: America/Chicago (CDT, -0500) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: yes Last DST change: DST began at Sun 2019-03-10 01:59:59 CST Sun 2019-03-10 03:00:00 CDT Next DST change: DST ends (the clock jumps one hour backwards) at Sun 2019-11-03 01:59:59 CDT Sun 2019-11-03 01:00:00 CST

Bonus Tips:

Chrony is replacement of NTP client. It can synchronize the system clock faster with better time accuracy and it can be very much useful for the systems which are not online all the time.

Chronyd is smaller in size, it uses less system memory and it wakes up the CPU only when necessary, which is better for power saving.

It can perform well, even when the network is congested for longer periods of time. You can use any of the below commands to check Chrony status:

# chronyc tracking Reference ID : C0A80105 (CentOS7.2daygeek.com) Stratum : 3 Ref time (UTC) : Thu Mar 28 05:57:27 2019 System time : 0.000002545 seconds slow of NTP time Last offset : +0.001194361 seconds RMS offset : 0.001194361 seconds Frequency : 1.650 ppm fast Residual freq : +184.101 ppm Skew : 2.962 ppm Root delay : 0.107966967 seconds Root dispersion : 1.060455322 seconds Update interval : 2.0 seconds Leap status : Normal

Run the sources command to display information about the current time sources:

# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* CentOS7.2daygeek.com 2 6 17 62 +36us[+1230us] +/- 1111ms

Conclusion

In this guide, you learned how to check NTP synchronize status on linux using three different commands.

If you have any questions, feel free to leave a comment. We will get back to you as soon as possible.

In CentOS/RHEL 8, ntp is no longer supported. chrony is enabled by default. For this reason, you might need to migrate from ntp to chrony.

Note: In CentOS/RHEL 7 users had a choice to between ntp and chrony. But Starting from CentOS/RHEL 8, they have to use chrony instead of ntp.

In standard CentOS/RHEL 8 servers, chrony should be installed and active already. It can be verified by executing:

# systemctl status chronyd ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2021-01-25 16:31:25 GMT; 2 days ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 1401 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS) Process: 1388 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 1397 (chronyd) Tasks: 1 (limit: 100197) Memory: 2.0M CGroup: /system.slice/chronyd.service └─1397 /usr/sbin/chronyd

The chronyc command can be used as the client, for example to check for the existing sources with:

# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* xxx.xxx.xxx.xxx 2 10 377 130 -40us[ -71us] +/- 36ms

And in the unlikely event that chrony is not installed, the package can be installed via yum, by installing chrony:

NTP vs Chrony

Below is an summary of comparison between NTP and chrony:

ntp name chrony name
/etc/ntp.conf /etc/chrony.conf
/etc/ntp/keys /etc/chrony.keys
ntpd chronyd
ntpq chronyc
ntpd.service chronyd.service
ntp-wait.service chrony-wait.service

Migrating from NTP to chrony

RedHat provides a nice script which can directly convert your NTP settings to chrony. The script /usr/share/doc/chrony/ntp2chrony.py in included by default along with chrony in CentOS/RHEL 8. The script automatically converts an existing ntp configuration to chrony.

Below is an example of converting your NTP configuration to chrony using the script:

# python3 /usr/share/doc/chrony/ntp2chrony.py -b -v Reading /etc/ntp.conf Reading /etc/ntp/crypto/pw Reading /etc/ntp/keys Writing /etc/chrony.conf Writing /etc/chrony.keys

Here,
-b – backups original /etc/chrony.conf or /etc/chrony.keys before making any changes.
-v – versbose printing.

Any unsupported directives from ntp.conf are included in the chrony.conf as comments.

Having an accurate system time on a Linux server is very important because of several system components such as Cron and Anacron, backup scripts and much more work based on time. Accurate timekeeping can be achieved using the Network Time Protocol (NTP) protocol.

NTP is an old, widely known and cross-platform protocol designed to synchronize the clocks of computers over a network. It commonly synchronizes a computer to Internet time servers or other sources, such as a radio or satellite receiver or telephone modem service. It can also be used as a time source/server for client systems.

In RHEL Linux 8, the ntp package is no longer supported and it is implemented by the chronyd (a daemon that runs in user-space) which is provided in the chrony package.

chrony works both as an NTP server and as an NTP client, which is used to synchronize the system clock with NTP servers, and can be used to synchronize the system clock with a reference clock (e.g a GPS receiver).

It is also used to synchronize the system clock with a manual time input, and as an NTPv4 server or peer to provide a time service to other computers in the network.

Read Also: How to Install and Use Chrony in Linux

In this article, we will show you how to install and configure the NTP server and client using chrony package in RHEL 8 Linux distribution.

Test Environment:

NTP Server - RHEL 8: 192.168.56.110 NTP Client - CentOS 7: 192.168.56.109

How to Install Chrony in RHEL 8

To install the chrony suite, use the following DNF package manager as follows. This command will install a dependency called timedatex.

# dnf install chrony
How to check NTP status in RHEL 8
Install Chrony in RHEL 8

The chrony suite consists of chronyd, and chronyc, a command line utility which is used to change various operating parameters and to monitor its performance whilst it is running.

Now start the chronyd service, enable it to auto start at system boot and verify the running status using the following systemctl commands.

# systemctl start chronyd # systemctl status chronyd # systemctl enable chronyd
How to check NTP status in RHEL 8
Start Chonyd in RHEL 8

How to Configure NTP Server Using Chrony in RHEL 8

In this section, we will show how to set up your RHEL 8 server a master NTP time server. Open the /etc/chrony.conf configuration file using any of your favorite text-based editor.

# vi /etc/chrony.conf

Then look for the allow configuration directive and uncomment it and set its value to the network or subnet address from which the clients are allowed to connect.

allow 192.168.56.0/24

Save the file and close it. Then restart the chronyd service configuration to apply the recent changes.

# systemctl restart chronyd

Next, open access to the NTP service in firewalld configuration to allows for incoming NTP requests from clients.

# firewall-cmd --permanent --add-service=ntp # firewall-cmd --reload

How to Configure NTP Client Using Chrony in RHEL 8

This section shows how to configure chrony as a direct NTP client in our CentOS 7 server. Start by installing the chrony package using the following yum command.

# yum install chrony
How to check NTP status in RHEL 8
Install Chrony in CentOS 7

Once installed, you can start, enable and verify the chronyd service status using the following systemctl commands.

# systemctl start chronyd # systemctl enable chronyd # systemctl status chronyd

Next, you need to configure the system as a direct client of the NTP server. Open the /etc/chrony.conf configuration file with a text-base editor.

# vi /etc/chrony.conf

To configure a system as an NTP client, it needs to know which NTP servers it should ask for the current time. You can specify the servers using the server or pool directive.

So comment out the default NTP servers specified as the value of the server directive, and set your RHEL 8 server’s address instead.

server 192.168.56.110
How to check NTP status in RHEL 8
Configure NTP Client on CentOS 7

Save the changes in the file and close it. Then restart the chronyd service configurations for the recent changes to take effect.

# systemctl restart chronyd

Now run the following command to show the current time sources (NTP server) that chronyd is accessing, which should be your NTP server address.

# chronyc sources
How to check NTP status in RHEL 8
Check Time Sources on NTP Client

On the server, run the following command to display information about NTP clients assessing the NTP server.

# chronyc clients
How to check NTP status in RHEL 8
Check NTP Clients Accessing the NTP Servers

For more information on how to use the chronyc utility, run the following command.

# man chronyc

That’s all! In this article, we have shown how to install and configure an NTP server in RHEL 8 using chrony suite. We also showed how to configure an NTP client on CentOS 7.

If you have any questions about this article, use the comment form below to ask any questions or queries.

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

How to check NTP status in RHEL 8

We are thankful for your never ending support.