Time Synchronisation
[This modification has been verified to work with Smoothwall GPL 1.0.
Smoothwall Express 2.0 includes this as standard functionality, configurable via the webinterface.]
Because Smoothwall is typically run on an older PC, the clock
may not remain accurate, but tends to drift over time (my Smoothwall
gains nearly a second every hour!).
This page details how to get your Smoothwall GPL installation to
periodically synchronise its clock to an internet time server.
Requirements:
You'll need:
-
A Smoothwall GPL 1.0 installation (obviously...).
-
A way of getting a command-line prompt on your Smoothwall box
(either by logging directly onto your Smoothwall box,
using a SSH client such as
PuTTY
or SSH Secure Shell,
or via the Smoothwall web interface).
Installation Instructions:
Ensure you have SSH enabled on your Smoothwall (it's configured on the
"remote access" page. This is required for logging into your Smoothwall with SSH.
Create a file called timesync, with the following contents
#!/usr/bin/perl
# check if red interface is connected
if (-e "/var/smoothwall/red/active")
{
# sync clock
$ntp = `/usr/bin/ntpdate -u -t 5 time_server_ip`;
$ntp = substr $ntp, (index $ntp, "offset");
if ($ntp eq '')
{
$ntp = "failed";
}
# update hardware clock
`/sbin/clock --systohc`;
# write to smoothwall log
`logger -t smoothwall "clock sync: $ntp"`;
}
Note that this script uses a number of different quotes: ' ` ".
If you use the wrong quotes, the script will fail to run.
Replace time_server_ip with a valid name or ip address
of an NTP time server, so refer to the URL listed below under References.
If you want your clock to be synchronised every hour, save it in
/etc/cron.hourly, or if
you want it to be synchronised once a day, save it in
/etc/cron.daily, and
adjust the permissons on the file using chmod 755 timesync.
Each time this script is run and your red interface is connected, it'll log
the results to your Smoothwall logfile:
Test the script by manually running it from the command prompt:
/etc/cron.hourly/timesync
Note that there will be no visible output at the command prompt if the script is working,
so check your Smoothwall log to check if it successfully updated your clock.
If your script has any errors in it, the errors will be displayed at the
command prompt.
If your internet connection is often saturated when Smoothwall is attempting
to synchronise it's clock, you may find that it is failing (as is often the case
with my dialup connection).
This can normally be overcome by specifying a longer timeout for ntpdate:
$ntp = `/usr/bin/ntpdate -u -t 5 time_server_ip`;
References:
NTP man page
Stratum Two Time Servers
last updated 8 Jan 2005
|