≡ Menu

How to Install and Configure Linux NTP Server and Client

NTP stands for Network Time Protocol.

It is used to synchronize the time on your Linux system with a centralized NTP server.

A local NTP server on the network can be synchronized with an external timing source to keep all the servers in your organization in-sync with an accurate time.

I. Configure NTP server

1. Install NTP Server

First, install NTP package on your server using the appropriate package management tool that is available on your Linux distro.

For example, on RedHat or CentOS, use yum to install ntp as shown below:

yum install ntp

2. Setup Restrict values in ntp.conf

Modify the /etc/ntp.conf file to make sure it has the following two restrict lines.

# 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

The first restrict line allows other clients to query your time server. This restrict line has the following parameters

  • noquery prevents dumping status data from ntpd.
  • notrap prevents control message trap service.
  • nomodify prevents all ntpq queries that attempts to modify the server.
  • nopeer prevents all packets that attempts to establish a peer association.
  • Kod – Kiss-o-death packet is to be sent to reduce unwanted queries

The value -6 in the second line allows forces the DNS resolution to the IPV6 address resolution. For more information on the access parameters list, Please refer to documentation on “man ntp_acc”

3. Allow Only Specific Clients

To only allow machines on your own network to synchronize with your NTP server, add the following restrict line to your /etc/ntp.conf file:

restrict mask nomodify notrap

If the localhost needs to have the full access to query or modify, add the following line to /etc/ntp.conf


4. Add Local Clock as Backup

Add the local clock to the ntp.conf file so that if the NTP server is disconnected from the internet, NTP server provides time from its local system clock.

server # local clock
fudge stratum 10

In the above line, Stratum is used to synchronize the time with the server based on distance. A stratum-1 time server acts as a primary network time standard. A stratum-2 server is connected to the stratum-1 server over the network. Thus, a stratum-2 server gets its time via NTP packet requests from a stratum-1 server. A stratum-3 server gets its time via NTP packet requests from a stratum-2 server, and so on.

Also stratum 0 devices are always used as reference clock.

5. Setup NTP Log Parameters

Specify the drift file and the log file location in your ntp.conf file

driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log

driftfile is used to log how far your clock is from what it should be, and slowly ntp should lower this value as time progress.

6. Start the NTP Serrver

After setting up appropriate values in the ntp.conf file, start the ntp service:

service ntpd start

II. Configure NTP Client to Synchronize with NTP Server

7. Modify ntp.conf on NTP Client

This setup should be done on your NTP Client (Not on NTP-server)

To synchronize the time of your local Linux client machine with NTP server, edit the /etc/ntp.conf file on the client side. Here is an example of how the sample entries looks like. In the following example, you are specifying multiple servers to act as time server, which is helpful when one of the timeservers fails.

server 0.rhel.pool.ntp.org iburst 
server 1.rhel.pool.ntp.org iburst 
server 2.rhel.pool.ntp.org iburst 
server 3.rhel.pool.ntp.org iburst

iburst: After every poll, a burst of eight packets is sent instead of one. When the server is not responding, packets are sent 16s interval. When the server responds, packets are sent every 2s.

Edit your NTP.conf to reflect appropriate entries for your own NTP server.

server prefer

prefer: If this option is specified that server is preferred over other servers. A response from the preferred server will be discarded if it differs significantly different from other server’s responses.

8. Start the NTP Daemon

Once the ntp.conf is configured with correct settings, start the ntp daemon.

/etc/init.d/ntp start

You will see the NTP will slowly start to synchronize the time of your linux machine with the NTP Server.

9. Check the NTP Status

Check the status of NTP using the ntpq command. If you get any connection refused errors then the time server is not responding or the NTP daemon/port is not started or listening.

# ntpq -p
     remote           	refid      st t when poll reach   delay   offset  jitter
*elserver1       3 u  300 1024  377    1.225   -0.071   4.606

10. Set Local Date and Time

The ntpdate command can be used to set the local date and time by polling the NTP server. Typically, you’ll have to do this only one time.

Your jitter value should be low, else check the drift from the clock in the driftfile. You may also need to change to some other NTP server based on the difference. This command synchronizes the time with your NTP server manually.

ntpdate –u

After this initial sync, NTP client will talk to the NTP server on an on-going basis to make sure the local time reflects the accurate time.

You can also use the following command to get the current status of ntpd.

# ntpdc -c sysinfo
system peer:          thegeekstuff.com
system peer mode:     client
leap indicator:       00
stratum:              4
precision:            -23
root distance:        0.00279 s
root dispersion:      0.06271 s
reference ID:         []
reference time:       d70bd07b.f4b5cf2b  Wed, Apr 30 2014 15:41:47.955
system flags:         auth monitor ntp kernel stats
jitter:               0.000000 s
stability:            0.000 ppm
broadcastdelay:       0.000000 s
authdelay:            0.000000 s
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • sacarde June 26, 2014, 1:45 am

    which are differences between “offset” and “delay” ?

    thank you

  • Jalal Hajigholamali June 27, 2014, 11:08 pm


    Very nice and useful article…

  • LnxGnome July 10, 2014, 7:31 am

    You should highlight “if the NTP server is disconnected from the internet”, in step “4. Add Local Clock as Backup”, as the “local clock” should not be used when upstream NTP servers are available.

  • Pouriya Ebrahimzadeh November 26, 2014, 5:18 am

    Thank you.

  • Tadeu May 28, 2015, 10:56 am

    Hello, nice tuto. A quick question, how can i send the time (via ntp off course) using a DHCP server. You know, i have a server with a DHCP server and i want my clients to get the correct time while it’s gets the IP. Thanks

  • Ganesh Pal May 29, 2015, 3:31 am

    Thanks sir nice guide.

  • Karina December 12, 2015, 11:14 am


    Thank you!!

  • ghetef January 7, 2016, 2:17 am

    Thanks! Very good guide.

  • Akash Saxena January 11, 2016, 3:24 am

    The above steps are really helpful to setup a normal NTP Client/Server. Can you please help me to setup a secure NTP Client/Server using autokey option in the same manner.
    Thanks in Advance. 🙂

  • Premnath Bangar February 4, 2016, 10:35 am

    Dear All,

    Please let me know how to configured replication of NTP Server in SuSE and CentOS.

  • Prabaht April 23, 2016, 4:31 am

    [root@localhost ~]# ntpstat
    time server re-starting
    polling server every 64 s
    [root@localhost ~]#

    help to resolve this issue

  • Balamurugan Ganesamoorthy March 1, 2017, 3:06 am

    yeah its working thank u

  • Lloyd Forney March 25, 2017, 5:14 pm

    Well put. A break down of each parameter is very much needed for someone like me who didn’t know these things and plus it now make sense when editing the ntp.conf file.