How to force NTPD to update date/time after boot?
The Raspberry Pi lacks a hardware clock. How do I force NTPD to update date/time immediately after every boot?
@Thorb Pi is connected with ethernet cable / dhcp. It simply does not get a valid date after booting, it takes a while (10 to 45 minutes)
It will do it on its own, when set up properly, within a few minutes. You might also want to be sure you are set to the correct master clock time source: https://raspberrypi.stackexchange.com/questions/68811/how-do-i-set-raspbian-to-use-the-primary-time-server-time-nist-gov
It will do it automatically, after a couple of minutes. Be sure you have set it to use the Master Clock at the National Bureau of Standards, time.nist.gov as described here: https://raspberrypi.stackexchange.com/questions/68811/how-do-i-set-raspbian-to-use-the-primary-time-server-time-nist-gov/68812#68812
The simplest and quickest is still (15 march 13h 01) being root or sudo-ed : "date -s 03151301" This is of course not an answer.
After searching around, this method worked for me. As you know, the Raspberry Pi 3 has NTP disabled by default. So by just typing this, the NTP support will be enabled:
sudo timedatectl set-ntp True
Check result with
In case of warning, you may have to run
sudo timedatectl set-local-rtc truetoo.
Thanks, this finally helped me out, and seems to be the proper way, despite previous answers.
apt-get install ntpdate.
ntpdatewill run when an Ethernet interface is brought up, and set the time from an ntp server (see
ntpdis running, ntpdate will do nothing, however
ntpdatewill run prior to
ntpdat bootup - so this should work out to set the time at bootup as long as there's an Ethernet connection.
If it is set up correctly it will do it automatically - although it may take a few minutes.
If your clock is way off, you may need to force ntp to sync by doing:
sudo /etc/init.d/ntp stop sudo ntpd -q -g sudo /etc/init.d/ntp start
Could you please visit http://raspberrypi.stackexchange.com/questions/47542/raspberry-pi-wont-update-time ? I have posted details there.
This was absolutely the solution to my problem, but I found it to be temporary until I rebooted. Eventually I caught an error in the shutdown that it couldn't update the hwclock because the hw clock had a future date (no idea how that happened). But the solution was a hwclock update force. That forced the update to the fake hardware clock and then on boot the time was at least close to the current so ntp could do it's job normally.
It is possible to pass those arguments to the `ntpd` daemon along with its configuration file. Don't use `/etc/ntp.conf` as it is the wrong configuration file and is likely to be overwritten at boot. IIRC you should be able to put these startup parameters in `/etc/default/ntpd`.
If you set the Time Zone in
raspi-configthe Raspberry Pi will automatically update the time on boot, if connected to the internet.
I2 Change Timezone
- Select your Geographical Area
- Select your nearest City
Yesto reboot now
See forum post Time does not sync on Pi 3 and with official dongle.
ntpd emits IP/UDP packets with the ToS field set to 0xc0. So that is quite similar to the other issue I (and many others) have with Raspberry Pi3 when operated over a Wi-Fi internal interface.
As a workaround, add the command
/sbin/iptables -t mangle -I POSTROUTING 1 -o wlan0 -p udp --dport 123 -j TOS --set-tos 0x00
to the file
before the exit 0 line. Next, reboot and check.
It should already be updating the time. The NTPD server should start just after the swap file and before SSHD.
Check your /etc/ntp.conf file to make sure it is configured.
It should list at least one server. I use time.nrc.ca for my server.
Manual page for ntp.conf is here: http://linux.die.net/man/5/ntp.conf
My son's Rasberry Pi would not update the time out of the box and after trying all the suggestions above I could get it to update manually but not automatically. Finally after looking elsewhere as well without success, I found that the ntp.conf file that came with the Rasberry Pi had the following lines commented out:
#restrict 127.0.0.1 #restrict ::1
sudo nano /etc/ntp.conf
in the terminal to edit the ntp conf file to now be:
# Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1
That solved the problem for us. It updates with both the WiFi and the ethernet cable. I don't know if it would update with WiFi without the change to rc.local suggested above, as by the time I found the solution above I had already made that change and I have not undone it.
This question is apparently being "recycled" for some reason, and so it seems appropriate to recycle some old answers also :)
This question was asked in 2013.
ntpdwas the timekeeping software included in the Raspbian distribution at that time (
wheezy). However, that changed with the
stretchdistribution in 2017 when
ntpd. The reasons for this change, and some of the technical tradeoffs were discussed in this old answer for those who are interested in such things.
With respect to the question here, perhaps the most salient point in that answer is this: If you decide to install
ntpdunder your current Raspbian distribution, know that
systemd-timesyncdwill "do the right thing"! It will check for the presence of other NTP daemons, and adjust its behavior accordingly; it just works. You can read all about it by entering this at the command line:
$ systemctl cat systemd-timesyncd
Note the last few lines:
# don't run timesyncd if we have another NTP daemon installed
In other words:
systemd-timesyncdchecks to see if any of these alternative time services are running on your system, and if so, it politely defers to them for providing your timekeeping services.
You don't need to use ntp to solve the issue. There is a script that reads the date from a server and you only need set the date to be the result of that script (your Raspberry Pi needs to be connected to the internet). Then, you need to run that command at startup.
Step1: Retrieve the date from a server.
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
Step2: Run the command at startup by adding it to the file
/etc/rc.local(Worked on Ubuntu 16.04).
sudo gedit /etc/rc.local
You may not need to use `ntp` but you should. It's better, faster, more accurate, and the industry standard. Don't make up your own weird things when good standards exist please.
I had a similar problem with a Pi not syncing. None of these solutions worked. Turns out my network environment was blocking the NTP port (123). The solution for me was
sudo apt install htpdate
Which updates the system clock through HTTP calls instead.