fhg
Volume 8, Number 24 -- June 25, 2008

Keeping Time with NTP

Published: June 25, 2008

by 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 
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers"
 /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:

HKLM\SYSTEM\CurrentControlSet\Services\Dhcp\Parameters\Options)

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


Sponsored By
HELP/SYSTEMS

SEQUEL™ is the leading business intelligence solution for the IBM® System i™.

                      · Executive Dashboards with Gauges for Critical Business Metrics
                      · Graphical Query and Reporting
                      · Drill-Down Data Analysis
                      · Multi-Platform Database Access
                      · Powerful Scripting with CL-like Programming
                      · Secure Web Access

SEQUEL meets all your System i data access and analysis requirements.

Learn more now.


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

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


 
The Four Hundred
The AS/400's Grandfather Talks Past, Present, and Future

IBM Offers Modest Discounts on i 525 and M25 Entry Boxes

Consistent Change Offers Adjunct Services for SoftLanding Tools

As I See It: Flights of Fancy

Agilysys Hires JPMorgan for Possible Sale

The Linux Beacon
The Top 500 Super Ranking Now Counts Watts as Well as Flops

Red Hat Launches oVirt Embedded KVM Hypervisor Project

openSUSE 11.0 Out the Door and On the Street

As I See It: Flights of Fancy

HP Donates the Guts of Tru64 Unix's File System to Linux

Four Hundred Stuff
DRV Cleans Up i OS Spool Files with ReportFlex

Agilysys Introduces New Software for Hotels

Subversion SCM Tool Becomes More Robust with Version 1.5

Cast Iron Simplifies NetSuite Integration with Appliance

Virtual Servers Keep On A Rollin', Thanks to uptime software

Big Iron
HP Launches NonStop Blade to Chase Mainframes and Unix Apps

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
June 21, 2008: Volume 10, Number 25

June 14, 2008: Volume 10, Number 24

June 7, 2008: Volume 10, Number 23

May 31, 2008: Volume 10, Number 22

May 24, 2008: Volume 10, Number 21

May 17, 2008: Volume 10, Number 20

The Windows Observer
Windows Server 2008 Greener Than Past Releases, Microsoft Says

Unisys Pushes Virtual Windows Desktops and Exchange Servers

MicroHoo Now All But Dead

As I See It: The Programmer as Artist

AMD Offers Clock Cranks on Barcelona Opterons

The Unix Guardian
Fujitsu-Siemens Finally Does Solaris on Primergy

The Top 500 Super Ranking Now Counts Watts as Well as Flops

Sysload Delivers Fine-Grain Monitoring for Virtual Servers

Mad Dog 21/21: iPhone Home

The World Can't Get Enough Disk Array Capacity

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

Help/Systems
WorksRight Software
Guild Companies


Printer Friendly Version


TABLE OF CONTENTS
Keeping Time with NTP

What Happened to My Key?

Stopping Your System i from Starting Up

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
IFF ACTIVE Equivalent in CL

Printer Problem

Capture Sort File and Copy to Database File

SNMP Traps on i5OS

Java Messages

Copying recs from a subfile to a file and keeping highlights





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement