colt_cc
Posts: 4
Joined: Thu Aug 30, 2012 7:51 pm

NTP / time settings

Thu Aug 30, 2012 8:01 pm

Hi all. First post. I'm using wheezy. My pi lives in a rural location that is subject to frequent short power outages. When the the pi powers back up, it does so quicker than my router can re-acquire its internet connection. So when it tries to update its time from an NTP server it fails because it has no internet access. I believe that's what is causing some mysterious time inaccuracies on my pi. (It's not off by an integral number of hours so the time zone isn't the problem.)

Can anyone point me towards a way to have the pi keep trying a bit harder for a bit longer to get a proper time? (Yes, I know I should just get a decent UPS or something...)

Or is there a place where detailed NTP logs are saved so I can try to dig a little deeper?

Many thanks

Left_Guard
Posts: 3
Joined: Sun Sep 02, 2012 8:33 am

Re: NTP / time settings

Sun Sep 02, 2012 8:37 am

I have the same problem.
My Pi is powered from a USB socket on the back of my modem and boots up much faster, if the modem restarts for any reason, and, as a result, my system time is well out from what it should be.
I'll post back, if I find a solution.

Left_Guard
Posts: 3
Joined: Sun Sep 02, 2012 8:33 am

Re: NTP / time settings

Sun Sep 02, 2012 2:34 pm

I (think) it's mission accomplished.

Having searched for information and having followed links to
http://raspberrypi.stackexchange.com/qu ... ystem-time
and
http://www.wikihow.com/Change-the-Timezone-in-Linux
this is how I did it.

I'm using Raspbian (Wheezy), meaning NTP is already installed, so I used

Code: Select all

sudo nano /etc/rc.conf
to create a file into which I put the line

Code: Select all

DAEMONS=(!hwclock ntpd)
.
After

Code: Select all

sudo reboot
the date was correct, but the time was one hour slow, so I then used

Code: Select all

sudo ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
which, after another dose of

Code: Select all

sudo reboot
, got the time in line with my local UK time.
Anyone not in the UK would have to search through /usr/share/zoneinfo's subdirectories to find the most appropriate location to change to symbolic link target to.

That's what seems to have worked for me.
I hope it works for you and anyone else who tries it.

If anyone with more experience than myself knows an easier way, of course....

colt_cc
Posts: 4
Joined: Thu Aug 30, 2012 7:51 pm

Re: NTP / time settings

Sun Sep 02, 2012 2:45 pm

Great, thanks for that, I will experiment. I was on the verge of running (as a cron job on reboot) a script to wait a while (to give the router time to come up) and then try NTP. Your solution looks like much less of a botch! Thanks

Oric Tosh
Posts: 3
Joined: Fri Aug 31, 2012 6:46 pm

Re: NTP / time settings

Sun Sep 02, 2012 10:00 pm

Hi,
I'm also using Raspbian (Wheezy)
The way I have setup my NTP time server for the Raspi to keep correct time was to edit this file
/etc/ntp.conf

Remove the hash(#) from the line below *You need to talk to an NTP server or two (or three)*
type the URL of the time server in front of server. such as ntp.timeserver.com

I also setup a rc.conf file the same as you have but found some more information on how to make it run faster, add ntpdate so your file looks this:
DAEMONS=(!hwclock ntpd ntpdate)

Source: http://raspberrypi.stackexchange.com/qu ... ystem-time

Hope that's useful

Left_Guard
Posts: 3
Joined: Sun Sep 02, 2012 8:33 am

Re: NTP / time settings

Mon Sep 03, 2012 10:41 am

Okay.
Watch this space. More to come, because....

Logged into my Pi today, to find the time two hours slow again!
Modem must have rebooted overnight, for some reason, (Note to self: Get a new modem. This one started randomly rebooting two weeks ago and you've no idea why) and the Pi hasn't got the right local time now.
Hey, ho. Back to work on it.

shaun5
Posts: 3
Joined: Wed Oct 03, 2012 6:40 pm

Re: NTP / time settings

Tue Oct 16, 2012 6:40 pm

I can not get the system time to update. Do I need to make rc.conf executable? I thought ntpd -gq would update the time, but it doesn't seem to be working either.

W. H. Heydt
Posts: 16363
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: NTP / time settings

Tue Oct 16, 2012 7:48 pm

If you have power issues...whether it's sags and surges or outages (brief or otherwise), or even if you think your power is reliable...

Get an Uninteruptable Power Supply (UPS). Put not only your Pi and PC on it, but you networking equipment (modem, router, switches, etc.) on it as well. If you can't get everything on one UPS, get however many you need. If you want to isolate your network gear, get small UPS (<500VA) for the network and a larger one for other equipment.

Doing this will save you much grief in the long run...and not just with the Pi. There will be less wear and tear on your electronics, you won't lose work because your machine dropped, you won't be rebuilding corrupted SD cards, you'll be able to ignore brief power interruptions, and you'll be able to do an orderly shutdown in longer interruptions.

Just to give a concrete example from a few years ago... I was running convention registration when the power went out in the hotel we were using for the con. I had my crew process the registrations they were already working on and then we did a controlled shutdown of 4 PCs, two impact printers, and a Linux server, plus the associated network bits that tied it all together ....all because it was all running on two 1.5KVA UPS'. The power was out for about 3 hours. When we got power back, everything came back up smoothly with no glitches and no file corruption.

You never know when or where you'll have a power outage.

blades
Posts: 10
Joined: Wed Oct 10, 2012 8:21 am

Re: NTP / time settings

Tue Nov 13, 2012 1:14 pm

Left_Guard wrote:I (think) it's mission accomplished.

Having searched for information and having followed links to
http://raspberrypi.stackexchange.com/qu ... ystem-time
and
http://www.wikihow.com/Change-the-Timezone-in-Linux
this is how I did it.

I'm using Raspbian (Wheezy), meaning NTP is already installed, so I used

Code: Select all

sudo nano /etc/rc.conf
to create a file into which I put the line

Code: Select all

DAEMONS=(!hwclock ntpd)
.
After

Code: Select all

sudo reboot
the date was correct, but the time was one hour slow, so I then used

Code: Select all

sudo ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
which, after another dose of

Code: Select all

sudo reboot
, got the time in line with my local UK time.
Anyone not in the UK would have to search through /usr/share/zoneinfo's subdirectories to find the most appropriate location to change to symbolic link target to.

That's what seems to have worked for me.
I hope it works for you and anyone else who tries it.

If anyone with more experience than myself knows an easier way, of course....
I was looking for ages for a workaround about the non real clock Pi and it seems your post gave real time to my Pi.Thanx a lot.

f0rd0prefect
Posts: 31
Joined: Fri May 17, 2013 11:58 am

Re: NTP / time settings

Fri May 17, 2013 12:09 pm

Hi,
I'm wondering about the successful settings.
AFAIK, Debian has not a rc.conf.
AFAIK you mix up two distros: Debian (SysV style init process) and Arch (BSD style init process). Wikipedia has a brief explanation here: http://en.wikipedia.org/wiki/Init.
Greetings
Herbert

really
Posts: 2
Joined: Mon Nov 11, 2013 4:09 am

Re: NTP / time settings

Mon Nov 11, 2013 4:19 am

So , I guess I'm not the only one who had to tackle this problem...
but I still haven't solved the problem
my PI is always 36 days behind,
I dont know why, I dont want to re-install it , again,
my Timezone is correct,
I want my PI to check the network time at boot, and adjust it's clock accordingly....
can one of you ( with NTP success ) post me the content of ntp.conf, because I can't see where is the problem with my PI
or is there a command to force ntp daemon to adjust time?

Thanks

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

Re: NTP / time settings

Tue Nov 12, 2013 12:55 am

really wrote:So , I guess I'm not the only one who had to tackle this problem...
but I still haven't solved the problem
my PI is always 36 days behind,
I dont know why, I dont want to re-install it , again,
my Timezone is correct,
I want my PI to check the network time at boot, and adjust it's clock accordingly....
can one of you ( with NTP success ) post me the content of ntp.conf, because I can't see where is the problem with my PI
or is there a command to force ntp daemon to adjust time?

Thanks
NTP won't normally reset the clock if it's off by more than 1000s.

If you run 'ntpd -gq' it ignores the clock being way adrift from ntp time and will force it to be correct then close. The old ntpdate program does the same thing.

You need an active Internet connection to run NTP.

My ntp.conf (on my RPi blank lines and comments removed)

Code: Select all

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
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

really
Posts: 2
Joined: Mon Nov 11, 2013 4:09 am

Re: NTP / time settings

Tue Nov 12, 2013 3:28 am

Thanks it really helped,

turns out , the 1000s was the culprit....
Thanks again, I been cranking on this for hours...

jissoune
Posts: 1
Joined: Mon Nov 24, 2014 8:31 pm

Re: NTP / time settings

Mon Nov 24, 2014 8:49 pm

Tks a lot , after some hours spend to configure the ntp.conf I finally thanks to you succeeded to have the correct time settings on my raspberry pi

delboy711
Posts: 1
Joined: Wed Jan 07, 2015 3:19 pm

Re: NTP / time settings

Wed Jan 07, 2015 3:26 pm

This thread is a bit old, but for people with similar questions there is an easier way than using ntp.

If you install the chrony package (ntp will be removed aitomatically)
Then on the next boot the date will be correct. (You may need to wait a minute or 2)
Chrony uses the NTP protocol just like ntp does, only it does it better. Especially for computers not permanently attached to the internet.

If you want chrony to use a different time server edit /etc/chrony/chrony.conf

bartonlp
Posts: 2
Joined: Sun Feb 08, 2015 9:06 pm

Re: NTP / time settings

Fri Mar 13, 2015 3:13 am

It appears that the Raspean that come with the new PI2 has almost everything working. The only thing I had to do was symlink the /etc/localtime to the correct /usr/share/zoneinfo file for my timezone. The ntpd already runs with -gq etc.

Glad this is fixed, on my old PI B+ I had to fiddle around and get ntpdate etc.

Spartan
Posts: 7
Joined: Tue Dec 02, 2014 2:57 am

Re: NTP / time settings

Wed Apr 29, 2015 9:15 pm

Unfortunately, the Pi2 might still have that issue.

Right now I'm working with two Pi 2s, and one of them had the time perfect after setting up the timezone and location, but the other had a 10min late time, and only corrected until I reset the service.

sudo /etc/init.d/ntp restart

I leave my Pi's running alone and I need to relay on them to have the time correctly.

So, I'm going to try chrony.

Thanks

-Daniel

mh348
Posts: 2
Joined: Wed May 06, 2015 4:33 pm

Re: NTP / time settings

Thu May 28, 2015 8:12 pm

Check your DHCP server, it might be issuing an ntp ip so the Pi won't use the one you specify in the config. To fix the issue I suggest You remove the ntp server entry from your dhcp server.

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

Re: NTP / time settings

Fri May 29, 2015 7:30 am

You could also update /etc/init.d/ntp by removing

Code: Select all

if [ -e /var/lib/ntp/ntp.conf.dhcp ]; then
        NTPD_OPTS="$NTPD_OPTS -c /var/lib/ntp/ntp.conf.dhcp"
fi
it won't use any DHCP NTP server.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

standin000
Posts: 19
Joined: Wed Dec 03, 2014 5:34 am

Re: NTP / time settings

Fri Feb 03, 2017 7:51 am

colt_cc wrote:Hi all. First post. I'm using wheezy. My pi lives in a rural location that is subject to frequent short power outages. When the the pi powers back up, it does so quicker than my router can re-acquire its internet connection. So when it tries to update its time from an NTP server it fails because it has no internet access. I believe that's what is causing some mysterious time inaccuracies on my pi. (It's not off by an integral number of hours so the time zone isn't the problem.)

Can anyone point me towards a way to have the pi keep trying a bit harder for a bit longer to get a proper time? (Yes, I know I should just get a decent UPS or something...)

Or is there a place where detailed NTP logs are saved so I can try to dig a little deeper?

Many thanks

try add

Code: Select all

# 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
to /etc/network/interfaces, it will wait network is OK.

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

Re: NTP / time settings

Fri Feb 03, 2017 1:05 pm

standin000 wrote: try add

Code: Select all

# 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
to /etc/network/interfaces, it will wait network is OK.
Don't do that on Jessie, it will break things. Use the raspi-config option to "wait for network".
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

kloosusa
Posts: 1
Joined: Wed May 17, 2017 11:07 pm

Re: NTP / time settings

Wed May 17, 2017 11:09 pm

Just get and RTC from adafruit.

lerner
Posts: 660
Joined: Sun Mar 29, 2015 12:12 am

Re: NTP / time settings

Wed Aug 09, 2017 7:06 am

Hi guys/gals.

I'm stuck on this thing too.

(Well I think I this is the right place/topic.)

I have a PI with a RTC. It kinda keeps time. Enough for what I need.

But that isn't the problem. This is:

I hope I have set it up correctly as an NTP for my network.
When I first set it up I used a laptop (M$) and it had a program to check NTP time/s.
I clicked on the program and it said my NTP was good. I was happy.
AFAIK, my NAS sees it on boot and the time is set there correctly, or as per the RTC on said PI.

"Things have changed" and I am wanting to now ask the time from other PIs on the network.
(They boot, and get their time from that NTP server.)

It isn't happening for some reason.

I log into the NTP machine and ask it the time (date command) and it returns a reasonable enough date.

In the /etc/ntp.conf of the other PIs I have edited it to point to the IP address, and tried variants - all to no avail.
They structure of the NTP server lines is vague and that isn't helping me enter the right stuff.

On Jessie, what file tells the PI to look at the NTP and get the time?
Is it /etc/ntp.conf?

Here is an extract of mine:

Code: Select all

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift


# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

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


# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
#server 0.debian.pool.ntp.org iburst

server 0 tic.net.telstra.net iburst
server 1 192.168.0.99
Now, before I am flamed: I have tried and in a line from the ORIGINAL part:
#server ntp.your-provider.example
It isn't 0.ntp.your-provider.example...

Code: Select all

server 0.tic.net.telstra.net iburst
and it works, as well as without the "extra" . (dot)
My local NTP is the 192.168.0.99 one.
It is set up as second only because I left the ZERO server alone.
If it is not connected to the BIG network, and only my network, when any other pi boots, it boots to EPOC date - or what ever the default name is.

So I am suspicious that it is something on the .0.99's side of things, but all the posts seem to skim that part of it, OR: I have done what they say and am not getting any result.
The "thing" is that I can't seem to find/resolve a command to tell the PI to "ask the NTP what time it is" that works in my setup.
Weirdly though, (and as said earlier) if all is connected to the BIg internet, the times are set.

Beats me.

User avatar
jahboater
Posts: 8829
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: NTP / time settings

Wed Aug 09, 2017 8:04 am

To set the time zone without adding symlinks by hand:

Code: Select all

sudo dpkg-reconfigure tzdata

gbayler
Posts: 11
Joined: Sat Aug 12, 2017 7:48 pm

Re: NTP / time settings

Sat Aug 12, 2017 9:19 pm

Hi lerner,

/etc/ntp.conf is the right configuration file. According to the ntp.conf man page, the structure of the server line is:
server address [options ...]
That is, there is no digit 0 or 1 between server and address. The 0. in the example you quoted belongs to the address itself.

Also, I noticed a typo in your first server line: instead of tic.net.telstra.net, it should be tic.ntp.telstra.net. Can it be that there is an additional server line in your ntp.conf, maybe a few lines above or below the block you are editing? Otherwise, I cannot explain how this configuration can work.

Anyways, the correct server lines in the /etc/ntp.conf of your client-Pis should be in my opinion

Code: Select all

server tic.ntp.telstra.net iburst
server 192.168.0.99 iburst
(The option iburst after the address speeds up the synchronization after starting the client.)

Hope that helps!

Günther

Return to “Beginners”