Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

NTP Daemon for ASUSWRT/Merlin

Discussion in 'Asuswrt-Merlin' started by kvic, Nov 6, 2015.

  1. kvic

    kvic Very Senior Member

    Joined:
    Aug 11, 2014
    Messages:
    1,374
    Location:
    Hong Kong
    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.
     
  2. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    10,796
    Location:
    San Diego, CA
    If running NTP, it's pretty close, as it updates often...

    ntpq_example.png
     
  3. kvic

    kvic Very Senior Member

    Joined:
    Aug 11, 2014
    Messages:
    1,374
    Location:
    Hong Kong
    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)
     
  4. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    10,796
    Location:
    San Diego, CA
    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
     
  5. kvic

    kvic Very Senior Member

    Joined:
    Aug 11, 2014
    Messages:
    1,374
    Location:
    Hong Kong
    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.
     
  6. cmkelley

    cmkelley Occasional Visitor

    Joined:
    Aug 11, 2015
    Messages:
    18
    But having your own GPS-based timeserver is totally geeky! It's on my "someday" list for my home network.
     
  7. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    10,796
    Location:
    San Diego, CA
    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.
     
  8. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    10,796
    Location:
    San Diego, CA
    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> 
    
     
  9. cmkelley

    cmkelley Occasional Visitor

    Joined:
    Aug 11, 2015
    Messages:
    18
    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.
     
  10. joegreat

    joegreat Very Senior Member

    Joined:
    Jan 9, 2013
    Messages:
    1,360
    Location:
    Vienna, Austria
    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:
    [email protected]:/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?
     
  11. kvic

    kvic Very Senior Member

    Joined:
    Aug 11, 2014
    Messages:
    1,374
    Location:
    Hong Kong
    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...
     
    joegreat likes this.
  12. joegreat

    joegreat Very Senior Member

    Joined:
    Jan 9, 2013
    Messages:
    1,360
    Location:
    Vienna, Austria
    Yes, bash was helpful, but still not the full solution:
    [email protected]:/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: Jan 29, 2017
    kvic likes this.
  13. kvic

    kvic Very Senior Member

    Joined:
    Aug 11, 2014
    Messages:
    1,374
    Location:
    Hong Kong
    @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
     
    JGrana and joegreat like this.
  14. Beherit

    Beherit Regular Contributor

    Joined:
    Sep 19, 2016
    Messages:
    60
    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?
     
  15. Helghast59

    Helghast59 Occasional Visitor

    Joined:
    Nov 2, 2014
    Messages:
    11
    Location:
    St.-Petersburg, Russia
    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
     

    Attached Files:

  16. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    204
    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, [email protected]>
    

    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/
     
  17. Helghast59

    Helghast59 Occasional Visitor

    Joined:
    Nov 2, 2014
    Messages:
    11
    Location:
    St.-Petersburg, Russia
    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)
     
  18. Denna

    Denna Senior Member

    Joined:
    Aug 4, 2016
    Messages:
    220
    @kvic,

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

    [email protected]:/tmp/home/root# /opt/etc/init.d/S77ntpd-custom start
    Starting ntpd... done.
    [email protected]:/tmp/home/root# /jffs/bin/ntpstats.sh
    /jffs/bin/ntpstats.sh: line 1: syntax error: unterminated quoted string
    [email protected]:/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.
    [email protected]:/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: Mar 6, 2017
  19. tomsk

    tomsk Senior Member

    Joined:
    Sep 3, 2016
    Messages:
    483
    https://www.snbforums.com/threads/ntp-daemon-for-asuswrt-merlin.28041/page-7#post-304949
     
    joegreat likes this.
  20. Denna

    Denna Senior Member

    Joined:
    Aug 4, 2016
    Messages:
    220
    @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: Mar 8, 2017

Share This Page