NTP with DCHP


9 posts
by alfonso82 » Wed Dec 12, 2012 3:23 am
Hi, this is my first post on the forum, I have searched the forum for an answer with no luck, I´m trying to get my Pi to update the date and time using NTP and I have tried every solution on the forum and I came to a conclution that the DHCP configuration of my wireless router is screwing up my Pi and not letting it get connected to the NTP servers, I´m a noob when it comes to linux so a step by step answer will be appreciated and thank you in advance.
Posts: 10
Joined: Wed Nov 21, 2012 12:55 am
by efflandt » Wed Dec 12, 2012 6:53 am
Judging from the system logs and /etc/services, ntp uses UDP port 123 to poll ntp servers and that should happen soon after you get IP and everything from a dhcp server (your router).

Does following command show an IP address for eth0 (or wlan0 if wireless): ifconfig

Does following show a default gateway (UG) to your router IP: route -n

Does following show at least one nameserver (often router IP): cat /etc/resolv.conf

Does /var/log/syslog show eth0 errors or any USB devices dropping out (a sign of not enough voltage or something on USB using too much power or not supported).
Posts: 359
Joined: Mon Dec 03, 2012 2:47 am
Location: Elgin, IL USA
by alfonso82 » Wed Dec 12, 2012 2:10 pm
First of all thank you efflandt for a quick reply, I have my Pi connected using wireless module and in the ifconf I only have the SSID and password of my wireless lan, I maneged to fix the IP address of my Pi thru my wireless router, because I´m using it as a headless box ;) .

The route -n command it shows the IP address of my router as the gateway wich I guess is the way it should be.

On cat /etc/resolv.conf I have as a servername the IP address of my router

And finally in the /var/log/syslog I have a LOT of entries and I could´nt find any related to my internet connection or NTP

Thank you one more time for your help
Posts: 10
Joined: Wed Nov 21, 2012 12:55 am
by morgad » Thu Dec 13, 2012 10:20 pm
my ntp servers and clients run under dhcp with no problem

could you post your /etc/ntp.conf file? and the result of 'grep ntpd /var/log/daemon.log' ?

best regards
Dave
Posts: 15
Joined: Sun Jan 29, 2012 10:24 pm
by alfonso82 » Thu Dec 13, 2012 11:00 pm
Hi morgad, this is my /etc/ntp.conf file:
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.timeserver.com

# 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 1.debian.pool.ntp.org iburst
#server 2.debian.pool.ntp.org iburst
#server 3.debian.pool.ntp.org iburst
server 0.south-america.pool.ntp.org
server 1.south-america.pool.ntp.org
server 2.south-america.pool.ntp.org
server 3.south-america.pool.ntp.org
server 4.br.pool.ntp.org

# 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


And this is my /var/log/daemon.log file is too large to post it.

May be if you give me some instruction on what you did to get your Pi working on DHCP I could get mine too and thank you.
Posts: 10
Joined: Wed Nov 21, 2012 12:55 am
by morgad » Fri Dec 14, 2012 8:43 pm
Hi
I did nothing to get ntp working with dhcp, it just works.
(I am running Rasbian here)

I tried your ntp.conf file, and it worked (although there are some minor problems)
Code: Select all
$ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 176.74.176.167  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
-200.69.222.89   170.210.222.2    4 u  113  128  377  238.287    1.285   0.467
*200.186.125.195 .ONBR.           1 u   35  128  377  206.004    0.710   0.425
+200.37.61.61    149.20.64.28     2 u  107  128  377  181.360   -1.930   0.662
+200.192.232.8   200.160.7.186    2 u  103  128  377  245.560    4.458   0.513

(ntp.timeserver.com is not an ntp server, server 4.br.pool.ntp.org does not resolve (only 0-3 prefixes are valid))

if ntpq -pn gives 'ntpq: read: Connection refused' then ntp is not running, try
'tail -f /var/log/daemon.log' in one terminal window and then 'sudo service ntp restart' in the other
and see if you get any error messages in the log, my running systems gives
Code: Select all
Dec 14 18:08:53 raspberrypi2 ntpd[4912]: ntpd 4.2.6p5@1.2349-o Fri May 18 20:30:57 UTC 2012 (1)
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: proto: precision = 1.000 usec
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: Listen normally on 1 lo 127.0.0.1 UDP 123
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: Listen normally on 2 eth0 192.168.1.27 UDP 123
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: peers refreshed
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: Listening on routing socket on fd #19 for interface updates
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: restrict: error in address '::' on line 39. Ignoring...
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: restrict: error in address '::1' on line 43. Ignoring...
Dec 14 18:08:53 raspberrypi2 ntpd[4913]: Deferring DNS for 4.br.pool.ntp.org 1
Dec 14 18:08:53 raspberrypi2 ntpd[4933]: signal_no_reset: signal 17 had flags 4000000
Dec 14 18:08:55 raspberrypi2 ntpd_intres[4933]: host name not found: 4.br.pool.ntp.org
Dec 14 18:09:57 raspberrypi2 ntpd_intres[4933]: host name not found: 4.br.pool.ntp.org
Dec 14 18:11:59 raspberrypi2 ntpd_intres[4933]: host name not found: 4.br.pool.ntp.org
Dec 14 18:16:01 raspberrypi2 ntpd_intres[4933]: host name not found: 4.br.pool.ntp.org
Dec 14 18:24:04 raspberrypi2 ntpd_intres[4933]: host name not found: 4.br.pool.ntp.org
Dec 14 18:40:07 raspberrypi2 ntpd_intres[4933]: host name not found: 4.br.pool.ntp.org

on your ntp.conf file

hope this helps narrow down the problem

best regards
Dave
Posts: 15
Joined: Sun Jan 29, 2012 10:24 pm
by pluggy » Fri Dec 14, 2012 8:53 pm
Anybody established if the OP's internet works yet ?

Code: Select all
ping 8.8.8.8
ping www.google.com


Would be a reasonable starting place. The internet settings being right aren't the same as the internet actually working.

The standard ntp settings work fine, if there is an internet connection
Don't judge Linux by the Pi.......
User avatar
Posts: 2428
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by alfonso82 » Sat Dec 15, 2012 12:12 am
Hi morgad, I fixed what you found on my /etc/ntp.conf file and then I did a reboot and I still get no awnser from any ntp server, and when I run ntpq -pn I get this:

Code: Select all
     remote           refid      st t when poll reach   delay   offset  jitter
======================================================
 200.160.0.8     .INIT.          16 u    -   64    0    0.000    0.000   0.000
 200.186.125.195 .INIT.          16 u    -   64    0    0.000    0.000   0.000
 200.192.112.8   .INIT.          16 u    -   64    0    0.000    0.000   0.000
 200.1.22.6      .INIT.          16 u    -   64    0    0.000    0.000   0.000


When I try the "tail -f /var/log/daemon.log" I get:

Code: Select all
Oct 29 20:50:38 raspberrypi ntpd[2189]: ntpd exiting on signal 15
Oct 29 20:50:40 raspberrypi ntpd[2640]: ntpd 4.2.6p5@1.2349-o Fri May 18 20:30:5                                                                                        7 UTC 2012 (1)
Oct 29 20:50:40 raspberrypi ntpd[2641]: proto: precision = 1.000 usec
Oct 29 20:50:40 raspberrypi ntpd[2641]: Listen and drop on 0 v4wildcard 0.0.0.0                                                                                         UDP 123
Oct 29 20:50:40 raspberrypi ntpd[2641]: Listen normally on 1 lo 127.0.0.1 UDP 12                                                                                        3
Oct 29 20:50:40 raspberrypi ntpd[2641]: Listen normally on 2 wlan0 192.168.0.122                                                                                         UDP 123
Oct 29 20:50:40 raspberrypi ntpd[2641]: peers refreshed
Oct 29 20:50:40 raspberrypi ntpd[2641]: Listening on routing socket on fd #19 fo                                                                                        r interface updates
Oct 29 20:50:40 raspberrypi ntpd[2641]: restrict: error in address '::' on line                                                                                         41. Ignoring...
Oct 29 20:50:40 raspberrypi ntpd[2641]: restrict: error in address '::1' on line                                                                                         45. Ignoring...
Oct 29 20:59:13 raspberrypi ntpd[2641]: ntpd exiting on signal 15
Oct 29 20:59:15 raspberrypi ntpd[2723]: ntpd 4.2.6p5@1.2349-o Fri May 18 20:30:57 UTC 2012 (1)
Oct 29 20:59:15 raspberrypi ntpd[2724]: proto: precision = 1.000 usec
Oct 29 20:59:15 raspberrypi ntpd[2724]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
Oct 29 20:59:15 raspberrypi ntpd[2724]: Listen normally on 1 lo 127.0.0.1 UDP 123
Oct 29 20:59:15 raspberrypi ntpd[2724]: Listen normally on 2 wlan0 192.168.0.122 UDP 123
Oct 29 20:59:15 raspberrypi ntpd[2724]: peers refreshed
Oct 29 20:59:15 raspberrypi ntpd[2724]: Listening on routing socket on fd #19 for interface updates
Oct 29 20:59:15 raspberrypi ntpd[2724]: restrict: error in address '::' on line 41. Ignoring...
Oct 29 20:59:15 raspberrypi ntpd[2724]: restrict: error in address '::1' on line 45. Ignoring...
Oct 29 20:59:53 raspberrypi wpa_supplicant[1504]: wlan0: WPA: Group rekeying completed with 14:d6:4d:38:3a:54 [GTK=TKIP]


The last thing that I´m guessing is that my router is blocking the ntp servers.

And yes pluggy that was the fisrt thing that I did, if I could ping any site.
Posts: 10
Joined: Wed Nov 21, 2012 12:55 am
by adam van gaalen » Fri Apr 11, 2014 1:10 pm
Make sure you have a line like (10.0.0.138 is my DHCP-server):
server 10.0.0.138 iburst
in your file:
/var/lib/ntp/ntp.conf.dhcp

I even added some more lines:
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

And all work well now!
Posts: 18
Joined: Sun Jul 01, 2012 11:51 am