PyTime

Click here to download

NTP is a sophisticated protocol for synchronizing computer clocks. Unfortunately, many corporate networks filter UDP port 123 on their external firewall. I administer a small set of Linux machines used for R&D. The time on these computers needs to be synchronized. Otherwise, the time on my file servers and desktop machines will drift and makefiles and backups won’t work right. NTP works on my local network, but, NTP packets from public NTP servers are filtered out and the network administrator is quite unhelpful.

The solution? A tiny Python program that gets the time from time.nist.gov using a TCP socket and sets the time on the machine using date and hwclock. It won’t be as accurate as using NTP, but it is better than nothing.

Hopefully, this program will help others who suffer unhelpful, incompetent network administrators. You need root privileges. Run it as root or set this script to run from rc.local at boot time or from a daily cron job. To run it as a cron job, just copy the script to the /etc/cron.daily directory.

To be polite to NIST, and to keep all your machines synchronized, run this only on one m/c and have the remaining machines use that one as an NTP server behind the firewall.

If your firewall does not allow outgoing TCP connections, but allows web access, you might need a slightly different solution.