http://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/
HowTo: Verify My NTP Working Or Not
by VIVEK GITEon MARCH 25, 2010 last updated NOVEMBER 29, 2015
in LINUX, NETWORKING, UNIX
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?
You can use any one of the following program to verify ntp client configuration:
ntpq - standard NTP query programntpstat - show network time synchronisation statustimedatectl - 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
Use the echo command to display exit status of ntp client:
$ echo $?
Sample outputs:
0
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:
remote refid st t when poll reach delay offset jitter ============================================================================== *dione.cbane.org 204.123.2.5 2 u 509 1024 377 51.661 -3.343 0.279 +ns1.your-site.c 132.236.56.252 3 u 899 1024 377 48.395 2.047 1.006 +ntp.yoinks.net 129.7.1.66 2 u 930 1024 377 0.693 1.035 0.241 LOCAL(0) .LOCL. 10 l 45 64 377 0.000 0.000 0.001
The above is an example of working ntp client. Where,
-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):
[Time] Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
Save and close the file. Finally, start and enable it, run:
# timedatectl set-ntp true
# timedatectl status
Recommend readings:
TwitterFacebookGoogle+Download PDF version Found an error/typo on this page?
More like this:Debian / Ubuntu Linux Install NTPD To Synchronism Clock With Internet…What are the exit statuses of ssh command?Ubuntu Linux how to set the date and time via Network Time Protocol (NTP)Bourne Shell Exit Status ExamplesHP-UX UNIX Configure an NTP ServerShell: How to determine the exit status of Linux and UNIX commandCentOS / Red Hat Configure an NTP Client And ServerCentOS / Redhat Linux: Install OpenNTPD To Synchronize The Local ClockCentOS Linux Install and Configure NTP to Synchronize The System ClockBash: Find out the exit codes of all piped commands
{ 5 comments… add one }
Philippe Petrinko
Informative and simple. Thanks Vivek
Wes
You should fix this typo:
>> “exit status 1 – Cock is not synchronised.”
Thanks for the heads up. The faq has been updated.
Philippe Petrinko
Hi Vivek,
Recommend readings link seems to be broken:
“man ntpq”
http://www.manpager.com/linux/man8/ntpq.8.html
I guess you may want to recommend:
http://linux.die.net/man/8/ntpd
https://en.wikipedia.org/wiki/Ntpd
http://www.eecis.udel.edu/~mills/ntp/html/ntpq.html
http://support.ntp.org/bin/view/Support/TroubleshootingNTP
https://en.wikipedia.org/wiki/Ntpd
http://www.unix.com/man-page/freebsd/8/ntpq/
http://www.kossboss.com/linux—maintaining-time-on-debian—datetime-and-ntp-client-and-server
Hi Philippe,
The post has been updated. As always, I appreciate your feedback and time :)
Leave a Comment
Name *
Email *
Comment
Tagged with: client configuration, echo command,network time protocol, ntp, ntp daemon, ntp network,ntpd, ntpq, ntpq command, ntpstat, ntpstat command,system clock, systemd, time accuracy, time synchronisation, Easy
Next FAQ: Linux / UNIX: Encrypt Backup Tape Using Tar & OpenSSL
Previous FAQ: Linux Kernel Recompile: Do I Have To Recompile All Installed Applications
Featured Articles:
30 Cool Open Source Software I Discovered in 201330 Handy Bash Shell Aliases For Linux / Unix / Mac OS XTop 30 Nmap Command Examples For Sys/Network Admins25 PHP Security Best Practices For Sys Admins20 Linux System Monitoring Tools Every SysAdmin Should Know20 Linux Server Hardening Security TipsLinux: 20 Iptables Examples For New SysAdminsTop 20 OpenSSH Server Best Security PracticesTop 20 Nginx WebServer Best Security Practices20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors15 Greatest Open Source Terminal Applications Of 2012My 10 UNIX Command Line MistakesTop 10 Open Source Web-Based Project Management SoftwareTop 5 Email Client For Linux, Mac OS X, and Windows UsersThe Novice Guide To Buying A Linux Laptop
Follow Us
©2000-2015 nixCraft. All rights reserved. Privacy -Terms of Service - Questions or Comments