How to forcefully sync date and time using the NTP server in Linux

The commands and steps to initiate a forceful sync with NTP server may vary based on the distribution you are using.

By default if NTP service is running it will automatically sync the client's date and time from the NTP server based on the polling interval but what if you want to do a force sync immediately and cannot wait for the NTP client to sync it.

On SuSE Enterprise Linux
The current date and time on my node is

# date
Fri Dec  8 02:51:04 IST 2017

My ntp service status

# /etc/init.d/ntp status
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.10.100    10.171.8.4       3 u    1   64    1    0.173  -593996   0.000
 10.40.130.1     .INIT.          16 u    -   64    0    0.000    0.000   0.000

Checking for network time protocol daemon (NTPD):                       running

So my ntp client is running, lets change the date and time of my node before doing a force sync

# date --set "4 Dec 2017 10:00:00"
Mon Dec  4 10:00:00 IST 2017

My new date and time

# date
Mon Dec  4 10:00:02 IST 2017

Time to do a force sync

# /etc/init.d/ntp ntptimeset
Time synchronized with 192.168.10.100

So as you see it immediately sent a request to the NTP server and updated the localhost date and time details from the NTP server

# date
Thu Dec  7 10:23:35 IST 2017

On Red Hat Enterprise Linux 7
Unfortunately ntptimeset is not available in Red Hat Enterprise Linux so we have to try something else

My existing date and time

# date
Thu Dec  7 10:25:03 IST 2017

NTPD service status

# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2017-12-06 17:43:02 IST; 16h ago
  Process: 5957 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 5958 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─5958 /usr/sbin/ntpd -u ntp:ntp -g

Dec 06 17:43:02 Ban17-pgw01-a systemd[1]: Starting Network Time Service...
Dec 06 17:43:02 Ban17-pgw01-a ntpd[5957]: ntpd 4.2.6p5@1.2349-o Wed Mar  1 09:00:51 UTC 2017 (1)
Dec 06 17:43:02 Ban17-pgw01-a systemd[1]: Started Network Time Service.
Dec 06 17:43:02 Ban17-pgw01-a ntpd[5958]: proto: precision = 0.038 usec
Dec 06 17:43:02 Ban17-pgw01-a ntpd[5958]: 0.0.0.0 c01d 0d kern kernel time sync enabled

Now lets change the date and time

# date --set "4 Dec 2017 10:00:00"
Mon Dec  4 10:00:00 IST 2017

First stop the ntpd service

# systemctl stop ntpd

Next initiate a force sync from your NTP server using the below command

# ntpdate 192.168.10.100
 7 Dec 10:27:36 ntpdate[6701]: step time server 192.168.10.100 offset 260769.003401 sec

Now start the NTP service again

# systemctl start ntpd

Lastly validate if your localhost date and time is updated correctly

# date
Thu Dec  7 10:27:48 IST 2017

IMPORTANT NOTE: If you do not wish to stop the ntp server for doing the sync then use "-u" with ntpdate
-u      Direct  ntpdate  to  use  an unprivileged port for outgoing packets. This is most useful
        when behind a firewall that blocks incoming traffic to privileged ports, and you want to
        synchronize with hosts beyond the firewall. Note that the -d option always uses unprivi‐
        leged ports.

Without '-u' and when NTPD service is running

# ntpdate  0.in.pool.ntp.org
10 Feb 17:34:48 ntpdate[2574]: the NTP socket is in use, exiting

With '-u' and ntpd running in the background

# ntpdate  -u 0.in.pool.ntp.org
10 Feb 17:35:22 ntpdate[2575]: step time server 13.126.37.14 offset 1.335054 sec

I hope the article was useful.

Leave a Comment

close button