OpenWrt Forum Archive

Topic: can't start the NTP daemon (openntpd)

The content of this topic has been archived on 29 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I've got a problem with ntp daemon on my router. After installing openntpd package and restarting the daemon doesn't seem to start at all. The symptoms are:
- there is no process called ntpd or similar
root@scorpio2:~# ps | grep ntp
5967 root      1348 S    grep ntp

- the port 123 is not on the netstat list (and I suppose it should?)
root@scorpio2:~# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 *:80                    *:*                     LISTEN
tcp        0      0 *:53                    *:*                     LISTEN
tcp        0      0 *:22                    *:*                     LISTEN
tcp        0     52 192.168.2.1:22          192.168.1.100:50755     ESTABLISHED
udp        0      0 *:53                    *:*
udp        0      0 *:67                    *:*
udp        0      0 *:tftp                  *:*
udp        0      0 192.168.3.2:25826       *:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node Path
unix  6      [ ]         DGRAM                    351    /dev/log
unix  2      [ ]         DGRAM                    1253
unix  2      [ ]         DGRAM                    1097
unix  2      [ ]         DGRAM                    531
unix  2      [ ]         DGRAM                    358

- system log doesn’t have any entry from ntpd
root@scorpio2:~# dmesg | grep ntp
root@scorpio2:~#

- ntp client on the other router can’t connect to my ntp daemon because of “connection refused”


I’m sure that the init script is enabled, but I also tried to start ntpd manually and the response was:
root@scorpio2:~# /usr/sbin/ntpd -s
fatal: stat: No such file or directory
dispatch_imsg in main: pipe closed
Terminating

My /etc/ntpd.conf file looks as follows:
# use a random selection of 8 public stratum 2 servers
# see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers
server 0.openwrt.pool.ntp.org
server 1.openwrt.pool.ntp.org
server 2.openwrt.pool.ntp.org
server 3.openwrt.pool.ntp.org
listen on 192.168.3.2
listen on 192.168.4.2

As you can see I added only two lines with listening interfaces, but even without them the situation remians the same.

What is going on?

Seems that openntpd is not a best solution since it causes many problems. I followed all advices I could find but still no results hmm

So I tried ntpd but again encountered a problem. This time after starting ntpclient I get:
rejected packet: LI==3
and the client does not adjust it's time to server's time...
From the RFC spec I found that LI=3 in SNTP means that the server has not synchronized its clock to any other server. And because my server (router#1) is not synchronized to any other server, my client (router#2) won't synch with #1 and will print "rejected packet: LI==3".
Well, the thing is that I don't want #1 to synchronize to anyone. My routers connect only with each other and don't have internet connection.

Can anyone help me?
I ONLY WANT MY ROUTER#1 TO SYNCHRONIZE ITS DATE AND TIME WITH ROUTER#2 AUTOMATICALLY AFTER EACH STARTUP WITHOUT NEED OF CONNECTION TO ANY NTP SERVER IN THE INTERNET.

It's such a simple thing but I failed to find a solution... How can I use ntpd and ntpclient to get what I need or what workaround can I employ instead of using NTP protocol?

Many thanks in advance.
drobiazg

dump ntpd and install chrony.

Hi cptdondo!

Thanks for your reply, but looks like chrony doesn't work because of the same reason ntpd didn't work.

I installed chrony on both routers and changed /etc/config/ntpd files. On the "time serving" side was:
# Generic NTP configuration
# Time servers and network(s) that may access the time service

config ntpd
        option TimeServers     "0.openwrt.pool.ntp.org 1.openwrt.pool.ntp.org 2.openwrt.pool.ntp.org 3.openwrt.pool.ntp.org"
        option ClientAccessFrom "wifi wifi900"


and on the "client" side:
# Generic NTP configuration
# Time servers and network(s) that may access the time service

config ntpd
        option TimeServers     "192.168.3.1"
        option ClientAccessFrom "lan"


The problem is that in the /etc/init.d/ntpd before starting the whole process there's a line:
while chronyc tracking | grep 'Reference ID.*0.0.0.0' >/dev/null ; do sleep 1; done
For me it looks like waiting for synchronization with another time server and this won't happen without internet connection... So the script stucks.

I tried removing list of time servers from /etc/config/ntpd - no results, script still stucked.
Also tried removing this waiting line from /etc/init.d/ntpd - no results, script finally not stucked and finished but no time synchronization observed after that.
Also tried installing ntpclient instead of chrony on the client side - agin no results, command `ntpclient -s -h 192.168.3.1` prints out:
recvfrom: Connection refused

HOW SHOULD I CONFIGURE CHRONY?

If you can get GPS signals, I'd get a $30 GPS puck, install gpsd, and sync the time to the gps as the primary clock and the internet as the backup.  That's my setup and it works 100% of the time.

Regarding your original problem with the ntpd daemon not starting, you might consider using the init script instead of invoking ntpd directly. That is:

root@scorpio2:~# /etc/init.d/ntpd start

HTH

I tried "/etc/init.d/ntpd start" but the result still was:
dispatch_imsg in main: pipe closed
Terminating

I found out somewhere that ntpd needs some directories created but intit.d script includes creating them. Anyway I created them manually again with no results.

GPS probably is a solution, but there must be a way to get over my problem without it, don't you think?

Any ideas appreciated!
So far the best results I had with ntpd + ntpclient (but there was this LI==3 issue). Maybe there's a way to fool ntp daemon and make it thinking it is already synchronized so the client will synchronize with it?

I had the same problems that drobiazg describes here trying to start openntpd - 3.9p1-3 installed on my Backfire 10.03 r20728 system.

As it turned out after I edited ntpd.conf to ensure that the line for servers was properly formatted for syntax I was able to start the daemon.  In my case I had mistakenly used 'server' to define a multi-server pool and I just needed to edit it to 'servers' (http://www.openbsd.org/cgi-bin/man.cgi?query=ntpd.conf)

root@xxx:~# cat /etc/ntpd.conf
servers 3.us.pool.ntp.org
listen on 192.168.1.1

As an aside openntpd 3.9p1-3 apparently does not include the ntpd.conf check function  documented at that page.

root@xxx:~# ntpd -n
ntpd: invalid option -- n
usage: ntpd [-dSs] [-f file]

(Last edited by valuequest on 15 Nov 2011, 15:39)

There are lots of reasons that the openntp ntpd might terminate at startup.
One way to narrow the problem down is to start ntpd manually undaemonized,
doing this will start the daemon in foreground and provide more detailed info to stderr.


 root@xyzzy:~# /usr/sbin/ntpd -sd

I got an error that included this line:
fatal: client_query socket: Address family not supported by protocol (That's EAFNOSUPPORT)
The cause was that openntp attempts to open an AF_INET6 socket.  My kernel didn't support
that protocol because I didn't include the kmod-ipv6 package (actually I'd pulled it to save space).
So you might include kmod-ipv6, if it isn't already installed.

For whatever it may be worth by the way I think I've discovered it to be necessary to delete the /etc/config/system setting for rdate (which appears to have been a default setting for builds before 28612) before the openntpd daemon will start.

Here is what I think to be a related question... why does a "/etc/init.d/ntpd stop" command as given below not actually stop the ntpd daemon even though it reports back "Terminated"?

root@hostname:~# ps | grep ntp
 1752 network    532 S    /usr/sbin/ntpd -s
 1754 root       520 S    /usr/sbin/ntpd -s
 1923 root       936 S    grep ntp
root@hostname:~# /etc/init.d/ntpd stop
Terminated
root@hostname:~# ps | grep ntp
 1752 network    532 S    /usr/sbin/ntpd -s
 1754 root       520 S    /usr/sbin/ntpd -s
 1927 root       936 S    grep ntp
root@hostname:~#

(Last edited by valuequest on 15 Nov 2011, 15:45)

Probably because the init script is badly written, using "killall ntpd" which just kills the initscript itself instead of the running daemon.

The discussion might have continued from here.