11

I bought a Raspberry Pi 3 approximately two months ago, and since then time has never updated. Details:

  1. The operating system is a fresh installation of Raspbian Jessie (4.1.19-v7+).
  2. The Internet connection is via native Wi-Fi and no other problem with communication.
  3. No firewall problems as time update works like a charm on a Windows machine on the same LAN.
  4. Time zone is properly set.

I first started with nptdate. When I tried forcing update,

sudo /etc/init.d/ntp stop
sudo ntpd -q -g
sudo /etc/init.d/ntp start

the terminal froze at the second command. The last message in /var/log/syslog was:

Listening on routing socket on fd #22 for interface updates

/etc/ntp.conf contents:

driftfile /var/lib/ntp/ntp.drift

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

server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

restrict 127.0.0.1
restrict ::1

It seems to me that the ntp package has a problem. How do I set up time update, as my Raspberry is turned on only during the day and time lag accumulates during the night?

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Pygmalion
  • 458
  • 2
  • 7
  • 23
  • 1
    What distribution are your using? These ancient links have nothing to do with current Raspbian. How long do you wait after boot? What are you doing to confirm "time won't update"? – Milliways May 18 '16 at 09:46
  • It is Raspbian if you are asking that. No matter how long I wait it does not update. I use "date" command and watch clock command in the corner. – Pygmalion May 18 '16 at 09:48
  • ntpd changed at some point in the past few years to make it harder for the user to force a change. Considering how simplistic its purpose, it is one of the absolute worst designed, most obtuse apps of all time. Someone should just write a basic, client only implementation for standalone end-user systems. It could not take more than a day, including reading the RFCs. I feel for you. I hate that thing (except it generally works for me so I'm not bothered...). Good luck. – goldilocks May 18 '16 at 10:56
  • That said, I think you could add a more detailed explanation of what exactly happens. It certainly squawks a lot when it cannot connect to a server, and that stuff will be in syslog. Have a look at sudo grep ntp /var/log/syslog or, after booting, journalctl | grep ntp. – goldilocks May 18 '16 at 11:00
  • @goldilocks sudo grep ntp /var/log/syslog returns bunch of bad peer from pool x.debian.pool.ntp.org errors. After restarting journald | grep ntp returns bash: journald: command not found and sudo grep ntp /var/log/syslog returns bunch of can't find host x.debian.pool.ntp.org: name or service not known errors and no servers can be used, exiting – Pygmalion May 18 '16 at 11:20
  • Sorry that should have been journalctl (comment edited). Anyway on Raspbian syslog should contain the same stuff. Edit those errors into the question and clarify over what timespan "not ever" applies to (as in "not ever today since I noticed the problem", "not ever in 4 months since I've had the pi", etc). – goldilocks May 18 '16 at 11:22
  • @goldilocks journalctl returns No journal files were found. I also updated the question and syslog result after the restart in the comment. – Pygmalion May 18 '16 at 11:25
  • @goldilocks Here is follow-up of my question: http://unix.stackexchange.com/questions/284354/problems-with-timesyncd-or-networkd – Pygmalion May 20 '16 at 07:25
  • @Milliways I added additional information to the question. – Pygmalion May 20 '16 at 08:18
  • The best approach is to always use time.nist.gov as the official ntp time. See this Q&A: https://raspberrypi.stackexchange.com/questions/68811/how-do-i-set-raspbian-to-use-the-primary-time-server-time-nist-gov – SDsolar Jun 22 '17 at 20:11
  • I had the same problem with setting the time and found it worked after I connected to a LAN cable. Could not set time on wi-fi. – Craig Oct 08 '16 at 01:58
  • This is not the standard behavior, and is unlikely to be the cause of the OP's problem. In your case this implies an issue with your network configuration. – Steve Robillard Oct 08 '16 at 10:07

8 Answers8

12
sudo sntp -s time.google.com

This worked for me.

goobering
  • 10,730
  • 4
  • 39
  • 64
Nicky
  • 121
  • 1
  • 2
9

I tried several ways with ntp, chrony... Finally fixed with the following method.

Fetch date from any renowned website like google to set your machine time at every boot.

  1. Open rc.local file

    sudo nano /etc/rc.local

  2. Add following line to the rc.local file

    sudo date -s "$(wget -qSO- --max-redirect=0 www.google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"

  3. Reboot the Rpi

    sudo reboot

nmur
  • 103
  • 2
Shamshu
  • 101
  • 1
  • 3
  • I liked the solution. It worked but I would be happy with ntp solution. I tried them but I was not able to get through that. – Varad A G Aug 14 '17 at 06:59
  • I can understand this desperation - this is exaclty what I also have done on some ocasions (date from HTTP header), but now I'm in a closed network with no internet access, and no HTTP servers, just a NTP server. – Tomasz Gandor Sep 14 '17 at 21:01
6

You need to try to update time via a USB Wi-Fi dongle. If it will work fine, then use tcpdump and take a look how the packet is handled on both sides: On Raspberry Pi 3 and the Wi-Fi AP it connects to.

The internal Wi-Fi of Raspberry Pi 3 is used to be losing packets silently as far as I know.

How /etc/network/interfaces should look like:

# Wired adapter #1
auto eth0
    iface eth0 inet static
    address 192.168.0.3
    netmask 255.255.255.0
    gateway 192.168.0.1
    dns-servers 8.8.8.8,8.8.4.4
    post-up /usr/sbin/ntpdate -4 1.2.3.4

Don't forget leading spaces!

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Alexey Vesnin
  • 926
  • 9
  • 16
  • Comments are not for extended discussion; this conversation has been moved to chat. – Ghanima May 22 '16 at 18:48
  • I found solution how to "repair" ntpd on this thread: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=141454. I still do not know how to make it automatically at booting the RPi3. – Pygmalion Jun 01 '16 at 15:14
  • @Pygmalion as I said before - ntpD=NTP Daemon - is not required for a simple host time setting... It is maid for distributing time through network, i.e. if you have a multiple nodes, you need it for sure. But for a single endpoint time setting a ntpdate tool is made. It is even separated in ntp source tree itself – Alexey Vesnin Jun 13 '16 at 18:28
4

If you set the Time Zone in raspi-config the Raspberry Pi will automatically update the time on boot, if connected to the internet.

  1. sudo raspi-config
  2. Select Internationalisation Options
  3. Select I2 Change Timezone
  4. Select your Geographical Area
  5. Select your nearest City
  6. Select Finish
  7. Select Yes to reboot now
mwd27
  • 351
  • 2
  • 2
  • Of course I set time zone the very first day. – Pygmalion May 21 '16 at 20:07
  • 1
    I also set the time zone the very first day, but my Pi recently stopped updating the time on reboot, exactly like the problem you are having. I re-ran raspi-config yesterday and the time has updated correctly on every reboot since, even if I've left the power unplugged for a while. I suggest you give it a try? Let me know how you get on... – mwd27 May 21 '16 at 20:13
  • I am sorry. I did as you suggested, but it failed. – Pygmalion May 22 '16 at 06:36
  • Oh, that's a shame. I'll keep thinking... – mwd27 May 22 '16 at 12:55
3

The following command will surely work

sudo date -s"Sep 11 12:50"
satven
  • 31
  • 1
  • 1
    Thank you for your answer. I think the question is about automatic updating, using NTP, though, and your answer seems to be about one-time setting of the clock. – Bex Sep 11 '18 at 09:19
2

I found that using the following worked as a one off via WiFi.

sudo sntp -s 0.debian.pool.ntp.prg
Ghanima
  • 15,855
  • 15
  • 61
  • 119
David
  • 21
  • 1
1

For me I had to wait a bit for some reason it didn't set the correct time right away. This is after I set correct time zone, had internet access enabled and rebooted.

Lightsout
  • 429
  • 1
  • 5
  • 20
1

In Application Menu/Preferences/Raspberry Pi Configuration I went to the Localisation tab and selected values for Set Locale, Set Timezone and Set WiFi Country.

Clicked OK and Time is now correct.

Scott H
  • 11
  • 1