• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Keeping Time with NTP

    June 25, 2008 Tom Van Looy

    The Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks. NTP uses UDP port 123 as its transport layer. It is designed particularly to resist the effects of variable latency (jitter buffer).

    The Network Time Protocol (NTP) version 3 is described in RFC1305 and the Simple Network Time Protocol (SNTP) version 4 is described in RFC2030. NTP is not related to the much simpler daytime RFC867 and time RFC868 protocols.

    NTP client/server on i5/OS

    You can validate the current time with the command DSPSYSVAL QDATETIME. The NTP server on the system will redistribute the time shown there. Setting up an NTP client and server is simple; use the Change SNTP Attributes (CHGNTPA) command. i5/OS implements the SNTP protocol.

    The “remote system” parameter for the NTP client must be set to one or more servers, or to a server pool. I usually set this parameter to pool.ntp.org on my local NTP server. Local clients have the hostname of my local NTP server configured there. If you want to run the client, set Client autostart to *YES. If you want to run the server as well, set Server autostart to *YES. There is a nice parameter, Synchronization required, that restricts the server to serve time when the client is out of sync. Last, you can set the client and server logging level with the Client activity log and Server activity log parameters. Activate the configured values with an IPL or the following command:

    STRTCPSVR SERVER(*NTP) NTPSRV(*CFGFILE)
    

    To stop the NTP client and server, use this command:

    ENDTCPSVR SERVER(*NTP)
    

    Depending on the configured logging level, your logs will be more or less verbose. Use the following command to find these logs on the IFS:

    WRKLNK '/QIBM/USERDATA/OS400/TCPIP/NTP'
    

    Here’s an example of the client with ACTLOG(*POLL):

    SNTP Client Activity Log QTOTNTP/QNTP/002415  02/05/08 22:25:54.306
    TCP9136 SNTP Client started.
    TCP9146 Using time server pool.ntp.org.
    TCP9146 Using time server pool.ntp.org.
    TCP9162 02/05/08 22:25:55.174 Time remaining for adjustment is 
    0.000 seconds.
    TCP9116 02/05/08 22:25:55.174 NTP server UTC time is 02/05/08 
    20:25:55.213.
    TCP9117 02/05/08 22:25:55.174 Client clock UTC time is 02/05/08 
    20:25:55.174.
    TCP9120 02/05/08 22:25:55.174 Client clock adjusted = 1  
    (0 = not adjusted, 1 = adjusted)
    

    An example of the server with SRVACTLOG(*ALL):

    SNTP Server Activity Log QTOTNTP/QNTP/020258  03/05/08 12:44:53.906
    TCP9159 SNTP Server started.
    TCP9161 03/05/08 15:35:52.048 Client 10.1.2.30, Unsynchronized 
    status returned.
    TCP9162 03/05/08 15:35:52.048 Time remaining for adjustment is 
    0.000 seconds.
    TCP9161 03/05/08 15:37:02.973 Client 10.10.1.35, Unsynchronized 
    status returned.
    TCP9162 03/05/08 15:37:02.973 Time remaining for adjustment is 
    0.000 seconds.
    

    As you would expect, you can view the NTP jobs from a CL command line:

    WRKUSRJOB USER(QNTP)
    

    NTP client on the HMC

    The Hardware Management Console (HMC) is actually just a stripped down Linux box, and can be configured on a restricted shell. You can access the shell locally from the window manager (fluxbox) menu, or remotely with SSH (if you set it up). The current time can be printed with the DATE command.

    NTP is configured in the files /etc/sysconfig/xntp and /etc/ntp.conf. Luckily, there are some commands available that form an interface over these configuration files, namely chhmc and lshmc. The system has manual (“man”) pages available for these commands. Use them if you want to know the exact scope of a command used below. The NTP client used on the HMC is the implementation of ntp.org, packaged by S.u.S.E. (now Novell). The x in xntp was intended as experimental, but after a decade of code it was a bit inappropriate so they dropped it for NTPv4. So in practice, xntp refers to an implementation of version three.

    To show if the client is running, use the command lshmc -r -F xntp. The system will respond with enable or disable.

    The HMC is protected by a firewall. If you want to use the NTP server on your network, you have to open up the port used by NTP on the correct network interface. The HMC usually has three interfaces (eth0, eth1 and eth2). From within WebSM, you can look up which interface will be used by NTP (the one that’s connected to the local network). Try to ping your local NTP server over this interface to be sure you are configuring the correct one. For example if the interface is eth2 and the IP address of the NTP server is 10.10.1.34: ping -I eth2 10.10.1.34.

    Now you can configure the NTP client with the chhmc command. chhmc -c xntp -s add -a 10.10.1.34 -i eth2. The –s flag also accepts remove instead of add to remove a server. There is also a -h flag that accepts a hostname instead of an IP address. You only have to specify -h or -a, not both of them. It’s possible to validate configuration changes directly in the already mentioned configuration files.

    The last step is to enable the NTP client. This can be done with the command chhmc -c xntp -s enable. The server logs will show the client startup, an example of grep ntp /var/log/messages:

    May 02 09:37:21 hmc1 ntpdate[15903]: adjust time server 10.10.1.34 
    offset 0.071392 sec
    May 02 09:37:21 hmc1 ntpd[15912]: ntpd 4.2.0a@1.1213-r Fri May 02 
    13:44:28 UTC 2006 (1)
    May 02 09:37:21 hmc1 ntpd[15912]: precision = 3.000 usec
    May 02 09:37:21 hmc1 ntpd[15912]: Listening on interface wildcard, 
    0.0.0.0#123
    May 02 09:37:21 hmc1 ntpd[15912]: Listening on interface lo, 
    127.0.0.1#123
    May 02 09:37:21 hmc1 ntpd[15912]: Listening on interface eth0, 
    9.6.24.1#123
    May 02 09:37:21 hmc1 ntpd[15912]: Listening on interface eth2, 
    10.10.1.33#123
    May 02 09:37:21 hmc1 ntpd[15912]: Listening on interface sl0, 
    10.253.0.1#123
    May 02 09:37:21 hmc1 ntpd[15912]: kernel time sync status 0040
    May 02 09:37:21 hmc1 ntpd[15912]: frequency initialized 2.643 PPM 
    from /var/lib/ntp/drift/ntp.drift
    

    As far as I know, it is impossible to run an NTP server on the HMC.

    NTP Client on Windows

    Windows also has an implementation of the SNTP protocol. It is possible to configure the client from the Windows GUI using the date and time properties. I was told it’s easy to configure the NTP server for all clients on your network using active directory. As I don’t use active directory, I added a command to my Samba login script, namely net time /SETSNTP:ntp1.example.com,0x1.

    You can also push the server into the registry with the command:

    reg add 
    "HKLMSOFTWAREMicrosoftWindowsCurrentVersionDateTimeServers"
     /v 0 /t REG_SZ /d ntp1.example.com /f
    

    To verify that you are using the correct time server, use the command net time /querysntp. To manually resync with the server, use the command w32tm /resync. There are a handful of other w32tm commands, but I’ve never needed them.

    The clients on my network all make use of the dynamic host configuration protocol (DHCP). DHCP is defined in RFC2131 and can make use of DHCP options, defined in RFC1533. There is an option 42, which sends network time protocol servers . Because DHCP supports sending NTP servers, I tried to configure this on my Windows client. The client does not request option 42 by default. On NT4 you could add this option to the registry:

    HKLMSYSTEMCurrentControlSetServicesDhcpParametersOptions)
    

    But, on XP this doesn’t seem to work anymore.

    NTP Client on *nix

    Manually setting up a NTP server/client on Linux/*BSD is a matter of configuring /etc/ntpd.conf. Some distributions, such as OpenSUSE, will make this even easier by providing a graphical frontend on the configuration files (YaST).

    But, I also tried to use the DHCP option with the ISC DHCP client, which many Linux distributions use. All you need to do is add a request for ntp-servers to the /etc/dhclient.conf and extend the dhclient-script with the function below. Call it somewhere in BOUND|RENEW|REBIND|REBOOT. I only do so on $reason REBOOT:

        add_new_ntp() {
          if [ -n "$new_ntp_servers" ]; then
            perl -i -ne 'print unless /^server/' /etc/ntpd.conf
            for address in $new_ntp_servers; do
              echo "server" $address >> /etc/ntpd.conf
            done
            pkill -KILL ntpd && ntpd
          fi
        }
    

    In this case I used OpenBSD and its NTP client, so configuring ntpd.conf and restarting ntpd can be a bit different on a Linux distribution using the client of ntp.org. Here’s a piece of tcpdump output showing the REQ/ACK of option 42(look for NTP):

    15:51:15.261777 192.168.1.79.bootpc > 255.255.255.255.bootps:
    xid:0xdc015522 vend-rfc1048 HN:"glenda" RQ:192.168.1.79 
    DHCP:REQUEST PR:SM+BR+DG+DN+NS+HN+NTP [tos 0x10]
    
    15:51:15.501148 192.168.1.1.bootps > 192.168.1.79.bootpc:
    xid:0xdc015522 Y:192.168.1.79 S:192.168.1.1 vend-rfc1048 DHCP:ACK
    SID:192.168.1.1 LT:43200 SM:255.255.255.0 BR:192.168.1.255
    DG:192.168.1.1 DN:"example.com" NS:ns1.example.com 
    NTP:192.168.1.3 [tos 0x10]
    

    Tom Van Looy started out his IT career as an ILE/RPG developer in 2005 and moved over to the position of i5/OS system engineer in 2007. He is currently employed by Lisis nv in Belgium. Although a Unix enthusiast, he also has great affinity with GNU/Linux and *BSD. Tom can be reached by email at tom@ctors.net.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Computer Keyes

    Fax Directly from your IBM i

    KeyesFax is a full function automated IBM i fax system. Spooled files are burst by fax number and auto transmitted with overlays.  It combines both a send and receive facsimile processing system with a complete image package.

    The fax software will edit, send, receive, display, print, and track fax documents or images using any standard IBM i without additional expensive hardware, software or subscriptions.

    Computer Keyes has been developing Software Solutions since 1978!

    www.computerkeyes.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    OCEAN:  Technical conference, June 30, 2008, Irvine, CA
    COMMON:  Join us at the Focus 2008 workshop conference, October 5 - 8, in San Francisco, California
    Vision Solutions:  System i Management Tips Blog - Free i5/OS Tips Each Week!

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    Getting Started with PHP for i5/OS: List Price, $59.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket Developers' Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    iSeries Express Web Implementer's Guide: List Price, $59.00
    Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    WebFacing Application Design and Development Guide: List Price, $55.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    The All-Everything Machine: List Price, $29.95
    Chip Wars: List Price, $29.95

    LTO Tape Drive Sales Increased 15 Percent in 2007 The Power Systems 550 M50 Versus Its Predecessors

    Leave a Reply Cancel reply

Volume 8, Number 24 -- June 25, 2008
THIS ISSUE SPONSORED BY:

Help/Systems
WorksRight Software
Guild Companies

Table of Contents

  • Keeping Time with NTP
  • What Happened to My Key?
  • Stopping Your System i from Starting Up

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18
  • Will The Turbulent Economy Downdraft IBM Systems Or Lift It?
  • How IBM Improved The Database With IBM i 7.6
  • Rocket Celebrates 35th Anniversary As Private Equity Owner Ponders Sale
  • 50 Acres And A Humanoid Robot With An AI Avatar
  • IBM i PTF Guide, Volume 27, Number 17

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle