1

The time on my Raspberry Pi is off by a few days. When I try

$ sudo dpkg-reconfigure ntp

it doesn't change the time, but some stuff comes up in the syslog:

Oct 21 18:27:45 airpiClock ntpd[2142]: ntpd exiting on signal 15

Oct 21 18:27:51 airpiClock ntpd[2758]: ntpd [email protected] Fri May 18 20:30:57 UTC 2012 (1)

Oct 21 18:27:51 airpiClock ntpd[2759]: proto: precision = 1.000 usec

Oct 21 18:27:51 airpiClock ntpd[2759]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123

Oct 21 18:27:51 airpiClock ntpd[2759]: Listen normally on 1 lo 127.0.0.1 UDP 123

Oct 21 18:27:51 airpiClock ntpd[2759]: Listen normally on 2 wlan0 192.168.2.141 UDP 123

Oct 21 18:27:51 airpiClock ntpd[2759]: peers refreshed

Oct 21 18:27:51 airpiClock ntpd[2759]: Listening on routing socket on fd #19 for interface updates

Oct 21 18:27:51 airpiClock ntpd[2759]: restrict: error in address '::' on line 38. Ignoring...

I found that when I reverted from a static IP address to DHCP and rebooted, the date and time were corrected. I need to keep a static IP address, but I also need to be able to accurately schedule tasks, so the date and time must be correct.

This is what my /etc/network/interfaces file looks like:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0

auto wlan0

iface wlan0 inet static

address 192.168.2.143
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
gateway 192.168.2.1

wpa-ssid "ssid"
wpa-psk "password"

What do I need to change in order to be able to have a static IP address and accurate time?

4 Answers 4

0
$ sudo dpkg-reconfigure ntp

has nothing to do with getting the time from the Internet. The correct way would be:

$ sudo ntpdate pool.ntp.org

or you may specify any of your favourite servers. regarding the static address, most probably your router has no idea about this address and effectively disable outbound internet access for your RasPi. you should setup your DHCP server to allocate the IP address based on the MAC, and then specify RasPi MAC address to be given specific IP address all the time. usually this kind of settings are available in your router (or whatever device you use as DHCP server).

2
  • hi lenik. I can ping an outside address. This makes me think that I have outbound internet access. Oct 22, 2013 at 17:28
  • Oh, ntpdate wasn't installed. I thought I read that it came with raspbian. I downloaded it and now the date is correct. Thanks for the hint. Oct 22, 2013 at 19:50
2

Though Lenik's suggestion of using ntpdate helped me initially, I've since read that ntpdate is deprecated, so I kept trying to get ntpd to do what it's supposed to.

On another forum, somebody mentioned a version of Raspbian that was missing something from the NTP library, and that a reinstall fixed it:

sudo apt-get --reinstall install ntp

This ended up working for me. I am still not sure how it was related to the static IP address.

1
  • Very weird. It works for me, but the issue comes again after reboot; if I resinstall again it solves the issue again. I don't want to reinstall ntp at each reboot however! Do you understand what is happening? Apr 15, 2015 at 6:56
0

On the Raspbian, there is generated a file /var/lib/ntp/ntp.conf.dhcp by the dhcp-client, and that is generated on the basis of your DHCP-server and what it tells the client.

If you do not use DHCP, delete it. Then ntp will read /etc/ntp.conf If you do not have one, use this:

# /etc/ntp.conf, configuration for ntpd
logfile /var/log/ntpd
driftfile /var/lib/ntp/ntp.drift

# NTP servers
server <your local NTP server> # Delete line if you do not have one
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

# Default restriction. See
# http://support.ntp.org/bin/view/Support/AccessRestrictions
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Allow localhost (via the "ntpq" command)
restrict 127.0.0.1
restrict -6 ::1

Restart the ntp, then use ntpq -p to see if your getting info from your peers/servers.

And one final note: If your clock is more that 1000s inaccurate, ntp will quit. You have to adjust the time manually via date

2
  • Thanks for the response. I don't have an ntp.conf.dhcp file. I made sure my ntp.conf file looked like yours. Strangely, when I restarted ntp, ntpq -p showed peers, and then I ran it again immediately after and it returned 'Error: name or service not known' Oct 22, 2013 at 17:42
  • Sounds like a DNS problem, not a NTP problem. Try running dig +short 0.pool.ntp.org, that should always give an anwser. If not, you might want to try another DNS-server (located in /etc/resolv.conf)
    – Sitron_NO
    Oct 23, 2013 at 6:30
0

All these pools are going to be way down the list of handoffs between systems all the way back to Stratum-1.

What you need to do is modify your ntpd to reach the official Master Clock at time.nist.gov.

Here is a Q&A on this Stack Exchange that explains the process.

How do I set Raspbian to use the primary time server time.nist.gov?

It makes a huge difference when you are trying to synchronize multiple Raspian or ubuntu or Windows systems so they all have the correct time down to the microsecond.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.