What's new

NTP Daemon for ASUSWRT/Merlin

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Modern clocks use crystal resonance to define a second. A spinning HDD creates vibration which exerts upon the motion of the crystal and possibly deviate its motion and deteriorate its accuracy. Seems some programs in your router smart enough to detect and resist... to give you a more stable time. Or perhaps simply coincidence. If I were you I would look into somewhere else, the two events have little correlation.
 
Modern clocks use crystal resonance to define a second. A spinning HDD creates vibration which exerts upon the motion of the crystal and possibly deviate its motion and deteriorate its accuracy. Seems some programs in your router smart enough to detect and resist... to give you a more stable time. Or perhaps simply coincidence. If I were you I would look into somewhere else, the two events have little correlation.

If running NTP, it's pretty close, as it updates often...

ntpq_example.png
 
If running NTP, it's pretty close, as it updates often...

View attachment 7989

Right ntpd continuously adjusts system clock in the background. Very nice. btw yours aren't updated as frequent as mine. Maybe you shall also add a few more hosts with less delay..

ntpq.png


(I blanked out the hosts 'cos SNB is too popular. Don't want to create unnecessary burden on the timeservers suddenly)
 
Right ntpd continuously adjusts system clock in the background. Very nice. btw yours aren't updated as frequent as mine. Maybe you shall also add a few more hosts with less delay..

Fair enough... how's this?

There's another thread on the forums if one wants to get even more accurate via GPS directly...

ntpq_littlebitmore.png
 
What did you mean? I think hosts from ubuntu pool haven't passed initialization stage. lol

GPS or clock source other than through IP network definitely has its advantage. I can understand why guys in data centre want to use GPS and such.

For most users, timeservers through IP network (maybe with a bit additional QoS) are good enough.
 
But having your own GPS-based timeserver is totally geeky! It's on my "someday" list for my home network.
 
Again - do a search on the forums here for GPS and PPS - the code and scripts, along with a good howto recipe are there that can be easily implemented.

Precision on time of day is becoming more important, esp. as the IOT universe is starting to lock things down.
 
What did you mean? I think hosts from ubuntu pool haven't passed initialization stage. lol

yep, right... old configuration file - now fixed - luck of the draw that I picked the one machine that had an old config, lol..

thx for the heads up...

Code:
ntpq> as

ind assid status  conf reach auth condition  last_event cnt
===========================================================
  1  9778  941a   yes   yes  none candidate    sys_peer  1
  2  9779  9324   yes   yes  none   outlier   reachable  2
  3  9780  9324   yes   yes  none   outlier   reachable  2
  4  9781  9324   yes   yes  none   outlier   reachable  2
  5  9782  963a   yes   yes  none  sys.peer    sys_peer  3
  6  9783  933a   yes   yes  none   outlier    sys_peer  3
  7  9784  9324   yes   yes  none   outlier   reachable  2
  8  9785  9324   yes   yes  none   outlier   reachable  2
  9  9786  9424   yes   yes  none candidate   reachable  2
ntpq> pe
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp.newfxlabs.c 69.75.229.42     2 u    6   64    1   18.648    2.903   1.269
-helium.constant 128.59.0.245     2 u    2   64    1   88.376    2.179   1.187
-jtsage.com      200.98.196.212   2 u    2   64    1   62.337   10.454   1.186
-192.187.114.131 152.2.133.53     2 u    2   64    1   70.427   11.489   1.353
*clock.xmission. .XMIS.           1 u    2   64    1   47.260    9.313   1.768
-tomimori.parad. 204.123.2.72     2 u    3   64    1   27.755   -7.374   3.058
-173.255.140.30  139.78.97.128    2 u    5   64    1   29.575   -1.055   1.091
-138.68.46.177 ( 5.100.133.221    2 u    1   64    1   21.640   -2.033   0.987
+alphyn.canonica 132.246.11.231   2 u   14   64    1   83.096    3.611   0.000
ntpq>
 
Again - do a search on the forums here for GPS and PPS - the code and scripts, along with a good howto recipe are there that can be easily implemented.

Precision on time of day is becoming more important, esp. as the IOT universe is starting to lock things down.
Yeah, I've seen the scripts and stuff. Just have to do it when I'll have time to set it up and debug it. Nothing ever quite works right out of the box.
 
Hi,

On my AC87-Router "NTP Daemon Performance Stats" stopped working after update to Merlin .64 release.

It looks like the ntpstats.sh script produces an error:
chief@RT-AC87U:/jffs/bin# ./ntpstats.sh
./ntpstats.sh: line 1: syntax error: unterminated quoted string


Could it be that the updated BusyBox v1.25.1 creates an error?
 
Hi,

On my AC87-Router "NTP Daemon Performance Stats" stopped working after update to Merlin .64 release.

It looks like the ntpstats.sh script produces an error:
chief@RT-AC87U:/jffs/bin# ./ntpstats.sh
./ntpstats.sh: line 1: syntax error: unterminated quoted string


Could it be that the updated BusyBox v1.25.1 creates an error?

For Entware users, worth replacing first line with "#!/opt/bin/bash" to use the standard Bash shell. To install, type "opkg install bash"

My RT-AC56U is using the BusyBox from 380.60 alpha 1. So I won't be able to debug this issue. Might need you or others' help to resolve this one...
 
For Entware users, worth replacing first line with "#!/opt/bin/bash" to use the standard Bash shell. To install, type "opkg install bash"
Yes, bash was helpful, but still not the full solution:
chief@RT-AC87U:/jffs/bin# ./ntpstats.sh
./ntpstats.sh: command substitution: line 40: unexpected EOF while looking for matching `"'
./ntpstats.sh: command substitution: line 41: syntax error: unexpected end of file
618x248
618x248
618x248
618x248
618x248

The line 40 contains a command with only one opening double quote (") - but missing the closing one:
DATE=`date "+%a %b %e %H:%M %Y"`
By adding the closing quote after %Y it works without error - also with /bin/sh shell.

Maybe you can update the installation packages with the fixed script...:rolleyes:
 
Last edited:
@joegreat Great finding!

Somehow the end quotation mark exists in my local copy but not the package archive :confused:. I'll find time to re-pack the newer binaries with this fix as well as newer look like below into a new package.

stats-week-ntp-offset.png

stats-week-ntp-sysjit.png

stats-week-ntp-freq.png
 
Very cool and fun project!

I installed it on my RT-AC87U with Merlinwrt v380.65, and can confirm it's working.

I did have to adjust line 40 in ntpstats.sh as per this post: https://www.snbforums.com/threads/ntp-daemon-for-asuswrt-merlin.28041/page-7#post-304949

And updating the ntpd_stats-BIN.zip took some bit of guess-work and searching to find the actual location where to copy the files (/jffs/bin/).

I didn't need to touch /www/Tools_NtpdStats.asp as per post #22 to get the webUI working.

I'm trying out an idea to run ntpd as a server and sync all connected units to it. But I can't connect to port 123 on the router. Is there any restrict code in /jffs/etc/ntp.conf that blocks this? Or a required option needed to enable the server on port 123? I know the ntpd included in busybox needs -l, but that option doesn't seem to exist in this package.

Another question I have is if's preferable to only use 3 time servers or if there's any benefit to add more?
 
I'm trying out an idea to run ntpd as a server and sync all connected units to it. But I can't connect to port 123 on the router.
I add in the end of post-mount script "ntpd -l" and Windows 10 and DLink DIR-300 start to synchronize time if i use my lan ip address (in my case 192.168.0.254) of ac87u. Try to use ddns, but can't open 123 port, don't know why iptables in firewall-start script not work. And here is my ntp.conf
 

Attachments

  • Снимок экрана 2017-03-02 в 2.14.02.png
    Снимок экрана 2017-03-02 в 2.14.02.png
    68.4 KB · Views: 425
I add in the end of post-mount script "ntpd -l" and Windows 10 and DLink DIR-300 start to synchronize time if i use my lan ip address (in my case 192.168.0.254) of ac87u. Try to use ddns, but can't open 123 port, don't know why iptables in firewall-start script not work. And here is my ntp.conf
There are two different "ntpd" programs. Which one?

Type the command to see which "ntpd".
which ntpd

There's a ntpd in Busybox with different parameters. And there's the real ntpd in Entware-ng.

/usr/sbin/ntpd --help
Code:
BusyBox v1.25.1 (2017-03-01 16:21:56 EST) multi-call binary.

Usage: ntpd [-dnqNwtl -I IFACE] [-S PROG] [-p PEER]...

NTP client/server

        -d      Verbose
        -n      Do not daemonize
        -q      Quit after clock is set
        -N      Run at high priority
        -w      Do not set time (only query peers), implies -n
        -t      Trust network and server, no RFC-4330 cross-checks
        -S PROG Run PROG after stepping time, stratum change, and every 11 mins
        -p PEER Obtain time from PEER (may be repeated)
                If -p is not given, 'server HOST' lines
                from /etc/ntp.conf are used
        -l      Also run as server on port 123
        -I IFACE Bind server to IFACE, implies -l


/opt/sbin/ntpd --help
Code:
ntpd - NTP daemon program - Ver. 4.2.8p9
Usage:  ntpd [ -<flag> [<val>] | --<name>[{=| }<val>] ]... \
                [ <server1> ... <serverN> ]
  Flg Arg Option-Name    Description
   -4 no  ipv4           Force IPv4 DNS name resolution
                                - prohibits the option 'ipv6'
   -6 no  ipv6           Force IPv6 DNS name resolution
                                - prohibits the option 'ipv4'
   -a no  authreq        Require crypto authentication
                                - prohibits the option 'authnoreq'
   -A no  authnoreq      Do not require crypto authentication
                                - prohibits the option 'authreq'
   -b no  bcastsync      Allow us to sync to broadcast servers
   -c Str configfile     configuration file name
   -d no  debug-level    Increase debug verbosity level
                                - may appear multiple times
   -D Num set-debug-level Set the debug verbosity level
                                - may appear multiple times
   -f Str driftfile      frequency drift file name
   -g no  panicgate      Allow the first adjustment to be Big
                                - may appear multiple times
   -G no  force-step-once Step any initial offset correction.
   -i --- jaildir        built without --enable-clockctl or --enable-linuxcaps or --enable-solarisprivs
   -I Str interface      Listen on an interface name or address
                                - may appear multiple times
   -k Str keyfile        path to symmetric keys
   -l Str logfile        path to the log file
   -L no  novirtualips   Do not listen to virtual interfaces
   -n no  nofork         Do not fork
                                - prohibits the option 'wait-sync'
   -N no  nice           Run at high priority
   -p Str pidfile        path to the PID file
   -P Num priority       Process priority
   -q no  quit           Set the time and quit
                                - prohibits these options:
                                saveconfigquit
                                wait-sync
   -r Str propagationdelay Broadcast/propagation delay
      Str saveconfigquit Save parsed configuration and quit
                                - prohibits these options:
                                quit
                                wait-sync
   -s Str statsdir       Statistics file location
   -t Str trustedkey     Trusted key number
                                - may appear multiple times
   -u --- user           built without --enable-clockctl or --enable-linuxcaps or --enable-solarisprivs
   -U Num updateinterval interval in seconds between scans for new or dropped interfaces
      Str var            make ARG an ntp variable (RW)
                                - may appear multiple times
      Str dvar           make ARG an ntp variable (RW|DEF)
                                - may appear multiple times
   -w Num wait-sync      Seconds to wait for first clock sync
                                - prohibits these options:
                                nofork
                                quit
                                saveconfigquit
   -x no  slew           Slew up to 600 seconds
      opt version        output version information and exit
   -? no  help           display extended usage information and exit
   -! no  more-help      extended usage information passed thru pager

Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.


The following option preset mechanisms are supported:
 - examining environment variables named NTPD_*

Please send bug reports to:  <http://bugs.ntp.org, bugs@ntp.org>


AND, if you're trying to use Windows as an NTP server, you must first turn on the NTP server in Windows services and then allow inbound UDP port 123 on the Windows firewall.
https://www.snbforums.com/threads/yet-another-way-to-sync-your-routers-clock.37439/
 
There are two different "ntpd" programs. Which one?

Type the command to see which "ntpd".
which ntpd

There's a ntpd in Busybox with different parameters. And there's the real ntpd in Entware-ng.

/usr/sbin/ntpd --help
Code:
BusyBox v1.25.1 (2017-03-01 16:21:56 EST) multi-call binary.

Usage: ntpd [-dnqNwtl -I IFACE] [-S PROG] [-p PEER]...

NTP client/server

        -d      Verbose
        -n      Do not daemonize
        -q      Quit after clock is set
        -N      Run at high priority
        -w      Do not set time (only query peers), implies -n
        -t      Trust network and server, no RFC-4330 cross-checks
        -S PROG Run PROG after stepping time, stratum change, and every 11 mins
        -p PEER Obtain time from PEER (may be repeated)
                If -p is not given, 'server HOST' lines
                from /etc/ntp.conf are used
        -l      Also run as server on port 123
        -I IFACE Bind server to IFACE, implies -l


/opt/sbin/ntpd --help
Code:
ntpd - NTP daemon program - Ver. 4.2.8p9
Usage:  ntpd [ -<flag> [<val>] | --<name>[{=| }<val>] ]... \
                [ <server1> ... <serverN> ]
  Flg Arg Option-Name    Description
   -4 no  ipv4           Force IPv4 DNS name resolution
                                - prohibits the option 'ipv6'
   -6 no  ipv6           Force IPv6 DNS name resolution
                                - prohibits the option 'ipv4'
   -a no  authreq        Require crypto authentication
                                - prohibits the option 'authnoreq'
   -A no  authnoreq      Do not require crypto authentication
                                - prohibits the option 'authreq'
   -b no  bcastsync      Allow us to sync to broadcast servers
   -c Str configfile     configuration file name
   -d no  debug-level    Increase debug verbosity level
                                - may appear multiple times
   -D Num set-debug-level Set the debug verbosity level
                                - may appear multiple times
   -f Str driftfile      frequency drift file name
   -g no  panicgate      Allow the first adjustment to be Big
                                - may appear multiple times
   -G no  force-step-once Step any initial offset correction.
   -i --- jaildir        built without --enable-clockctl or --enable-linuxcaps or --enable-solarisprivs
   -I Str interface      Listen on an interface name or address
                                - may appear multiple times
   -k Str keyfile        path to symmetric keys
   -l Str logfile        path to the log file
   -L no  novirtualips   Do not listen to virtual interfaces
   -n no  nofork         Do not fork
                                - prohibits the option 'wait-sync'
   -N no  nice           Run at high priority
   -p Str pidfile        path to the PID file
   -P Num priority       Process priority
   -q no  quit           Set the time and quit
                                - prohibits these options:
                                saveconfigquit
                                wait-sync
   -r Str propagationdelay Broadcast/propagation delay
      Str saveconfigquit Save parsed configuration and quit
                                - prohibits these options:
                                quit
                                wait-sync
   -s Str statsdir       Statistics file location
   -t Str trustedkey     Trusted key number
                                - may appear multiple times
   -u --- user           built without --enable-clockctl or --enable-linuxcaps or --enable-solarisprivs
   -U Num updateinterval interval in seconds between scans for new or dropped interfaces
      Str var            make ARG an ntp variable (RW)
                                - may appear multiple times
      Str dvar           make ARG an ntp variable (RW|DEF)
                                - may appear multiple times
   -w Num wait-sync      Seconds to wait for first clock sync
                                - prohibits these options:
                                nofork
                                quit
                                saveconfigquit
   -x no  slew           Slew up to 600 seconds
      opt version        output version information and exit
   -? no  help           display extended usage information and exit
   -! no  more-help      extended usage information passed thru pager

Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.


The following option preset mechanisms are supported:
 - examining environment variables named NTPD_*

Please send bug reports to:  <http://bugs.ntp.org, bugs@ntp.org>


AND, if you're trying to use Windows as an NTP server, you must first turn on the NTP server in Windows services and then allow inbound UDP port 123 on the Windows firewall.
https://www.snbforums.com/threads/yet-another-way-to-sync-your-routers-clock.37439/
I reset settings on router, but I remember settings was like on first one. I never try this so think it's from the topic, my bad)
 
@kvic,

Did this ever get fixed ? From the instructions on github.

admin@RT-AC88U-0000:/tmp/home/root# /opt/etc/init.d/S77ntpd-custom start
Starting ntpd... done.
admin@RT-AC88U-0000:/tmp/home/root# /jffs/bin/ntpstats.sh
/jffs/bin/ntpstats.sh: line 1: syntax error: unterminated quoted string
admin@RT-AC88U-0000:/jffs/bin# opkg install bash
Installing bash (4.3.42-1a) to root...
Downloading http://pkg.entware.net/binaries/armv7/bash_4.3.42-1a_armv7soft.ipk
Installing libncurses (6.0-1c) to root...
Downloading http://pkg.entware.net/binaries/armv7/libncurses_6.0-1c_armv7soft.ip k
Installing libncursesw (6.0-1c) to root...
Downloading http://pkg.entware.net/binaries/armv7/libncursesw_6.0-1c_armv7soft.i pk
Configuring libncursesw.
Configuring libncurses.
Configuring bash.
admin@RT-AC88U-0000:/jffs/bin# /jffs/bin/ntpstats.sh
/jffs/bin/ntpstats.sh: command substitution: line 40: unexpected EOF while looki ng for matching `"'
/jffs/bin/ntpstats.sh: command substitution: line 41: syntax error: unexpected e nd of file
618x248
618x248
618x248
618x248
618x248​
 
Last edited:
@kvic ,

Did this ever get fixed ? From the instructions on github.

admin@RT-AC88U-0000:/tmp/home/root# /opt/etc/init.d/S77ntpd-custom start
Starting ntpd... done.
admin@RT-AC88U-0000:/tmp/home/root# /jffs/bin/ntpstats.sh
/jffs/bin/ntpstats.sh: line 1: syntax error: unterminated quoted string
admin@RT-AC88U-0000:/jffs/bin# opkg install bash
Installing bash (4.3.42-1a) to root...
Downloading http://pkg.entware.net/binaries/armv7/bash_4.3.42-1a_armv7soft.ipk
Installing libncurses (6.0-1c) to root...
Downloading http://pkg.entware.net/binaries/armv7/libncurses_6.0-1c_armv7soft.ip k
Installing libncursesw (6.0-1c) to root...
Downloading http://pkg.entware.net/binaries/armv7/libncursesw_6.0-1c_armv7soft.i pk
Configuring libncursesw.
Configuring libncurses.
Configuring bash.
admin@RT-AC88U-0000:/jffs/bin# /jffs/bin/ntpstats.sh
/jffs/bin/ntpstats.sh: command substitution: line 40: unexpected EOF while looki ng for matching `"'
/jffs/bin/ntpstats.sh: command substitution: line 41: syntax error: unexpected e nd of file
618x248
618x248
618x248
618x248
618x248​
https://www.snbforums.com/threads/ntp-daemon-for-asuswrt-merlin.28041/page-7#post-304949
 
@kvic,

The script on github still hasn't been fixed.

Adding the extra quote fixed it.

Also, in the Uninstall section, the following command needs a "/" before jffs
  • rm jffs/etc/ntp.conf
 
Last edited:

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top