NTP setting time with NTPDATE or NTP while NTP is running

You will most likely have NTP running on your computer syncing time to whatever servers are listed in /etc/ntp.conf. To check

Some history:

rdate used to set time equal to another PC in lan time
Just had script set on boot
Its important to have time equal in network. If cant get it equal to outside, have it all relatively equal at least.
ntpdate came out to set to another server (but thats only a client, it cant be used a server) – ntpdate just grabs time
Most ntp servers like ntpd set time and grab time
Just had script set on boot
ntpd came out and is better then ntpdate as it can set and grab time.

History from here: http://www.debian.org/doc/manuals/system-administrator/ch-sysadmin-time.html

If you have NTP running it will be a TIME SERVER and it will also SYNC/GRAB TIME from another server. It will grab time from the servers that are configured in /etc/ntp.conf

NOTE: NTP works on UDP port 123

It will adjust time when it gets away by alot and it will fix it on boot.

To manually set the time

First find out your server from /etc/ntpd.conf

First stop NTP (also known as ntpd) because ntpdate cant set the time while ntp/ntpd is running as they both need to listen to port 123 to set the time. Then we will sync time with the old ntpdate (and new command ntpd -gq). Finally we will start the ntpd/ntp server again.


NOTE: see below for a way without turning off ntp


NOTE: see below for a way without turning off ntp

Ntpdate to sync time is nice, but since ntpdate is old and deprecated and now ntpd can set its own time

NEW WAY (because ntpdate is deprecated):

NOTE: see below for a way without turning off ntp


NOTE: more on hardware time setting below

NOTE: more info here  http://askubuntu.com/questions/254826/how-to-force-a-clock-update-using-ntp

NOTE: if you get an error “cant find servers” just run OLD WAY or GOLD WAY below

Checking Time difference when NTP is running

ntpd/ntp has a client program ntpq to do house keeping with. ntpq is ntpd secretary.

When NTP is running you can look at the skew of time between server and current time

Here we can see my host host1, is -3.661 milliseconds off prod2k8

to see ips of servers

NOTE: ntpq only works when ntpd/ntp is running, as its a client for ntpd/ntp
Notice current system time is off by 262 ms, which is less then 1 second so you wont notice much change.

Systemtime/Ostime vs Hardware time:

Your system has OS time (which is what we have been looking at above) and also HARDWARE time on your motherboard. The SYSTEM time is whateverything runs off when your working, on boot though everything works off HARDWARE time. Its best to have those insync.

To set the hardware time do this

First look at how far off it is

NOTE: –show or -r will show the difference between OS and HW time but dont look at it as its off sometimes

Notice that systemtime above is 30 seconds or so ahead of HW time, yet the difference shows as -0.8 seconds. The top line is SYS/OS time from date output, and bottom line is HW time from hwclock output

To fix the hardware time:

Check new:

Notice now it looks right:

NOTE: date will show current OS time, and hwclock will show HW time (the the difference will also be shown)



Add to /etc/ntp.conf at the top

/etc/default/ntp sets options/arguments for ntp on boot – its checked by /etc/init.d/ntp

More Quering commands for NTP with NTPQ and for NTPDATE with NTPDATE

NOTE: ntpq only works when ntp is running

NOTE: ntpdate doesnt have any other commands to run with it, so you set and query time with it (the onlything you cant do with it is server time) and run a smart daemon

More info, like time offsets with servers configured in /etc/ntp.conf



NOTE: the offset value tells us how much the time is off


Set/Sync time without killing ntp/ntpd – The GOLD WAY

Only reason ntpdate doesnt work while ntp is running is because ntpdate complains about a used socket (port 123 udp). Well how about we change time without turning off ntp and use a different port then 123 udp:
-u option uses another port besides 123


NOTE: can do all of the above while ntp is running

More information from other links





Leave a Reply

Your email address will not be published. Required fields are marked *