89

The time on my system is incorrect for some reason.
i need to run an update but i can't seem to be able to
this is the errror.

ntpdate pool.ntp.org
31 Aug 12:31:59 ntpdate[3108]: the NTP socket is in use, exiting

i just rebooted, i do not know how anything can be in use.

terdon
  • 54,564

4 Answers4

179

If you want to execute ntpdate with the ntp daemon already up and running, use the following command:

# ntpdate -u pool.ntp.org

and it will use a different port.

RoseHosting
  • 2,386
97

It's in use because the ntp service is probably running. You did not mention which Linux you are using so this assumes you have service installed (that you are running a System V system):

$ sudo ntpdate pool.ntp.org
31 Aug 19:05:55 ntpdate[8911]: the NTP socket is in use, exiting
$ sudo service ntp stop
[ ok ] Stopping NTP server: ntpd.
$ sudo ntpdate pool.ntp.org
31 Aug 19:07:11 ntpdate[10355]: adjust time server 46.29.176.115 offset -0.002893 sec
$ sudo service ntp start
terdon
  • 54,564
4

Simple one-liner to sync your clock:

ntpdate -u ptbtime1.ptb.de && hwclock -w
1

You could have a firewall blocking port 123 which can cause the ntp server to never see time servers.

In my case my ISP (Internet Service Provider) was blocking ports.

A port scan of 123 didn't detect the blockage either.

The smoking gun was that I temporarily have two independent, internet feeds. In linux if I run ntpq -p (repeatedly) with the first internet feed hooked up nothing gets updated, but with the other feed I get updates!

As @Jens A. Koch says, ntpdate -u <server name> does go around this, well, temporarily (no pun intended), it does not fix the time issue long term.

Over time drift will occur in both your system and hardware clocks. Also in my case dual booting linux/windows causes the hardware clock to further get messed up (by hours).

So you must have port 123 open for UDP for to maintain your system clock.


Rather than using -u, you can also do this which I think uses port 123 (rather than a non 'privileged' port):

service ntp stop, then
ntpdate <server url> (without the -u) and finally
service ntp start.

This seems to bypass the port blockage issue, at least to set the clock one time. If -u works, but this does not, then it's a pretty sure sign that the port is blocked, or the server is unresponsive, ...


Another issue that I had to solve was that for me the Debian default /etc/ntp.conf configuration included 4 lines to the pools: debian.pool.ntp.org. None of those servers worked. I got this error message:

Error resolving debian.pool.ntp.org: No address associated with
hostname (-5) 24 Mar 04:49:27 ntpdate[15115]: Can't find host
debian.pool.ntp.org: No address associated with hostname (-5) 24 Mar
04:49:27 ntpdate[15115]: no servers can be used, exiting

I had to change the servers to us.pool.ntp.org.