How to set up time server in linux

The Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks. NTP uses UDP port 123 as its transport layer. It is designed particularly to resist the effects of variable latency (Jitter). 

Please also refer 

How to Install and Configure The Network Time Protocol

How to Sync date and time via NTP server

Using NTP is a great way to keep your system clock set correctly. It works by contacting a number of servers  around the world, asking them for the time and then calculating what the correct local time is from their responses.

Install NTP server in Debian

#apt-get install ntp ntpdate ntp-server

This will install all the required packages for NTP

Configuring NTP Server

By Default main configuration file located at /etc/ntp.conf

Default configuration file looks like below 

#/etc/ntp.conf, configuration for ntpd

driftfile /var/lib/ntp/ntp.drift
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example

# pool.ntp.org maps to more than 300 low-stratum NTP servers.
# Your server will pick a different set every time it starts up.
# *** Please consider joining the pool! ***
# *** ***
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

# By default, exchange time with everybody, but don't allow configuration.
# See /usr/share/doc/ntp-doc/html/accopt.html for details.

restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.

restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access,
# but only if cryptographically authenticated
#restrict 192.168.123.0 mask 255.255.255.0 notrust

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet,
# de-comment the next lines. Please do this only if you trust everybody
# on the network!
#disable auth
#broadcastclient

Example Configuration

You need to add a number of servers to the server list. The Debian default is pool.ntp.org which works but isn’t always amazingly accurate because it makes no attempt to use time servers near you. If you want more accuracy use the time servers either on your continent (for instance europe.pool.ntp.org) or your country (for instance uk.pool.ntp.org) one of your local country servers.The optimal number of servers to listen to is three but two will also give a good accuracy. If your ISP runs a time server for you it is worth including it in your server list as it will often be more accurate than the pooled servers and will help keep the load down on the pool.

I am using the following two servers for my configuration

server ntp0.pipex.net
server ntp1.pipex.net

Restrict the type of access you allow these servers. In this example the servers are not allowed to modify the run-time configuration or query your Linux NTP server.

restrict otherntp.server.org mask 255.255.255.255 nomodify notrap noquery
restrict ntp.research.gov mask 255.255.255.255 nomodify notrap noquery

The mask 255.255.255.255 statement is really a subnet mask limiting access to the single IP address of the remote NTP servers.

If this server is also going to provide time for other computers, such as PCs other Linux servers and networking devices, then you’ll have to define the networks from which this server will accept NTP synchronization requests. You do so with a modified restrict statement removing the noquery keyword to allow the network to query your NTP server. The syntax is:

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

In this case the mask statement has been expanded to include all 255 possible IP addresses on the local network.

We also want to make sure that localhost (the universal IP address used to refer to a Linux server itself) has full access without any restricting keywords

restrict 127.0.0.1

Save the file and exit

Now you need to run the ntpdate command against your server

#ntpdate ntp0.pipex.net

restart NTP for these settings to take effect using the following command

#/etc/init.d/ntp restart

You can now configure other Linux hosts on your network to synchronize with this new master NTP server in a similar fashion.

Determining If NTP Is Synchronized Properly

Use the ntpq command to see the servers with which you are synchronized. It provided you with a list of configured time servers and the delay, offset and jitter that your server is experiencing with them. For correct synchronization, the delay and offset values should be non-zero and the jitter value should be under 100.

#ntpq -p

Output looks like below
ntp1

A star by any one of the names means that the system clock is synchronising with the NTP clock. If you don’t have a star (as in the example above) it means that the clocks are unreachable, already synchronized to this server or has an outrageous synchronization distance. Try running ntpdate (you will need to stop the ntp server) with your first ntp server as an argument. This will set your system clock fairly accuratly and mean that the server will be able to choose a clock to synchronize with.

Firewall Configuration for NTP

NTP servers communicate with one another using UDP with a destination port of 123. Unlike most UDP protocols, the source port isn’t a high port (above 1023), but 123 also. You’ll have to allow UDP traffic on source/destination port 123 between your server and the Stratum 1/2 server with which you are synchronizing.

NTP Client Configuration

If you want to configure ntp client you need to install the following packages

#apt-get install ntp ntp-simple ntpdate

Configuring NTP client

You need to edit the /etc/ntp.conf file you need to point the following settings to NTP server ip address

Server configuration settings

server 192.168.1.1

Restrict the type of access you allow these servers. In this example the servers are not allowed to modify the run-time configuration or query your Linux NTP server.

restrict default notrust nomodify nopeer

Localhost configuration

restrict 192.168.1.1

In this case the mask statement has been expanded to include all 255 possible IP addresses on the local network.

We also want to make sure that localhost (the universal IP address used to refer to a Linux server itself) has full access without any restricting keywords

restrict 127.0.0.1

Now you need to save and exit the file

run ntpdate command against your server

ntpdate 192.168.1.1

Restart ntp service using the following command

/etc/init.d/ntp restart

If you use the date command to change time, it is worth setting also the hardware clock to the correct time. Otherwise, the time is wrong after the next reboot since the hardware clock keeps the time when power is turned off. When the clock in the operating system shows the correct time, set the hardware clock like this

#hwclock --systohc

se the ntpq command to see the servers with which you are synchronized

#ntpq
#ntpdc -p

 


16 Responses to “How to set up time server in linux”

  • slempase says:

    i want make ntp server lokal

    pc server——pc router——xp client

    between pc server n router ntp has ok but to xp client not work…

    how to make ntp server lokal on debian to sync with xp client

  • I think people felt bad for me afterwards because of how
    nervous I was. We had no problem finding a space,
    though, despite the fact that there was a performance
    that night. An estimated 80% of Americans between the ages of 33 and 44 use the internet as a tool for research, shopping and banking.

  • Edgar says:

    Nanokeratin locks onto the hair, forming a fine,
    smooth coat of keratin. Likewise, using imported shampoos and conditioners from a tropical country when
    your climate is cold and temperate is not such a good idea.
    A well groomed woman will look to her hair and makeup first and a poll
    of 3,000 females across the UK revealed that about 44% feel attractive if they are having a good hair day, this compares to 16% who
    felt pleased with their appearance if good teeth gave them that winning smile.

  • of course like your website however you need to check the spelling on several of your posts. Several of them are rife with spelling problems and I find it very bothersome to tell the reality on the other hand I’ll certainly come back again.

  • Mercedes says:

    Hair that is thin will benefit from lighter oils while hair that is coarse will benefit from heavier oils.
    It can also be left in the hair as a conditioner but it may be hard to explain the tomatoes.

    com/hair-growth-products-top-things-to-know-before-purchasing-a-product ]hair growth products visit our website howtomakeyourhairgrow-fasterandlonger.
    However, sometimes the sebaceous gland generates
    too much oil, which is noticeable as oily hair. Indeed, nourishing and conditioning the scalp using aromatherapy oils is
    one of the most basic and simplest ways to prevent further hair loss
    and stimulate healthier hair regrowth.

  • Benedict says:

    It is widespread thing to encounter some sorts of illnesses within
    our life, but the factor is it really is uncommon to meet
    the proper treatment as soon as. Predominantly the computer software will endeavor to lure you into paying for non-existent software program to clear away the viruses
    that are infecting your Computer. Pick out ideal food for our
    daily lifestyle may be the basis to remedy the root in the yeast.
    Yet again, new advances and engineering make these procedures rapid and helpful, and this
    cuts down on the value tremendously. Her new Bluetooth Headset is obviously the latest
    model.

  • Lowell says:

    Discount vouchers can be used for your acquisition of
    various items just like clothes, electronic devices, guides, travelling packages, gifts, games
    and in some cases food. Discount vouchers and money off coupons are
    getting widely used in Australia with on-line shops who are looking to encourage individuals to shop at their sites.
    Latest Discount Vouchers, they over a plethora of purchasing opportunities that
    will blow your mind.

  • simulator says:

    Since the program is based on a real time world, users would not
    only be able to choose the weather of their choice but also the scenery.
    All of these issues add to the interest that can be produced
    about a site and this works for spots in this place and any place in the world.
    You can train up your hobo so that you can kill other hobos even more easily, and it is a very
    addicting game. If you are looking for some excitement beyond
    just flying, the Jane’s series of combat flight simulators is the best place to look. Retain on your own and these you enjoy in the gaming.

  • mining says:

    If you have a Jewel crafting or a jewel crafter friend.
    It also happens sometimes that your character will say something silly.
    If you choose an activity that the both of you enjoyed together, this will aid remind your ex of how pleasurable it was spending time with you,
    bring back the good days.

  • defensive says:

    In contrast, the non-organic gardener is more
    likely to use chemically created fertilizers.

    When you’re preparing your planting area, just mix the soil with about three inches of organic compost. In some cases, the quantity of materials for making compost in the amounts desired (an annual layer 2 inches deep across the garden) cannot be obtained.

  • Oma says:

    Of course, the dictatorship in Egypt is far
    different than what the vast majority of Americans face. Egyptian cotton bedding has
    become the popular choice of many savvy consumers. The news that you as a reporter tend
    to report must be based on fact. God gets all buddy-buddy with
    Satan and in fact hires Satan to cause our hero all sorts of misfortunes and calamities.
    In advance of purchasing, you should also review if the reproduction Hermes totes
    are priced way too high compared to it really is top quality and also product difference.

  • mulching says:

    This could cause them to grow less, flower less,
    and maybe even die. Mulch will reduce weed growth and prevent new weeds from growing in the garden.
    Depending on the density of the mulch, one should lay
    two to six inches of mulch over topsoil in the vegetable garden.

  • I’m no longer positive the place you are getting your info, but good topic. I must spend some time learning much more or understanding more. Thank you for magnificent info I used to be on the lookout for this information for my mission.

  • I do not create a comment, but after reading through some of the remarks on
    How to set up time server in linux | Techgurulive.
    com. I do have some questions for you if you don’t mind. Could it be only me or does it look as if like a few of these remarks look like they are coming from brain dead individuals? :-P And, if you are writing at additional online social sites, I’d like to
    keep up with you. Would you post a list of every one of your social pages like your Facebook page, twitter
    feed, or linkedin profile?

  • men and women, it seems kind involving dangerous intuition to calculate. Tonight is bound to become a night to kill, do not know how many people can see the sunlight tomorrow? Road harsh wind unfortunate. Life in the skin of relentless war, is so fragile, the blow will be broken, lost forever in this specific world. To in the end is what folks do, why have not encountered life and death Rain is really also sensitive to them, tory burch outlet

  • このライトアップと上のスポットは、私は本当にこの Webサイトを | はるか ニーズたいを仮定仮定と思う考察。私抣lは最も高い もう一度もう一度 読むするために、その情報のためむしろ方法より、感謝される。


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>