linuxntpd

Device is getting time from ntpd but "ntpq -p" command is getting timeout


In our code we are using ntpd to get the time from servers and to set the time. After executing ntpd command, we are running "ntpq -p" to check the server offsets. We are running below commands for ntpd in different process and after finishing that ntpq.

/bin/ntpd -g -c /etc/ntp.conf /bin/ntpq -p

In one lab setup router, we are able to observe that device is getting time properly but when we ran "/bin/ntpq -p", it is blocking for some time and it is returning time out. We are trying to continuously for one hour before giving up in the code. In the lab setup only, it is giving problem. Outside the lab, where the devices are connected to other routers are working fine. When I take a device which is working outside the lab (connected to another router) and if I connect the device to lab router, it is getting timeout.

I thought lab router setup has some problem and that is the reason it is not able to connect to ntp servers. But I was wondering if the device is unable to contact NTP servers, how device is getting proper time. It is very strange that device is getting time from ntp servers but ntpq -p is returning time out. And one more strange behavior is if I reboot the router (device is running), the device is working fine till the device rebooted and if I reboot the device, the same timeout is happening. Can any one please let me know the reasons for this strange behavior.


Solution

  • You have the noquery restriction enabled for whatever host you are trying to nun ntpq -p from.

    From ntp.org docs: https://www.eecis.udel.edu/~mills/ntp/html/accopt.html

    noquery
        Deny ntpq and ntpdc queries. Time service is not affected.