How to check ntp sync in linux from client to server using ntpstat and timedatectl utility on rhel / centos /ubuntu
Check ntp sync in linux with ntpstat
[root@makeuseoflinux ~]# ntpstat
synchronised to NTP server (143.244.134.227) at stratum 4
time correct to within 93 ms
polling server every 64 s
We can also use timedateclt to verify the status of ntp sync
[root@makeuseoflinux ~]# timedatectl
Local time: Thu 2022-02-17 09:30:59 IST
Universal time: Thu 2022-02-17 04:00:59 UTC
RTC time: Thu 2022-02-17 04:00:59
Time zone: Asia/Kolkata (IST, +0530)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
[root@makeuseoflinux ~]# timedatectl status
Local time: Thu 2022-02-17 09:31:03 IST
Universal time: Thu 2022-02-17 04:01:03 UTC
RTC time: Thu 2022-02-17 04:01:03
Time zone: Asia/Kolkata (IST, +0530)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Sometimes above commands may not work as expected if the client is not able to communicate to ntp servers. Since ntp work on 123/udp, we can use netcat to test the connectivity of ntp server.
[root@makeuseoflinux ~]# nc -v -z -u 165.22.211.200 123
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connected to 165.22.211.200:123.
Ncat: UDP packet sent successfully
Ncat: 1 bytes sent, 0 bytes received in 2.01 seconds.
Curl can also be used to check connectivity where netcat is not available.
# curl -v telnet://165.22.211.200:443
* Rebuilt URL to: telnet://165.22.211.200:443/
* Trying 165.22.211.200...
* TCP_NODELAY set
* Connected to 165.22.211.200 (165.22.211.200) port 443 (#0)
Conclusion
We have verified ntp sync from client to the ntp server and also we have tested the connectivity of ntp on udp port 123.