ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Spent 2 Weeks getting NTP to update at Boot, Please Help....

Mon Mar 27, 2017 10:04 am

I tried every suggestion posted in threads on Raspberry Pi Fourms, Stackexchange, SuperUser...

I reflashed my Raspberry Pi Zero because it was a total mess fiddliing with rc.local, ntpd, ntpdate, cronjob ect..

However as i have heard that its not recommended to use ntpdate and stick with the ntpd. But the only thing that got my time to work is by using this..

This

Code: Select all

sudo ntpdate -b -u pool.ntp.org
I tried adding it to cronjob and rc.local.. failed to update... checked systemlogs and didnt show a thing..

Past few weeks i got the firewall configured to send outgoing UDP on port 123.

So i need this to be automatic on startup without entering at commandline.. im running on user, Pi.

Please give suggestions and a step by step Thankyou :(

SurferTim
Posts: 1934
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Mon Mar 27, 2017 12:27 pm

If you are using wifi, I had trouble with my RPi3 and NTP using wifi only. This solved it for me. Maybe it will help you.

Code: Select all

sudo /sbin/iptables -t mangle -I POSTROUTING 1 -o wlan0 -p udp --dport 123 -j TOS --set-tos 0x00
sudo apt-get install iptables-persistent
My advice applies to RaspiOS only. Please mention if you use another OS.

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Mon Mar 27, 2017 12:40 pm

SurferTim wrote:If you are using wifi, I had trouble with my RPi3 and NTP using wifi only. This solved it for me. Maybe it will help you.

Code: Select all

sudo /sbin/iptables -t mangle -I POSTROUTING 1 -o wlan0 -p udp --dport 123 -j TOS --set-tos 0x00
sudo apt-get install iptables-persistent
ill try this and will get back to you, fingers cross :)

Edit: Do i need to do anything else? Edit ntpd.conf? Did a reboot and nothing happened

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Thu Mar 30, 2017 2:47 am

Still having no luck. not sure how yours works. I might be missing something

Heres my configs

http://imgur.com/hN3IbqU

(etc/rc.local)

http://imgur.com/tooIdfO

(home/pi/set_ntp_time.sh)

http://imgur.com/VmsJalf

Thanks..

knute
Posts: 664
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Thu Mar 30, 2017 6:13 pm

You might just try a clean Raspbian install and see if it doesn't just work. Let it boot and run ntpq -p and post the results.

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Fri Mar 31, 2017 2:45 am

knute wrote:You might just try a clean Raspbian install and see if it doesn't just work. Let it boot and run ntpq -p and post the results.
I didn't do much on my second raspbian install, here it is

http://imgur.com/xyTMQWa

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Fri Mar 31, 2017 6:06 am

I read someone's post here about NTP recently, and think it worth to mention here. I dont have Dr Google on phone, so cant just post its URI.

NTP wont set time in a instant way, like set to 9:00 from 8:59, or set to 9:00 from 9:01. Because doing so make time lost its physical nature. Time is continuously and monotonic. Jumping to future or past just break the logic of program. Think about sorting thing according to time.

So NTP dont do so.

NTP would make the time flow fast or slower, to catch up with the truth slowly, while keep the time always flow forward and continuously.

So maybe you should wait some while after boot.

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Fri Mar 31, 2017 9:10 am

allfox wrote:I read someone's post here about NTP recently, and think it worth to mention here. I dont have Dr Google on phone, so cant just post its URI.

NTP wont set time in a instant way, like set to 9:00 from 8:59, or set to 9:00 from 9:01. Because doing so make time lost its physical nature. Time is continuously and monotonic. Jumping to future or past just break the logic of program. Think about sorting thing according to time.

So NTP dont do so.

NTP would make the time flow fast or slower, to catch up with the truth slowly, while keep the time always flow forward and continuously.

So maybe you should wait some while after boot.
Its very frustrating, i sorta get what your saying but im guessing as long as i reboot every couple days to get the time right from a external NTP server.... as im using this as a outdoor motion detectiong where there is no possible way to get ethernet connection to.. WiFi seems to only accept my connection when the time is close to its realtime on the router.

I cannot seem to add a realtime clock addon board because the case for the Raspberry Pi Zero W is the official case.

I guess there will be no possible way for future Pi Zeros to have a builtin realtime clock with some kind of battery to it as it would be too big and not enough space on the PCB board.

Not sure what you mean to wait some time after boot, as i cannot seem to get the startup script to execute /home/pi/set_ntp_time.sh ... or if ntpdate -b -u pool.ntp.org is the only thing that works for me.

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Fri Mar 31, 2017 10:20 am

According to http://www.pool.ntp.org/zh/use.html , the "wait" could as long as half an hour.

If you have a Internet connection, then you dont need ntpdate nor any script, Pi has ntpd equipped. All you need is wait until "ntpq -pn" print an * before a server.

User avatar
scruss
Posts: 3839
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Fri Mar 31, 2017 2:39 pm

If you have network access, ntpd will start very shortly after boot in stock Raspbian and Raspbian Lite distributions. You don't have to do anything to configuration files or firewalls. ntpd will keep the time in sync automatically for as long as it can reach a network. The ‘poll’ column from ntpq -pn tells you how often, in seconds, it resyncs with a time server. This from one of my Raspberry Pis that has been up for a while:

Code: Select all

$ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*129.70.132.34   129.70.130.71    2 u  126 1024  377  132.040   -2.357   4.541
-208.53.158.34   216.93.242.12    3 u  957 1024  377   38.439   -3.759   3.290
+2600:3c03::f03c 192.5.41.209     2 u  451 1024  375   42.436    5.293   5.000
+196.10.52.57    0.60.139.194     2 u  722 1024  377  270.749    0.544   3.068
The offset and jitter values should be non-zero. In the example you posted they were zero, indicating no connection.

So maybe there's something else that's the problem:
  • Does your Zero talk to the network? A quick test would be ping -c 5 raspberrypi.org. If you get ‘64 bytes from …’ results, you're good. ‘… Destination Host Unreachable’ is not good.
  • Have you set your timezone with sudo raspi-config, then 4 Localisation Options followed by I2 Change Timezone? Linux maintains its internal time in UTC, and manages its presentation of time to the user through the timezone system.
  • Apart from setting the time, what are you trying to do with your Zero? There are many (almost far too many) ways to start a task at boot, and you might be going about it the hard way.
I wouldn't worry to much about obfuscating host names. Better to post output as plain text in Code blocks. Also, threads from Raspberry Pi Forums, Stackexchange, SuperUser, etc from before early 2016 will provide misleading information, as the startup process has changed significantly.

The suggested delay-after-startup could be as simple as something like this in cron (edited with crontab -e):

Code: Select all

@reboot			sleep 30; /path/to/the/script/you/want/to/run …
This is pretty crude, and assumes that the clock should be set by ntpd within 30 s of booting.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

knute
Posts: 664
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Fri Mar 31, 2017 6:02 pm

314_PIE wrote:
knute wrote:You might just try a clean Raspbian install and see if it doesn't just work. Let it boot and run ntpq -p and post the results.
I didn't do much on my second raspbian install, here it is

http://imgur.com/xyTMQWa
You are missing the IP addresses under refid. Do you have an internet connection? Does DNS work? Try pinging one of the host names under remote and see if you can get a response.

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Fri Mar 31, 2017 11:52 pm

allfox wrote:According to http://www.pool.ntp.org/zh/use.html , the "wait" could as long as half an hour.

If you have a Internet connection, then you dont need ntpdate nor any script, Pi has ntpd equipped. All you need is wait until "ntpq -pn" print an * before a server.
I left my Pi running for 24 hours, ill keep an eye out for this " * " in ntpq -pn. :)
scruss wrote:If you have network access, ntpd will start very shortly after boot in stock Raspbian and Raspbian Lite distributions. You don't have to do anything to configuration files or firewalls. ntpd will keep the time in sync automatically for as long as it can reach a network. The ‘poll’ column from ntpq -pn tells you how often, in seconds, it resyncs with a time server. This from one of my Raspberry Pis that has been up for a while:

Code: Select all

$ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*129.70.132.34   129.70.130.71    2 u  126 1024  377  132.040   -2.357   4.541
-208.53.158.34   216.93.242.12    3 u  957 1024  377   38.439   -3.759   3.290
+2600:3c03::f03c 192.5.41.209     2 u  451 1024  375   42.436    5.293   5.000
+196.10.52.57    0.60.139.194     2 u  722 1024  377  270.749    0.544   3.068
The offset and jitter values should be non-zero. In the example you posted they were zero, indicating no connection.

Thanks for the information, ill paste them from now on. I do have internet connection and DNS configured correctly.

Code: Select all

pi@PiZeroW:~ $ 
pi@PiZeroW:~ $ ntpq -pn   
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.1.100   .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 27.124.125.252  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 59.167.170.228  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 129.250.35.251  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 104.156.232.147 .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 27.124.125.250  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
pi@PiZeroW:~ $ 
scruss wrote:Does your Zero talk to the network? A quick test would be ping -c 5 raspberrypi.org. If you get ‘64 bytes from …’ results, you're good. ‘… Destination Host Unreachable’ is not good.

Code: Select all

pi@PiZeroW:~ $ ping -c 5 raspberrypi.org
PING raspberrypi.org (93.93.128.230) 56(84) bytes of data.
64 bytes from 93.93.128.230: icmp_seq=1 ttl=48 time=389 ms
64 bytes from 93.93.128.230: icmp_seq=2 ttl=48 time=390 ms
64 bytes from 93.93.128.230: icmp_seq=3 ttl=48 time=392 ms
64 bytes from 93.93.128.230: icmp_seq=4 ttl=48 time=392 ms
64 bytes from 93.93.128.230: icmp_seq=5 ttl=48 time=393 ms

--- raspberrypi.org ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev = 389.621/391.652/393.326/1.514 ms
pi@PiZeroW:~ $
scruss wrote:Have you set your timezone with sudo raspi-config, then 4 Localisation Options followed by I2 Change Timezone? Linux maintains its internal time in UTC, and manages its presentation of time to the user through the timezone system.

Code: Select all

pi@PiZeroW:~ $ sudo raspi-config

Current default time zone: 'Australia/Brisbane'
Local time is now:      Sat Apr  1 07:58:14 AEST 2017.
Universal Time is now:  Fri Mar 31 21:58:14 UTC 2017.
scruss wrote:Apart from setting the time, what are you trying to do with your Zero? There are many (almost far too many) ways to start a task at boot, and you might be going about it the hard way.
Im setting it up as a motion detection security camera for outside driveway, connection via WiFi (builtin Antenna), Im using Raspbian Lite.

scruss wrote:The suggested delay-after-startup could be as simple as something like this in cron (edited with crontab -e):
Ok, is the [ntpd -q -g] the right command to execute at startup? Do i need to change anything in the set_ntp_time.sh

Even if my firewall is blocking UDP 123 which is not.. would still be working?

knute wrote:You are missing the IP addresses under refid. Do you have an internet connection? Does DNS work? Try pinging one of the host names under remote and see if you can get a response.
Ill ping the ones that were pasted above:

Code: Select all

pi@PiZeroW:~ $ 
pi@PiZeroW:~ $ ping -c 3 192.168.1.100
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.
64 bytes from 192.168.1.100: icmp_seq=1 ttl=64 time=1.83 ms
64 bytes from 192.168.1.100: icmp_seq=2 ttl=64 time=4.42 ms
64 bytes from 192.168.1.100: icmp_seq=3 ttl=64 time=4.53 ms

--- 192.168.1.100 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.833/3.597/4.532/1.250 ms
pi@PiZeroW:~ $ ping -c 3 192.168.25.1 
PING 192.168.25.1 (192.168.25.1) 56(84) bytes of data.
64 bytes from 192.168.25.1: icmp_seq=1 ttl=64 time=4.50 ms
64 bytes from 192.168.25.1: icmp_seq=2 ttl=64 time=4.44 ms
64 bytes from 192.168.25.1: icmp_seq=3 ttl=64 time=4.49 ms

--- 192.168.25.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 4.446/4.480/4.501/0.081 ms
pi@PiZeroW:~ $ ping -c 3 27.124.125.252
PING 27.124.125.252 (27.124.125.252) 56(84) bytes of data.
64 bytes from 27.124.125.252: icmp_seq=1 ttl=49 time=82.9 ms
64 bytes from 27.124.125.252: icmp_seq=2 ttl=49 time=81.9 ms
64 bytes from 27.124.125.252: icmp_seq=3 ttl=49 time=82.3 ms

--- 27.124.125.252 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 81.925/82.403/82.934/0.529 ms
pi@PiZeroW:~ $ ping -c 3 59.167.170.228
PING 59.167.170.228 (59.167.170.228) 56(84) bytes of data.
64 bytes from 59.167.170.228: icmp_seq=1 ttl=244 time=31.3 ms
64 bytes from 59.167.170.228: icmp_seq=2 ttl=244 time=34.6 ms
64 bytes from 59.167.170.228: icmp_seq=3 ttl=244 time=33.5 ms

--- 59.167.170.228 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 31.313/33.167/34.631/1.390 ms
pi@PiZeroW:~ $
I seem to unable to ping the router: 192.168.1.100 on eth0 which has router access and 192.168.25.1 on wlan0 which is on a separate bridge interface on Openwrt. I'll start troubleshoot this, even though i can access the internet.. and ping local devices on 192.168.25.1.

Did ntpq -pn again:

Code: Select all

pi@PiZeroW:~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.1.100   .XFAC.          16 u    -  512    0    0.000    0.000   0.000
 27.124.125.252  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 59.167.170.228  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 129.250.35.251  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 104.156.232.147 .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 27.124.125.250  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
Should i stick with debain.pool.ntp.org or to au.pool.ntp.org in ntp.conf
Last edited by ldon13 on Sun Apr 02, 2017 4:28 am, edited 1 time in total.

User avatar
DougieLawson
Posts: 40823
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Sat Apr 01, 2017 5:10 am

Who owns your network? Is there a transparent proxy between your systems and the public internet? Does the network owner provide a LAN based NTP server?

You may need to pick up the phone and call their Networking Helpdesk.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Sat Apr 01, 2017 8:25 am

DougieLawson wrote:Who owns your network? Is there a transparent proxy between your systems and the public internet? Does the network owner provide a LAN based NTP server?

You may need to pick up the phone and call their Networking Helpdesk.
This is my home network, it wouldn't be a good idea for a enterprise network to be configured as a private class C network which will confict with remote users from outside of the network :P

Openwrt has a NTP server that can be configured on the router. I guess that would be the only option to get the time from it. Might have to implement one in each isolated subnet which im planning to do soon.

My network is in Double NAT because of a ISP VoIP bundle. My Apple devices work fine when recieving time automatically from time.apple.com on the same network.

User avatar
DougieLawson
Posts: 40823
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Sat Apr 01, 2017 9:48 am

Your CGNAT network doesn't allows port 123. So you need to shout loudly at your ISP (or change to one that does).

Your other option would be a GPS or DCF77 receiver as a reliable time source.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Sat Apr 01, 2017 10:52 am

DougieLawson wrote:Your CGNAT network doesn't allows port 123. So you need to shout loudly at your ISP (or change to one that does).

Your other option would be a GPS or DCF77 receiver as a reliable time source.
Thanks for the suggestions, if my Apple devices work, then UDP 123 should pass through. ill have another crack at it tomorrow.

Sorry if i explained it wrong, Im getting a public Dynamic IPv4 assigned to my modem so i wouldnt be in a CGNAT. The modem and Openwrt router are in a Double NAT to run the VoIP on VDSL.

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Sun Apr 02, 2017 4:18 am

I implemeted a local NTP server, and it seems to work, getting somewhere now.

Code: Select all

 pi@PiZeroW:~ $ ntpq -p     
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.1.100                     1 u   44   64  377    1.037   -0.498   0.238
pi@PiZeroW:~ $ 

knute
Posts: 664
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Sun Apr 02, 2017 3:59 pm

I got one more idea. Try putting a numerical server IP in ntp.conf instead of the host names for the pools. See if it is a DNS issue somewhere. The only other thing I can think of is after you do that, try running traceroute and see if the route to the server goes out the gateway that will actually get it there.

ldon13
Posts: 35
Joined: Mon Mar 27, 2017 9:46 am
Location: Australia

Re: Spent 2 Weeks getting NTP to update at Boot, Please Help

Mon Apr 03, 2017 12:42 am

knute wrote:I got one more idea. Try putting a numerical server IP in ntp.conf instead of the host names for the pools. See if it is a DNS issue somewhere. The only other thing I can think of is after you do that, try running traceroute and see if the route to the server goes out the gateway that will actually get it there.
DNS is working, My router is working solid for months with the correct time, a local ntp server is best solution for me. Heres an update of the ntpq -pn, my Pis were powered off during the night and powered back on next morning.

Code: Select all

pi@PiZeroW:~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.1.100   202.21.137.10    3 u   44  128  377    3.098   -1.631  28.252 
I got a spare Pi Zero lying around, i could turn it into another NTP server and peer with NTP server on router to sync with each other.

Thanks for all the help guys.

Return to “Troubleshooting”