OpenWrt Forum Archive

Topic: clock sync with the network time

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

the time and date which will be get from linux command 'date' is not in sync with network time.It is connected to network and ntpd is running in background .Even though time is not synchronized. Is there any solution for it?

Check the timezone settings (https://wiki.openwrt.org/doc/uci/system)

Ensure that the time zone is correct in relation to where the device is physically located. Then ensure that the configured NTP servers are reachable (ping / traceroute / DNS tests)

If the connectivity test fails, especially that the NTP servers are unreachable, then you'll need to dive into the reasons of why this happens. Perhaps there's a firewall somewhere that is blocking the NTP traffic?

If the connectivity test succeeds, then I'd look for the privileges that the NTP client program is running with. Is it allowed to modify the time settings of the system? Perhaps the NTP client program is faulty, and doesn't set the time correctly for some reason? Maybe there's something in 'dmesg' about the problem?

Next you might want to look at either https://wiki.openwrt.org/doc/uci/ntpclient or https://wiki.openwrt.org/doc/howto/ntp.client, depending on which one is more appropriate for your system.

The magic of Linux (and OpenWRT) is that there's more than fifty tools to do the same job, and the choice depends entirely on preference smile

A quick test on my Chaos Calmer 15.05.1 reveals that ntpd is implemented by busybox. Hence, from the three Wiki articles that I linked before, the last one is most current.

timezone has set correctly as UTC.And servers are also reachable.

I have two Mediatek chips which is running by openwrt. One is shoeing correct date and time and one not. I have compared the settings of the two. But both are same. Privilege of ntpd is same in two.Is there anything else to be done ?. Please find the config below.


config system
        option timezone 'UTC'
        option hostname 'mylinkit'
        option firmware_version 'v0.9.3'
        option loader_version 'v0.8.2'
        option linkit_firstboot '1'
        option log_type 'file'
        option log_size 100000
        option log_buffer_size 2048
        option log_remote '1'  # Need to turn this off to log locally.
        option log_ip 10.15.0.158
        option log_port 514

config timeserver 'ntp'
        list server '0.openwrt.pool.ntp.org'
        list server '1.openwrt.pool.ntp.org'
        list server '2.openwrt.pool.ntp.org'
        list server '3.openwrt.pool.ntp.org'
        option enabled '1'
        option enable_server '0'

aneeshya.rose wrote:

I have two Mediatek chips which is running by openwrt. One is shoeing correct date and time and one not. I have compared the settings of the two. But both are same. Privilege of ntpd is same in two.Is there anything else to be done ?

What do you mean by "two Mediatek chips"? Do you have two separate router devices, both running OpenWRT? If so, are these two routers placed one after another i.e. the Internet-connection of one router goes through the second one, or are they equal in terms, meaning both routers connect to available ports of a third router, through which your traffic goes to the Internet?

If the routers are chained together, then it might be the firewall rules of the first one that prevent the second one from getting the proper time and date. If they are equal in terms, and the configuration is exactly the same on both routers, then perhaps the other router is just broken?

No. Two chips are not connected one after another. They are separately connected to the network as two devices. What I am saying that even though two devices have same configuration, one device is acting different than the other (not getting the exact date and time) .

I'm out of ideas then. There might be tools for debugging NTP requests available for OpenWRT, and perhaps you could enable logging on the busybox-ntp program, but I'm unsure how to enable them.

I have analysed tcpdump data for the interface eth0 through the port 123 for the two devices.
In the device which is in sync with the date and time server and client messages were captured.

But in the non sync device, only client messages are there. Can you please help to interpret the same.

I just checked the port traffic on my OpenWRT router, and I can see regular messages through the port 123, and in TCPDUMP they look like the following:

root@OpenWRT:~# tcpdump -i eth0 'port 123'

20:55:39.133082 IP my-router-address.ZZ.ntp > target.server.ZZ.ntp: NTPv4, Client, length 48
20:55:39.158351 IP target.server.ZZ.ntp > my-router-address.ZZ.ntp: NTPv4, Server, length 48

I did a quick test and added an explicit block rule to the iptables input filter chain. After that I ended up seeing only the client-messages, without a corresponding server reply. Not sure if this is what is happening to you, though.

It was the same happening here too. Time server messages were filtered out. It worked when filter was disabled.Thank you.

The discussion might have continued from here.