Score:2

how to verify the setting of linux ntp client?

cn flag

I'm currently managing some RHEL 7.9 hosts which need to sync time to NTP server and only the ntpd can be utilized for time sync.

I did the following configurations in OS but not sure whether the result indicting they're correct or not.

  1. the time server in the environment is 192.168.30.200
  2. in the /etc/ntp.conf file, the parameters were written: server 192.168.30.200 and restrict 192.168.30.200
  3. command chkconfig ntpd on to start the ntpd.
  4. command ntpdate -dv 192.168.30.200 to do time sync (is it the command to sync time immediately?) and the output is below:
7 Nov 13:51:42 ntpdate[128853]: ntpdate [email protected] Mon Jun  1 11:18:15 UTC 2020 (1)
Looking for host 192.168.30.200 and service ntp
host found : 192.168.30.200
transmit(192.168.30.200)
receive(192.168.30.200)
transmit(192.168.30.200)
receive(192.168.30.200)
transmit(192.168.30.200)
receive(192.168.30.200)
transmit(192.168.30.200)
receive(192.168.30.200)
server 192.168.30.200, port 123
stratum 4, precision -23, leap 00, trust 000
refid [192.168.30.200], delay 0.02632, dispersion 0.00005
transmitted 4, in filter 4
reference time:    e7131a05.fd12bbc4  Mon, Nov  7 2022 13:45:41.988
originate timestamp: e7131b75.00e9ce65  Mon, Nov  7 2022 13:51:49.003
transmit timestamp:  e7131b75.004901f8  Mon, Nov  7 2022 13:51:49.001
filter delay:  0.02666  0.02657  0.02632  0.02663
         0.00000  0.00000  0.00000  0.00000
filter offset: 0.001956 0.001816 0.001894 0.001940
         0.000000 0.000000 0.000000 0.000000
delay 0.02632, dispersion 0.00005
offset 0.001894

 7 Nov 13:51:49 ntpdate[128853]: adjust time server 192.168.30.200 offset 0.001894 sec

is the output meaning that the time server is operating and time has been synced on ntp clients?

Score:2
vi flag

7 Nov 13:51:49 ntpdate[128853]: adjust time server 192.168.30.200 offset 0.001894 sec

This line means you had 0.001894 seconds offset from the NTP server.

I'm currently managing some RHEL 7.9 hosts which need to sync time to NTP server and only the ntpd can be utilized for time sync.

If your ntpd service is enabled and its status is started, your time will be synced automatically. You can check service status with something like this:

sudo systemctl status ntpd
Score:2
co flag

ntpdate does not use the local ntpd daemon. You can run it without ntpd installed, configured or running. It does a one-time sync, sets the time, and exits.

In your case, since you added -d, it actually doesn't even set the time.

The tool to query the status of ntpd is ntpq. What you are probably looking for is ntpq -p, which will list the current peers/servers, along with a bit of information about them, like their stratum (how far away they are from a really good clock), when it was last seen, how often it is polled, reachability, delay, offset and jitter. It also tells you which server is currently used as a reference.

Example:

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+dedibox.demonge 145.238.203.14   2 u  916 1024  377    5.333   -0.549   2.322
+ns.daupheus.com 145.238.203.14   2 u 1020 1024  377    5.433   -0.408   0.485
*82-64-45-50.sub .GPS.            1 u  777 1024  377   14.359   -0.669   0.353
+ip139.ip-5-196- 145.238.203.14   2 u  213 1024  377    2.188   -0.723   0.758
-time.cloudflare 10.20.8.4        3 u  664 1024  377    5.483    0.066   0.398
+194.169.214.72  17.253.108.125   2 u  940 1024  377    5.915   -0.459   0.443

The current active reference is the one with the *, which derives its time from GPS, and is stratum 1. There are a few other alternates + at stratum 2 (they derive their time from another server which is stratum 1), and so on.

Score:1
ma flag

Yep, it is synced enough.


If you just want to have the information about whatever local machine is synced or not, you can use ntpstat.

The ntpstat command will report the synchronization state of the NTP daemon 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.

exit status of ntpstat command

You can use the exit status to verify its operations from a shell script or command line itself:

  • exit status 0: clock is synchronized
  • exit status 1: clock is not synchronized
  • exit status 2: clock state is unknown, for example if ntpd is not reachable

Sample outputs

$ ntpstat
synchronised to NTP server (149.20.54.20) at stratum 3 
   time correct to within 42 ms
   polling server every 1024 s


$ echo $?
0
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.