Sunday, December 6, 2015

HowTo: Verify My NTP Working Or Not

http://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working

I've setup an NTP (Network Time Protocol) client and/or server to manage the system clock over a network. But, how do I verify that it is working correctly? Keeping correct time is important on a server. You can use any one of the following program to verify ntp client configuration:

ntpq - standard NTP query program

ntpstat - show network time synchronisation status

timedatectl - show or set info about ntp using systemd

ntpstat command

The
ntpstat command will report the synchronisation state of the NTP
daemon running on the local machine. If the local system is found to be
synchronised to a reference time source, ntpstat will report the
approximate time accuracy.

exit status

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

exit status 0 - Clock is synchronised.

exit status 1 - Clock is not synchronised.

exit status 2 - If clock state is indeterminant, for example if ntpd is not contactable.

Type the command as follows:$ ntpstat Sample outputs:

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

ntpq command

The
ntpq utility program is used to monitor NTP daemon ntpd operations and
determine performance. The program can be run either in interactive
mode or controlled using command line arguments. Type the following
command$ ntpq -pn OR$ ntpq -p Sample outputs:

-p : Print a list of the peers known to the server as well as a summary of their state.

-n : Output all host addresses in dotted-quad numeric format rather than converting to the canonical host names.

A note about timedatectl command

If you are using systemd based system, run the following command to check the service status# timedatectl status Sample outputs:

Fig.01: Is my NTP (systemd-timesyncd) Working?

systemd-timesyncd configuration

If NTP enabled is set to No. Try configuring by editing /etc/systemd/timesyncd.conf file as follows:# vi /etc/systemd/timesyncd.conf
Append/edit [Time] as follows i.e. add time servers or change the
provided ones, uncomment the relevant line and list their host name or
IP separated by a space (default from my Debian 8.x server):