1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

NTP Server

Discussion in 'Tomato Firmware' started by eangulus, Apr 19, 2014.

  1. eangulus

    eangulus Network Guru Member

    Am wanting to run a NTP Server from a RT-AC66U with Tomato.

    Now, before anyone questions why, we have very good reasons, as this is in a community radio station and allot of the software and such require precise timing.

    Secondly I have searched and all that I find are very old threads, mostly that are full of arguments as to why someone would want to do it.

    Regardless I do want to do it, have a need to do and have already attempted to following this thread: http://www.linksysinfo.org/index.ph...mato-for-your-small-office.68515/#post-243893

    But for some reason the above is not working. Not sure if its because its too old and no longer works or what.

    Is there an upto date tutorial or guide for me to try to get a NTP Server running?
     
  2. EOC_Jason

    EOC_Jason Networkin' Nut Member

    Have you tried using ntpd that is built into busybox? http://www.busybox.net/BusyBox.html


    It's not impossible to do, I turned an old router into a NTP server running OpenWRT... It got decent performance but at the same time it wasn't doing any routing, I do not know how the timekeeping would perform under heavy loads.

    Do you have a jffs partition or some place where you can drop a few binaries? I can try building it one day this week and try on my WNR3500L...

    There's not many files for the ntp distro, you just have a few binaries: ntpd, ntpq, ntpdc... Then a config & drift file... that's about it...
     
  3. koitsu

    koitsu Network Guru Member

    The biggest problem with running an NTP server on a residential router (like the MIPS-based ones that TomatoUSB presently runs on) is the fact that there is no good hardware timecounter (clocksource) available on the hardware. Standard x86/x64 PCs offer a multitude of hardware-supported timecounters which are (usually) reliable and allow for a stable frequency counter. The common ones are:

    HPET
    TSC
    ACPI
    Intel i8254 (PIT)

    None of these -- I repeat, NONE -- are available on MIPS-based routers (even higher-end ones like RT-N66U). All you have available is jiffies, which is pure software. Look around in /sys/devices/system/clocksource to see what I mean. And just in case you think I'm kidding...

    Your question then becomes: "okay, so you're saying running ntpd would work but would have problems? What kind of problems?" Without a good/reliable timecounter, your NTP server would end up drifting rapidly and could in turn potentially return completely skewed times back to NTP clients. ntpd has an immense amount of smarts within it to keep this from happening, but it's only as good as the hardware timecounters are -- and if there isn't one... do the math. :)

    You could consider buying an actual stratum 0 time source (these are often GPS-based), but they tend to be in the thousands of dollars range and are usually intended for datacenters. You're better off dedicating a PC on your LAN somewhere (preferably a UNIX or Linux system) to this task. Otherwise, just make sure all your systems, as NTP clients, are syncing from the same set of NTP servers on the Internet and you should be good. Be aware that ntp.org is generally not a good sole source of time data -- they have pools of servers, and the A records that are returned for a lookup change very rapidly, so client A will not necessarily be using the same NTP severs as client B or client C. You really want a diverse (geographically if possible) set of servers, of all different stratum levels (1 to 4 are good), so that intelligent NTP clients (ntpd of which is one!) can say "okay of these 6 servers the best is this, but these others are pretty good while this one is awful". Example of what I'm talking about:

    Code:
    $ ntpq -c peers
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    -clock.isc.org   129.6.15.29      2 u  452 1024  377   12.396    8.069   0.899
    -ntp-1.gw.illino 128.174.38.133   2 u  401 1024  377   93.398   -4.833   1.184
    +otc2.psu.edu    128.118.2.33     2 u  390 1024  177   90.553    3.100   1.051
    *tick.jrc.us     208.90.144.72    2 u  444 1024  377   95.696   -3.132   1.303
    +ntp1.linuxhoste 29.92.24.129     2 u  551 1024  377   27.766    4.332   0.007
    
    This is from a FreeBSD system on my LAN (which also acts as an NTP server). Note the extreme variances.

    My ntp.conf, by the way, which explains the logic (although the comments are now outdated -- clearly clock.isc.org is offering a stratum 2 server now, sigh, I need to go through and revamp this, obviously):

    Code:
    # Originally we used north-america.pool.ntp.org, but the list
    # of servers returned from that pool varied, and would regularly
    # include stratum 1 servers.  Therefore, we prefer a series of
    # stratum 2 servers, with a single stratum 1 as a stable base
    # comparison
    #
    # http://support.ntp.org/bin/view/Servers/StratumOneTimeServers
    # http://support.ntp.org/bin/view/Servers/StratumTwoTimeServers
    #
    # clock.isc.org          strat 1, California
    # ntp-1.cso.uiuc.edu     strat 2, Illinois
    # clock.psu.edu          strat 2, Pennsylvania
    # tick.jrc.us            strat 2, New Jersey
    # 0.us.pool.ntp.org      random
    #
    server clock.isc.org          iburst
    server ntp-1.cso.uiuc.edu     iburst
    server clock.psu.edu          iburst
    server tick.jrc.us            iburst
    server 0.us.pool.ntp.org      iburst
    
    # Security:
    #
    # By default, only allow time queries and block all other requests
    # from unauthenticated clients.
    #
    # See http://support.ntp.org/bin/view/Support/AccessRestrictions
    # for more information.
    #
    restrict default kod nomodify notrap nopeer noquery
    
    # Allow unrestricted access from localhost and relevant network(s)
    restrict 127.0.0.1
    restrict 192.168.1.0 mask 255.255.255.0
    
     
  4. EOC_Jason

    EOC_Jason Networkin' Nut Member

    While I agree there is better hardware out there if you want a nice stratum-1 server, like the OP said, without trying it first you never know what you will get. I'm currently recompiling and enabling BusyBox's built-in NTPD... That seems the simplest route and I doubt the full NTPD distro would yield any better results, and it doesn't sound like you need any advanced features.

    Once I get it compiled and my router updated I will let you know how it performs later today.

    Jiffies is not the end of the world... I have a production PowerEdge server and that is the only available timecounter for it... works fine and NTP has no issues...

    I do have 12 stratum-1 servers here on my home network... A mix of homemade and commercial that I got from eBay...

    7 x Soekris Net4501's w/Motorola Oncore M12+T or UT+ receivers running FreeBSD and NTPns
    2 x Symmetricom Tymserve TS2100 GPS
    2 x TrueTime NTS-100 IRIG
    1 x Endrun Praecis Gntp

    I also have a handful of other GPS modules & GPSDO's
     
  5. ntest7

    ntest7 Network Guru Member

    Victec's tomatoRAF for both RT-N66U and E3000 includes the busybox ntpd server; no rebuilding or installing third-party packages necessary. I would be surprised if the RAF build for the RT-AC66U didn't also include this.

    Enabling it is as easy as adding something like
    /usr/sbin/ntpd -l -p 0.pool.ntp.org -p 1.pool.ntp.org -p 2.pool.ntp.org
    to the WAN Up script page (not the Init script page). Use some servers close to you rather than the examples given above. Oh, and the '-l' is a lower-case L, not a number.

    But note well the limitations of using the router for a time source. It should work "good enough" for casual use of keeping a group of machines within a second or so (or maybe better) of each other, but don't depend on it for millisecond accuracy.
     
  6. EOC_Jason

    EOC_Jason Networkin' Nut Member

    Okay, gave it a try on my WNR3500L.... yeah performance blows with the busybox ntpd...

    It constantly has an offset around 50 ms compared to my S1 servers, also has high jitter... I tried running the service in high priority too but it didn't help any. I'll let it run a little while longer but I don't think the performance will improve any.

    entware has the regular ntpd package, you can give that a try...

    Otherwise if you want a low-power and cheap choice, a Rasberry Pi is very popular, and you can hook a GPS up to it for better timekeeping...
     

Share This Page