Page 1 of 1

Manually force date by ntpd instead of ntpdate

Posted: Sat Feb 28, 2015 2:21 pm
by ^rooker
As far as I've read, "ntpdate" is about to be somewhat discontinued and replaced by "ntpd" completely in the future.
"ntpd" is great, but by default it refuses to synchronize time/date if it's offset is too big.

Therefore, I've usually called "ntpdate" once on fresh installs, or when I wanted to manually force re-sync of time/date - and then ran the ntp demon.

Now, here's how you can do the same thing using "ntpd" only:

Code: Select all

$ ntpd -p $TIMESERVER -gq
Replace "$TIMESERVER" by any ntp timeserver you fancy. If you don't have one in house, you may want to try "pool.ntp.org".
The command returns nothing, but it's good to check your time/date afterwards:

Code: Select all

$ date
PS: That also works to fix date/time issues on OpenELEC on a Raspberry Pi ;)

Re: Manually force date by ntpd instead of ntpdate

Posted: Tue Nov 03, 2020 2:04 pm
by peter_b
Short update (Debian based systems, including *Ubuntu):

1) You need to stop the NTP service before

Code: Select all

$ systemctl stop ntp
2) You don't need to provide a timeserver
Since the default ntp configuration on a system contains a list of timeservers, it also works without providing any server:

Code: Select all

$ ntpd -gq
If you get the following error, the NTP service is still running (and binding the port), so it wasn't properly stopped:
3 Nov 12:03:39 ntpd[19073]: ntpd 4.2.8p10@1.3728-o (1): Starting
3 Nov 12:03:39 ntpd[19073]: Command line: ntpd -gq
3 Nov 12:03:39 ntpd[19073]: proto: precision = 0.088 usec (-23)
3 Nov 12:03:39 ntpd[19073]: leapsecond file ('/usr/share/zoneinfo/leap-seconds.list'): good hash signature
3 Nov 12:03:39 ntpd[19073]: leapsecond file ('/usr/share/zoneinfo/leap-seconds.list'): loaded, expire=2021-06-28T00:00:00Z last=2017-01-01T00:00:00Z ofs=37
3 Nov 12:03:39 ntpd[19073]: unable to bind to wildcard address :: - another process may be running - EXITING
3) You need to re-start the NTP service afterwards

Code: Select all

$ systemctl start ntp

Optional: If you want to know if your NTP service is properly running again, use this:

Code: Select all

$ systemctl status ntp
Here's an example output how this should/could look like:
● ntp.service - Network Time Service
Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-11-03 12:00:52 UTC; 2s ago
Docs: man:ntpd(8)
Process: 18139 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
Main PID: 18159 (ntpd)
Tasks: 2 (limit: 3553)
CGroup: /system.slice/ntp.service
└─18159 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 113:116

Nov 03 12:00:52 your_hostname ntpd[18159]: Listen and drop on 0 v6wildcard [::]:123
Nov 03 12:00:52 your_hostname ntpd[18159]: Listen and drop on 1 v4wildcard 0.0.0.0:123
Nov 03 12:00:52 your_hostname ntpd[18159]: Listen normally on 2 lo 127.0.0.1:123
Nov 03 12:00:52 your_hostname ntpd[18159]: Listen normally on 3 enp0s3 94.130.40.108:123
Nov 03 12:00:52 your_hostname ntpd[18159]: Listen normally on 4 lo [::1]:123
Nov 03 12:00:52 your_hostname ntpd[18159]: Listen normally on 5 enp0s3 [fe80::a00:27ff:fe89:96d2%2]:123
Nov 03 12:00:52 your_hostname ntpd[18159]: Listening on routing socket on fd #22 for interface updates
Nov 03 12:00:53 your_hostname ntpd[18159]: Soliciting pool server 144.76.100.49
Nov 03 12:00:54 your_hostname ntpd[18159]: Soliciting pool server 129.70.132.34
Nov 03 12:00:54 your_hostname ntpd[18159]: Soliciting pool server 176.9.18.143