LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   help with NTP (https://www.linuxquestions.org/questions/linux-newbie-8/help-with-ntp-797518/)

dhavalshah9898 03-24-2010 06:17 AM

help with NTP
 
Hi All,

i am sending my first questing on such forum.
i am using broadcom router .
when some one set time server name in time settings field
in router what kind of settings we have to do so that
system get time(sync with that) from that particular server.
i have already get very good answer from this forum so i know
i get very good answer which help me a lot.
your help is appreciated.

tronayne 03-24-2010 06:59 AM

If you have a time server on your network -- a machine that is synchronized with a time source such as a GPS clock, radio clock, or external time source such as a national time service -- all you need to do is set the address of that server in the /etc/ntp.conf file.

For example, if your time server's address is 192.168.1.10, the entry in your /etc/ntp.conf file would look something like this
Code:

server  127.127.1.0    # local clock
fudge  127.127.1.0 stratum 10
server  192.168.1.10

The reason for the "local clock" line and the "stratum 10" line is so NTP can sync locally if the external time server is not available for some reason.

You may want to add a couple of external pool servers to the entry; they of the form
Code:

server  0.cc.pool.ntp.org
server  1.cc.pool.ntp.org

where "cc" is the two-character country code for where you are in the world (in my case the entries are 0.us.pool.ntp.org); you want two or three of these electrically close to you to pick up the slack if your internal time server becomes unavailable.

The router you're using does not need any special settings as long as your local server can "see" the time server, you're good to go. If you have set up your LAN to require some sort of port access or the like, you may need to open that port on the router, but that would probably be unusual.

And, finally, if the time server has a "name" it also has an address -- you need to know the address to make the entry in /etc/ntp.conf. The example I've used above, 192.168.1.10, is a reserved for private network address (the 192.168.x.x) and you will need to use your LAN address.

If you make any changes to /etc/ntp.conf, you will need to stop and restart the NTP daemon. Also, if your local clock is not close to the correct time, NTP will not sync so you may need to stop the NTP daemon and use the ntpdate utility to set your local clock before starting the NTP daemon; e.g.,
Code:

ntpdate address_of_time_server
Hope this helps some.

dhavalshah9898 03-24-2010 11:32 PM

thanks a lot for your quick reply
this helps me a lot but i want to know what is a use of "fudge".
now as i understand from your reply
when someone add time_server_name in time setting field of router page(web page)
then
i have to add

server time_server_name

instead of

server 192.168.1.10

in ntp.conf file

and then ntpd stop
am i right.
your help is appreciated.

tronayne 03-25-2010 06:45 AM

Maybe, maybe not: if your system "knows" time_server_name by name; i.e., you can open a terminal window and ping time_server_name (obviously using the name of the server, not "time_server_name"), then, yes, you can use the name. It might be better, if the time server is using fixed IP addressing; i.e., the address of the server never changes, then if you use the actual address then the name doesn't have to be resolved. That means that your system does not have to contact a DNS server to get the address from the name (if you ping the server by name, the display will show you the address, for example)
Code:

prompt: ping -c 6 0.us.pool.ntp.org
PING 0.us.pool.ntp.org (66.36.239.104) 56(84) bytes of data.
64 bytes from 66.36.239.104: icmp_seq=1 ttl=49 time=213 ms
64 bytes from 66.36.239.104: icmp_seq=2 ttl=49 time=194 ms
64 bytes from 66.36.239.104: icmp_seq=3 ttl=49 time=252 ms
64 bytes from 66.36.239.104: icmp_seq=4 ttl=49 time=184 ms
64 bytes from 66.36.239.104: icmp_seq=5 ttl=49 time=252 ms
64 bytes from 66.36.239.104: icmp_seq=6 ttl=49 time=185 ms

--- 0.us.pool.ntp.org ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5003ms
rtt min/avg/max/mdev = 184.999/214.121/252.983/29.109 ms

The important thing is that your system can quickly and easily find the time server and you can use either the time server's name or the actual address (if it's fixed IP).

In the example I gave you, using a couple of pool servers in addition to your time server, I don't know their addresses and one of the truly nice things NTP does when you give it three or so time servers (the pool servers in this case) is that it will determine the best time server to use and switch from one to another if for some reason the initial choice drops out or becomes slower than one of the others. When you have an actual time server on your LAN, it's most likely going to be the closest electrically (that is the ping time is the shortest) and NTP will synchronize with it all the time. The idea of having external pool servers available is that if you LAN time server goes away for some reason (system maintenance, the LAN goes down, the phase of the moon, whatever) there are one or two external servers to back it up just in case.

So, you can make your entry either way -- name or address. If you can ping the name, that'll work (and might be better if the server is not using fixed IP addressing). LAN time servers typically do not use DHCP addressing but, if yours does, then you want to use the server name because the address may change periodically.

And, once you've made your entries, stop NTPD then start NTPD. After about five minutes you can see if you're sync'd up by executing ntpq like this
Code:

prompt ntpq -p
    remote          refid      st t when poll reach  delay  offset  jitter
==============================================================================
 LOCAL(0)        .LOCL.          10 l  58  64  177    0.000    0.000  0.001
+ntp1.Rescomp.Be 169.229.128.214  3 u    3  64  377  226.953  -6.159  3.536
*mirror          204.9.54.119    2 u  59  64  177  170.957  -5.269  7.542
+ns1.your-site.c 10.1.11.62      3 u  62  64  177  191.950  -3.331  7.818

Recall that I use three pool time servers (and this particular machine is on a dial-up line right now so the values are a little larger than they would otherwise be); the important thing is the plus signs and asterisk at the left end of the lines -- those tell you that you're in sync with the time server and that there are additional candidates for switching if the time server goes away.

Hope this helps some.

dhavalshah9898 03-25-2010 11:30 PM

thanks a lot.
this is very good reply for me.
now i want to know what is difference between ntpdate and ntpd?
can it possible to do the whole task of NTP by using only ntpdate
if i don't want to use ntpd.
because i have to change my linux system time whenever someone change time server name in router time setting (web page) page.
and also i have to execute cronjob of this time synchronization 1 time in a day.
i expect same more knowledgeable answer from you.
i am actually learning from your answer day to day.

tronayne 03-26-2010 06:39 AM

The ntpdate utility is a one-time set-the-clock-from-a-time-server. The daemon, ntpd, keeps the system clock synchronized with with a time reference (national time servers, GPS clocks and the like -- they're all referenced is to the so-called atomic clocks maintained around the world).

The clocks in computer systems are notorious for drifting, gaining and losing time. You'd think, what with wristwatches being as accurate and cheap as they are, that it wouldn't be too much trouble to keep accurate time in a computer but that just isn't the case (for a lot of reasons that I'll leave to you to discover). Essentially, your system clock will drift and it needs to be adjusted periodically to get it back in sync with the reference standard. That's what the NTP daemon does (and that's a Good Thing: networks and things work a little better if they're all on the same time).

It is unlikely that your network time server is going to change addresses; when a LAN time server is set up, the whole idea of doing so is to provide a time reference for all the computers attached to the LAN to keep them all in sync. You just don't fiddle with it once it's in place. And, when the time server system is rebooted or whatever it will only be out of service for a short period -- the beauty of NTP is that sort of thing is taken into account. If your network connection goes away or your LAN time server goes away, NTP will simply fall back to LOCAL (the internal clock) if the network drops off or to one of the pool servers you add to /etc/ntp.conf. When your LAN time server comes back, NTP automagically switches back to it and syncs your system. It's invisible, it's automatic and it requires no action on your part -- this is also a Good Thing.

Of course you can, if you choose, not use the daemon at all. You could set up a cron job to execute ntpdate once every X hours and that would keep your system clock pretty much on time. But you need to figure out how to set up the cron job, test it, check every so often to make sure that it's running and all that; why bother? You have a time server available, you can access pool servers to back that up and you don't have to fiddle with anything. The NTP daemon uses an insignificant amount of resources (you'd be hard-pressed to notice it), it works so you don't have to.

Hope this helps some.

dhavalshah9898 03-30-2010 12:18 AM

thanks a lot this helps me a lot.


All times are GMT -5. The time now is 05:00 AM.