Force host clock sync or update using public NTP

How to force host clock sync or update using public NTP ?

This tutorial guides you on how to force host clock sync or update with public NTP using ntpdate command or by setting up NTP and configuring host to sync with public NTP.

Force host clock sync or update using public NTP

Force host clock sync or update using public NTP

I was using Ubuntu development VM and which uses ubuntu.pool.ntp.org as NTP Time server and it is not in sync with the browser (local windows machine) as it was using time.windows.com as NTP server.

And I need to keep these two (Ubuntu machine and local Windows machine) host clock sync or to make it to use same public NTP with date and time synchronized. Therefore, I can do some performance testing to measure elapsed time for the data packets to travel end-to-end.

Note, I was not able to change the NTP Time Server to point to different from time.windows.com as it is office laptop and I don’t have permissions to do so. Hence, I decided to force the ubuntu host clock sync to the same NTP Time server as that of Windows which is time.windows.com.

Force a clock sync or update using ntpdate

You can force clock update using ntpdate command. You need to follow the below steps to do the same.
 
First, make sure that you had installed ntpdate package.
 
sudo apt-get install ntpdate

If you had installed NTP service and if it is up and running, make sure that you stop before you force update clock settings using ntpdate command. Otherwise you may get the error “can’t open the socket (port 123 UDP) and connect to ntp server.”

sudo service ntp stop

Then run the following command to change the host’s clock settings.

sudo ntpdate time.windows.com

Finally, start the ntp service.

sudo service ntp start

That’s it. You’r host clock is synced to public NTP time.windows.com.

Setup NTP and configure host to sync with public NTP

If you had not installed NTP or alternatively you can setup NTP and configure host to synchronize with a public NTP Server.

First, you need to install and configure NTP Server on Ubuntu Server. To install NTP on ubuntu follow the below steps.
 
1: Install ntp
 
sudo apt-get install ntp

2: Check status of ntp Stop ntp service

sudo service ntp status

Stop the service

sudo service ntp stop

3: Edit ntp.conf file to update the required public NTP server settings i.e., the public NTP server that you would like to synchronize your host clock.

sudo nano /etc/ntp.conf

Comment out the NTP servers (configurations starts with pool*) listed. And add the following NTP server configuration: pool time.windows.com as shown below.

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Leap seconds definition provided by tzdata
leapfile /usr/share/zoneinfo/leap-seconds.list

# Enable this if you want statistics to be logged.
#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

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst


# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com

pool time.windows.com

-----
-----

4: Finally, check if host clock is updated with public NTP time server

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 time.windows.co .POOL.          16 p    -   64    0    0.000    0.000   0.001
+10.38.72.8 (css 10.38.72.7       2 u  481 1024  377  295.347    3.033   0.542
*10.24.64.8 (css 10.38.64.7       2 u  820 1024  377  200.277    0.553   1.168
+10.38.64.8 (ntp 10.38.64.7       2 u  255 1024  377  289.660   -0.653   0.762

That’s it, you had forced host clock to sync with the public NTP Time server.

Hope this article is helpful 🙂

Also See:

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments