How to check if time is synced fine with NTP server in linux ?
Today we will see how to check if the time is synced fine with the NTP server.
We will understand if the time is synced and what is the difference between local & remote time.
Lets see how to check it step by step.
1. First check if our local time/clock is synchronized or not.
[root@ngelinux001 ~]# ntpstat synchronised to NTP server (10.207.0.8) at stratum 3 time correct to within 31 ms polling server every 512 s [root@ngelinux001 ~]# ### The output should not be like below. [root@ngelinux001 ~]# ntpstat unsynchronised time server re-starting polling server every 64 s
2. Check the difference between local and remote clock it should not be more than .5s.
[root@ngelinux001 ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== +ntp-NGEL1.ind 139.99.160.20 2 u 464 512 377 0.420 -0.120 0.092 *ntp-NGEL2.ind 139.99.160.20 2 u 29 512 377 0.414 -0.104 0.128 [root@ngelinux001 ~]#
Offset shows how much is the difference between local and remote time.
3. Verify service status.
[root@ngelinux001 ~]# service ntpd status ntpd (pid 16527) is running...
4. Check service config file.
[root@ngelinux001 ~]# cat /etc/ntp.conf # For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). driftfile /var/lib/ntp/drift # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 restrict -6 ::1 # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #broadcast 192.168.1.255 autokey # broadcast server #broadcastclient # broadcast client #broadcast 224.0.1.1 autokey # multicast server #multicastclient 224.0.1.1 # multicast client #manycastserver 239.255.254.254 # manycast server #manycastclient 239.255.254.254 autokey # manycast client # Enable public key cryptography. #crypto includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. keys /etc/ntp/keys # Specify the key identifiers which are trusted. #trustedkey 4 8 42 # Specify the key identifier to use with the ntpdc utility. #requestkey 8 # Specify the key identifier to use with the ntpq utility. #controlkey 8 # Enable writing of statistics records. #statistics clockstats cryptostats loopstats peerstats driftfile /var/lib/ntp/ntp.drift server ntp-NGEL1 server ntp-NGEL2 [root@ngelinux001 ~]#
5. Telnet works on UDP 123 port.
See it must respond and reject connection, should not hang waiting to hear.
[root@ngelinux001 ~]# telnet ntp-NGEL1 123 Trying 10.207.0.7... telnet: connect to address 10.207.0.7: Connection refused [root@ngelinux001 ~]# telnet ntp-NGEL2 123 Trying 10.207.0.8... telnet: connect to address 10.207.0.8: Connection refused [root@ngelinux001 ~]#
So in our case, all is fine.
In case you have issue with service, just give it a restart.