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?

    I'm running Raspbian and the Raspberry Pi is connected using an Ethernet cable.

    Mine already does that out of the box. What disto are you using?

    works as it is, somehow

    You need Internet connectivity for ntpd to have servers to ask.

    @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:

    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, as described here:

    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.

    Seems that no one has yet answered this question satisfactorily - i.e. how to sync time via NTP after a boot (i.e. without rebooting).

  • 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 timedatectl status

    In case of warning, you may have to run sudo timedatectl set-local-rtc true too.

    Thanks, this finally helped me out, and seems to be the proper way, despite previous answers.

    That is the best answer, helped me a lot. You can use 'sudo' to avoid typing your password (useful for scripts that run it). What is the purpose of the seconds command? set-local-rtc

  • Do an apt-get install ntpdate .

    ntpdate will run when an Ethernet interface is brought up, and set the time from an ntp server (see /etc/default/ntpdate).

    If ntpd is running, ntpdate will do nothing, however ntpdate will run prior to ntpd at bootup - so this should work out to set the time at bootup as long as there's an Ethernet connection.

    stock Raspbian will have all this already.

    @scruss mine didn't. (2013-02-09 wheezy rasbian)

    Mine also did not, had to do it manually.

    If it is set up correctly it will do it automatically - although it may take a few minutes.

    `Linux raspberrypi 4.14.30-v7+ #1102 SMP Mon Mar 26 16:45:49 BST 2018 armv7l GNU/Linux` didn't have it too.

  • 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

    It returns error "sudo: ntpd: command not found"

    ntpd must be installed to use the command

    It **is** installed, I am not that ignorant :)

    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`.

    /etc/init.d/ntp does not exist

  • 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

    this worked well for me

    `I2 Change Timezone` option doesn't exist any more

    It does exist, at least in Raspbian Buster.

    "Internationalisation Options" is now called "Localisation Options"

  • 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.

    I had the same issue as Iinstalled the RPi3 I got for XMas,and you solved my problem. Great !!!

  • 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 for my server.

    Manual page for ntp.conf is here:

  • 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 ::1

    I used

    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 ::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. ntpd was the timekeeping software included in the Raspbian distribution at that time (wheezy). However, that changed with the stretch distribution in 2017 when systemd-timesyncd replaced 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 ntpd under your current Raspbian distribution, know that systemd-timesyncd will "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-timesyncd checks 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 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.

    It doesn't help much if your RasPi is running 24/7.

  • 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

    taken from:

    Which updates the system clock through HTTP calls instead.

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM