Wednesday, November 3, 2010

Time of troubles - HTPDATE: Time Syncing under Proxy

Yeah, you know, in Europe last weekend we changed the time. In Italy we switched from CEST to CET.
Well, KDE4 is smart, as I remember giving the possibility of setting the time via NTP time servers. Also, no matter what desktop environment you use, on every Linux distro are available NTP utilities... but what to do if you are connected under proxy?

No way, if port 123 is closed, NTP won't work. So how to sync the time automagically without this amazing service?
The answer is HTP the "HTTP time protocol" which of course permits to sync under proxy, even if with less accuracy than NTP.

In archlinux HTP is available via the AUR via the htpdate package. Here you are the steps for its installation and use.

1) Go to the AUR to get the package tarball. and search for htp or htpdate
You'll find this package page:

2) Download the tarball

3) Extract it in your favourite folder

tar -xzvf htpdate.tar.gz

4) Make the package

cd htpdate

It will be created a ".tar.xz" file. That is your Archlinux package you can install with pacman -U

5) Install the package

sudo pacman -U htpdate-1.0.4-2-i686.pkg.tar.xz

Now you have htpdate installed... let's play with that...

6) Sync the time under proxy
It's very simple. Via the -P option you can tell htpdate your proxy address and port. If you want to see more output messages you can specify the -d option. Then with the -q option you submit only a time query without setting the time. With the -s option, instead, you will set your system time according to what retrieved from the specified host. As http server I used which should be well synced itself givend the service it supports ;-)

htpdate -dq -P proxyIP:proxyPORT httpSERVER

in order to set the time system wide you may need to be root

sudo htpdate -ds -P proxyIP:proxyPORT httpSERVER

Pay attention to this, the time which will be set is just your system time.
Following I'll show you how to set also the hardware clock preventing the time to be restored to the old one.

7) Set the hardware clock according to the system time


will show you the current system time (it should be correct because just set with htpdate)


will show you the current hardware clock time

With this command you can set the hardware clock according to your system time

sudo hwclock --systohc

Now your time is synced and you are happy!
You can further try to run htpdate as a deamon... Here you are the web version of the manpage and a good page on the gentoo wiki:

I think that's all ;-)

Be on time!

No comments:

Post a Comment