≡ Menu

Debian / Ubuntu Linux Install NTPD To Synchronism Clock With Internet Standard Time Servers

Q. How do I install and configure NTP ( Network Time Protocol ) daemon to keep my dedicated servers clock in sync?

A. ntpd is an operating system daemon which sets and maintains the system time-of-day in synchronism with Internet standard time servers. Ntpd is a complete implementation of the Network Time Protocol (NTP) version 4 but also retains compatibility with version 3.

Install ntp server

Type the following command:
# apt-get install ntp
Sample output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
Suggested packages:
The following NEW packages will be installed:
  libcap1 ntp
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 443kB of archives.
After this operation, 1126kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.us.debian.org lenny/main libcap1 1:1.10-14 [9082B]
Get:2 http://ftp.us.debian.org lenny/main ntp 1:4.2.4p4+dfsg-7 [434kB]
Fetched 443kB in 0s (480kB/s)
Selecting previously deselected package libcap1.
(Reading database ... 20411 files and directories currently installed.)
Unpacking libcap1 (from .../libcap1_1%3a1.10-14_i386.deb) ...
Selecting previously deselected package ntp.
Unpacking ntp (from .../ntp_1%3a4.2.4p4+dfsg-7_i386.deb) ...
Processing triggers for man-db ...
Setting up libcap1 (1:1.10-14) ...
Setting up ntp (1:4.2.4p4+dfsg-7) ...
Starting NTP server: ntpd.

Configure NTP server

/etc/ntp.conf is default configuration file. NTP uses UDP port 123 as its transport layer. It is designed particularly to resist the effects of variable latency by using a jitter buffer.
# vi /etc/ntp.conf
The default configuration will sync to various low-stratum NTP servers. You can set server as follows:

server 0.debian.pool.ntp.org iburst dynamic
server 1.debian.pool.ntp.org iburst dynamic
server 2.debian.pool.ntp.org iburst dynamic
server 3.debian.pool.ntp.org iburst dynamic

Once file updaed, restart ntp:
# /etc/init.d/ntp restart

ntpq – NTP query program

You can use ntpq to list the servers that you are currently polling:
$ ntpq
Sample output:

ntpq> peer
     remote           refid      st t when poll reach   delay   offset  jitter
*time.nist.gov   .ACTS.           1 u  128   64  376   64.616   -8.079   0.863
+iguana.igtc.com    2 u   19   64  377    9.105   -9.229   0.543
+hydrogen.cert.u  2 u   12   64  377   35.950   -7.184   0.438
-snag.rack911.co    3 u   50   64  377   33.782   -0.376   0.464

Alternatively, you can type the following to find out if ntp is working or not:
$ ntpq -p
Sample output:

     remote           refid      st t when poll reach   delay   offset  jitter
*time.nist.gov   .ACTS.           1 u    3   64  373   64.616   -8.079   0.716
+iguana.igtc.com    2 u   28   64  377    9.065   -9.429   0.628
+hydrogen.cert.u  2 u   19   64  377   35.950   -7.184   0.357
-snag.rack911.co    3 u   57   64  377   33.695   -0.893   0.645

Further readings:

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 6 comments… add one }
  • spirals (Dave J Aldridge sysop) August 20, 2009, 6:46 pm

    Thank you for the info on ntp setup.

  • Dean November 11, 2009, 4:53 pm

    Thanks – very helpful, clean and simple

  • Vivek Kapoor September 21, 2010, 6:03 pm

    I must say, you are maintaining a pretty good website having not-so-trivial details so easily accessible. Thank you much for it.

  • woo March 21, 2012, 10:19 pm

    correction: it’s
    ntpq -p
    to print out the peers

  • Programster August 18, 2014, 7:02 pm

    Perfectly short and sweet.

  • Radhika October 28, 2015, 10:56 am

    Hi, I have updated the ntp.conf as per the steps here and my NTP server is running in a Windows 2008 machine. The output of ntpq pe is
    remote refid st t when poll reach delay offset jitter
    ============================================================================== .LOCL. 1 u 15 16 377 0.713 2613780 10.556

    I had changed the date in my Linux machine to check if NTP is working or not. My Linux machine is not synching up with my NTP server, even after the .conf file is edited. Can you please help?

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , ,