LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 10-19-2016, 11:43 PM   #1
Namrata10
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Rep: Reputation: Disabled
How to set time for my raspberry pi?


I am trying to connect my raspberry pi to the ntp server to get the correct time. but somehow I am unable to do that. Can someone please help me out.

I followed the steps from here..
https://victorhurdugaci.com/raspberr...-date-and-time

But every time I restarts it, it takes the time that it had when it was power on. What could be the possible problem?

Thanks.
 
Old 10-20-2016, 06:22 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Post the output from the date command.

Verify that ntp is actually running
ps ax | grep ntp

Post the output of the command
sudo ntpq -p
 
Old 10-20-2016, 06:35 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,356
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Also, since the Rpi does not have a persistent clock, "ntpd" has to be run with the option -g (or options -gq) the first time after each cold boot. The instructions you link to seem to be missing that in the description and point to some remedial action in step number 10. So I'd check to make sure the init script is passing those options to "ntpd" and add them if they are missing.
 
Old 10-20-2016, 07:51 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Been a while since I played with Pi however depending on the distro, if you are attached to an Internet enabled network at boot, this takes care of itself. Last I used one it was a non-attended system to monitor a storage space. The Pi was supposed to be on or capable of booting into the desired application unattended and it required proper date and time since there were date and time stamps on the logs pertaining to the monitoring. We used Raspberian (sp), their default and as I recall there was no need to force NTP to start or restart, instead we just needed to verify that the network had been up and NTP had resolved the date and time so that the application was capable of creating sensible logs.
 
Old 10-21-2016, 12:29 AM   #5
Namrata10
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
sudo ntpq -p gives this output
localhost: timed out, nothing received
***Request timed out

PS I am connected to the internet.
 
Old 10-21-2016, 04:37 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Ntp is not running

sudo /etc/init.d/ntp start
 
Old 10-21-2016, 04:51 AM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,356
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Quote:
Originally Posted by michaelk View Post
Ntp is not running

sudo /etc/init.d/ntp start
If it is not getting launched with the -g option, it will exit. From the manual page: "Normally, ntpd exits with a message to the system log if the offset exceeds the panic threshold, which is 1000 s by default."
 
Old 10-21-2016, 05:00 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Possibly and it depends on what distribution is running on the Pi but typically the init script includes the -g option.
 
Old 10-21-2016, 05:12 AM   #9
Namrata10
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
Tried sudo /etc/init.d/ntp start.
Still ntpq -p gives the same output.
 
Old 10-21-2016, 05:16 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
what is in /etc/ntp.conf?
probably illegal/unreachable time server was configured.
 
Old 11-07-2016, 03:57 AM   #11
Namrata10
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
Sorry for being a little late. This is how the ntp.conf looks like:

# /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.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
server 2.asia.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst


# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
#restrict 127.0.0.1
#restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines. Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient
 
Old 11-07-2016, 04:21 AM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
pan64 is correct.

Quote:
#restrict 127.0.0.1
#restrict ::1
You disabled access. Uncomment the lines and restart ntp. The correct syntax is below.

restrict 127.0.0.1
restrict ::1

Last edited by michaelk; 11-07-2016 at 04:27 AM.
 
Old 11-07-2016, 04:35 AM   #13
Namrata10
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
Did that @michaelk
But still it is taking the same time that it had when last active.
 
Old 11-07-2016, 04:36 AM   #14
Namrata10
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
Do I need to change something here:
# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
 
Old 11-07-2016, 07:30 AM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Your using the Asia pool which should be sufficient.

Now post the output of the ntpq -p command.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Set Up The Raspberry PI Zero LXer Syndicated Linux News 0 02-02-2016 06:10 PM
VPN set up on Raspberry pi queenstdot Debian 1 10-08-2015 05:09 PM
VPN set up on Raspberry pi queenstdot Linux - Newbie 1 10-04-2015 04:08 AM
LXer: How To Set Up The Raspberry PI 2 LXer Syndicated Linux News 0 03-22-2015 06:28 PM
LXer: How to set up the Raspberry Pi LXer Syndicated Linux News 0 04-23-2012 03:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 01:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration