top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How we can Install and Configure Linux NTP Server and Client?

+2 votes
99 views
How we can Install and Configure Linux NTP Server and Client?
posted Nov 6, 2015 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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 192.168.1.0 mask 255.255.255.0 nomodify notrap

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

restrict 127.0.0.1

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  127.127.1.0 # local clock
fudge   127.127.1.0 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 19.168.1.1 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  19.168.1.1       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 19.168.1.1

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:         [19.168.1.1]
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
answer Dec 21, 2015 by Manikandan J
Similar Questions
+6 votes

I want to write NTP client which sends and receives NTP packet to NTP server and should read the value from one of the four offsets and convert it to user readable local or GMT time format, I specifically want to know which offsets should I read in order to get correct timestamp from the packet.

Any suggestions?

+3 votes

How to set up timing if NTP was block by ISP? I have try many way such as link the timezone , getting from the hardware clock. However, it is not the solution.

Please advice.

+2 votes

When there is a need to update our machine time, we use NTP update. Is there any public NTP server available which can serve all the requests coming from clients located around the globe ? Or Is a dedicated NTP server required for each geographical location ?

+1 vote

I would like to sync my CentOS 6.3 hardware clock time to my NTP server's time. Can I do that without reboot the hosts?

Does anyone has the steps to do that?

+4 votes

I am running Fedora 20 x86_64. Its on a private network not connected to the Internet, and with no NTP server. When I shut down the machine, it pauses for more than a minute at a stop job is running for NTP client/server. I dont think I enabled NTP when I installed it, but Ive done

systemctl disable ntpd.service 

and the same for ntpdate and sntp, but it still pauses for that stop job. Why is it doing that, and what can I do to make it skip that?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...