Time Synchronization
From Gentoo Linux Wiki
Contents |
[edit] Introduction
Configuring time synchronization can be difficult, and there are many ways to go about doing it, each with their own methods of configuration. The goal is to get your clock synchronized with a server on the Internet.
The classic tool to synchronize your system time, is the NTP and usually net-misc/ntp and others. But sometimes you have network restrictions or simply you need an easy-to-configure tool.
Several minimalist packages in Portage are:
[edit] Solutions
[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 is somewhat difficult. If no LAN-accesable NTP server is available, one can synchronize the time using HTTP, and htpdate can handle this job (with an accuracy of +-0.5 seconds).
To install:
The following command shows how to query (-q) a random web page in verbose mode (-d) using a proxy address (-P).
To set the system time, simply replace -q option with -s.
That's all you need to do. Additionally, instead of using www.linux.org, or www.opera.com, you may want to 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 datacenter. Your town hall web site may be a good reference.
You might also want to run htpdate as a daemon. As root, edit /etc/conf.d/htpdate and specify at least one correct Internet web page, setting up the correct proxy address (if needed) and, eventually, adding additional options (check the man page). Then
[edit] rdate
The 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.
To install:
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. rdate doesn't have support for NTP pool servers. Locating a Stratum two time server will need to be done to have the init script run correctly.
[edit] openntpd
emerge it:
or
Check that the config is to your liking. If you only want to synchronize time for your computer and not provide a server do NOT use the listen line. You may want to use a continental or country-specific pool, e.g. europe.pool.ntp.org or uk.pool.ntp.org. To ensure you get an accurate time you should confirm at http://www.pool.ntp.org/zone/@ that your country/continent has sufficient servers, or else use a higher level or multiple pools.
listen on * #Only use this line if you want to provide an NTP service to other computers! servers pool.ntp.org
Finally start the program and make it start at default level at every boot
[edit] openrdate
This program is a fork of rdate, and in addition to the RFC 868 (inetd time), it also implements the RFC 2030 (SNTP/NTP) protocol. It works right out of the box.
It's still masked so unmask and emerge:
Check that the config is to your liking:
RDATE_SERVER="pool.ntp.org" OPENRDATE_OPTS="-n -c"
Finally start the program and make it start at default level at every boot
[edit] getdate
The getdate utility seems to be itself a fork of the rdate fork. To install:
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] Finalize synchronization
To verify that your system time has changed correctly, run
Also, consider to synchronize 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, issue the following command
Again, to check your work, run:
[edit] Troubleshooting
[edit] Time zones
Occasionally, your timezone settings might be incorrect. For example it could be set to EST when it should be CST. There are a couple of ways to set the timezone:
- Run tzselect (comes with sys-libs/timezone-data):
or
- Copy the timezone info manually:
or
- Edit your /etc/conf.d/clock and (re)emerge sys-libs/timezone-data
TIMEZONE="Europe/Berlin"
Now, htpdate will sync the time correctly, according to your local time zone.
[edit] Graphical clocks
Graphical clocks may not respect the system timezone setting. For this reason, after syncing, check your work with date. If date shows the correct time, but you clock does not, check your graphical clock's settings to see what timezone it is using. 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 (this makes sense, because some people like to have several different timezones displayed in their clocks).
[edit] See also
- NTP: the Network Time Protocol
- High Drift Time Synchronization - for system clocks that get out of sync rapidly (must accept inaccuracy of up to two minutes, in worst case)
Old Wiki links:
- HOWTO NTP - accurately synchronizes the system time
- HOWTO NTP Using OpenNTPD - an easy-to-use, partial implementation of the NTP
- HOWTO Syncing Time via internet - for system clocks that get out of sync rapidly (must accept inaccuracy of up to two minutes, in worst case)
External links:
- HTTP Time Protocol (HTP) - Homepage of htpdate
- openrdate - A platform-independent package of OpenBSD's rdate program.