Time synchronisation
From Gentoo Linux Wiki
Contents |
[edit] Introduction
When trying to synchronise the clock on your system using an external source such as an NTP server, you may often stumble on difficult solutions that require a good deal of configuration. You might also be discouraged by the weight in kB of the packages, considering the simple task required: synchronise the system, local time with the correct time provided by some Internet server. This article will provide you with several simple solutions to achieve this task via the Transfer Control Protocol (TCP).
[edit] Clients
[edit] htpdate
People connecting to the Internet through a, sometimes transparent, proxy server or behind a firewall, in corporate or education-like environments, often have access to the HTTP and HTTPS protocols only. Since NTP requires access to outgoing and incoming packets from UDP port 123, synchronizing the system time with this protocol may prove difficult. If no LAN-accessible NTP server is available, one can synchronize the time using net-misc/htpdate via HTTP. The client can handle this job with an accuracy of ±0.5 seconds.
Query (-q) for the current time, in verbose mode (-d) and using a proxy address (-P):
Synchronise the system time using (-s) instead of (-q).
Instead of using sites similar to www.linux.org or www.opera.com, it is recommended that you choose Web servers that are hosted near you -- near in terms of TCP/IP routes, not pseudo-geographical location. For instance, a .com.ar site might be hosted in a North American data center. Your town hall Web site may always be a good reference.
You might also want to run htpdate as a daemon. As root, edit /etc/conf.d/htpdate by specifying at least one correct Web page, setting up the correct proxy address (if required) and, eventually, adding additional options (check the man page). Then[edit] rdate
The net-misc/rdate program downloads the time via the network. It connects to an RFC 868 time server over a TCP/IP network, prints the returned time and/or sets the system clock. It uses TCP or UDP to retrieve the current time of another machine. The project has been continued/ forked into net-misc/openrdate. The latter is an independent package of the OpenBSD's rdate program, available in Portage, and implements RFC 868 (inetd time) and RFC 2030 (SNTP/NTP) protocols.
Print the retrieved time:
Synchronize the system clock with the retrieved time:
Rdate also includes a boot script that can set the time during startup. The rdate boot script configuration file /etc/conf.d/rdate uses an NTP pool server. (Note: Rdate doesn't have support for NTP pool servers.) Locating a Stratum two time server will need done to have the init script run correctly.
[edit] getdate
The net-misc/getdate utility seems to be itself a fork of the rdate fork. From the man page it should go as follows:
Print the retrieved time:
Synchronize the system clock with the retrieved time:
Adjust the system clock with the retrieved time:
The -set option is a "brutal" change of the system time, while -adjust will let the kernel gently adjust the system time until it is correct.
[edit] Finalise synchronisation
To verify that your system time was changed correctly, run date. Also, consider to synchronise your hardware time with your system time (for example, here, upon reboot, the time went again out of sync). To store the Linux date and time in CMOS, do the following:
Again, check your work:
[edit] Troubleshooting
[edit] Time zones
Occasionally, your timezone settings might be incorrect. For example, it might be set to EST, while you're located in CET. There are several ways to set the timezone:
- Run tzselect (comes with sys-libs/timezone-data),
- Run cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime or
- Add TIMEZONE="Europe/Berlin" to /etc/conf.d/clock. Then emerge -tva sys-libs/timezone-data.
Now, htpdate will sync the time correctly, that is according to your local time zone.
[edit] Graphical clocks
Graphical clocks, like the one used by Desktop Environments, for example, may have a life of their own. That is, they might listen to their own internal timezone setting. This is why, after syncing, check your work with date. At the same time, check your clock's internal settings to see if it honours the correct timezone. For example, in Xfce, Orage clock requires not only that Orage be set to the correct timezone in Preferences, but also that Orage clock be configured appropriately in Clock options (perhaps confusing, but makes sense).
[edit] See Also
- NTP - Accurately synchronizes the system time. Also allows you to set up a time server for use on your network.
- High Drift Time Synchronization - for system clocks that get out of sync rapidly (must accept inaccuracy of up to two minutes, in worst case)