computer and network time exercise
Timezone control
Back up the system's notion of the rules for local time setting:
cp /etc/localtime /etc/localtime.org
Now make the system adopt the same rules for local time setting that people use in New York:
cp /usr/share/zoneinfo/America/New_York /etc/localtime
Set the time to a part of the year in which daylight savings time is not in effect in New York, then to a time when it is. In each case, ask the system what time it thinks it is locally (New York) and UTC, and note how many hours' difference.
Make the system think it's February.
date
02020200 sets 2 o'clock February 2
date
date --utc
How many hours' difference are there between the time New York uses in Feburary and UTC? How many hours' difference are there between the times reported by the last 2 commands above, when system time is in February?
Make the system think it's August.
date
08080800 sets 8 o'clock August 8
date
date --utc
How many hours' difference are there between the time New York uses in August and UTC? How many hours' difference are there between the times reported by the last 2 commands above, when system time is in August?
How did the system know correctly what goes on in New York? New York's rules for setting clocks are embodied in /usr/share/zoneinfo/America/New_York. The system uses the rules in /etc/localtime. If /etc/localtime is a copy (or link to) /usr/share/zoneinfo/America/New_York then the system adopts New York's rules and time behavior:. The rules used by many other cities and regions are also supplied in /usr/share/zoneinfo/. Make the system adopt the one you want by copying it to /etc/localtime.
Restore the system's original notion of the rules:
cp /etc/localtime.org /etc/localtime
You can view the time in another zone without converting your system to that zone, with the zdump command. It takes as argument a timezone specification in the form of the location of that zone's file relative to /usr/share/zoneinfo/. Try
zdump America/New_York
zdump Japan
zdump Iran
Some places have unconventional time rules. For example, Iran is "on the half hour" relative to most other places. The linux timezone file for it knows about such peculiarities.
Configure ntpd
The most important configuration responsibility is to supply ntpd with the identity of a time server. Visit www.ntp.org's public time server lists and choose a geographically close, stratum 2 server that's listed with access policy "Open Access" and notify policy "No". One such is ntp.ucsd.edu, another is nist1-la.ustiming.org. However you please pick a different one. Then save the original configuration file
cp /etc/ntp.conf /etc/ntp.conf.org
and create a new one using your editor, with the following barebones content:
server <server you chose>
restrict <server you chose> mask 255.255.255.255 nomodify
notrap noquery
restrict 127.0.0.1
Do an initial synchronization
Without checking the system time, find out from your wristwatch or your fellow students the approximate time. Try to determine a time that's rough, about 5 or 10 minutes fast or slow. We want the time to be a little off so that ntp will have some correcting to do! Let's say its May 23, more or less 9:45pm (2145h):
date 05232145
Set up 3 open terminal windows on your GUI desktop. I'll call them the ntp, sniffer, and log windows. In the sniffer window, execute:
tcpdump -nti eth0 port 123
Move over to the log window and do:
tail -f /var/log/messages
Both windows, in different ways, are now poised to dynamcially reveal the activities involved in performing a network time protocol interaction between your machine and the server you've configured. Set the 3 windows apart from each other so they are simultaneously visible with as little overlap as possible. In the ntp window execute:
ntpd -q
How far off was your time guess?
Now that you know the accurate time repeat the process but first, as the initial time, set the system clock way off by several hours. If it's 9:45 in the evening, set it to 11am or something like that:
date 05231100
Redo the test. What didn't happen? Why not? How are you going to restore accurate time to the system clock now that you've messed it up and ntp refuses to help? Restore it please before you continue.
Configure as a server
Restore the original configuration file:
cp /etc/ntp.conf.org /etc/ntp.conf
Note that the servers it designates for its use have names like 1.pool.ntp.org, suggesting not a single specific server but a pool of them collectively. This is a load distribution feature. Note the section for opening up your ntpd to others who may wish to update their time from you:
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
To activate this, uncomment the "restrict" line and edit the network designation to that of the network you want to serve (e.g., "164.67.79.0 mask 255.255.255.0"). Working with another student, have him designate you as his server, by your IP address in a "server" statement within his config file. See if you can update his time. Start your server:
service ntpd restart
Have him stop his if it's running and then issue "ntpd -q".
Reverse roles, adjusting your respective configuration files as needed.