{{Note|This method is an alternative to the three methods listed [http://wiki.archlinux.org/index.php/Network_Time_Protocol#Making_openntpd_dependent_upon_network_access above]. The other three methods are preferred and work better. Use this as a last resort.}}

+

{{Note|This method is an alternative to the three methods listed [[#Making openntpd dependent upon network access|above]]. The other three methods are preferred and work better. Use this as a last resort.}}

This will wait 5 minutes before starting openntpd, which should give the system sufficient time to set up the network properly. If your network settings change often, you may also consider restarting the daemon regularly with cron. The next section has a few ways of controlling the daemon.

This will wait 5 minutes before starting openntpd, which should give the system sufficient time to set up the network properly. If your network settings change often, you may also consider restarting the daemon regularly with cron. The next section has a few ways of controlling the daemon.

Revision as of 08:28, 9 August 2010

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

This article describes two different methods to synchronize the Linux software clock (system clock) to internet time servers. For more information on computer timekeeping, see Time. Traditional ntpd is explained first and then OpenNTPD (part of the OpenBSD project) is explained. Both daemons can sync the local clock and act as a time server if needed. OpenNTPD is designed to be simple and secure, while ntpd has a larger set of features. Note that OpenNTPD is not currently maintained for Linux (see this thread).

NTPD

Installation

/etc/ntp.conf

The first line in your ntp.conf file should contain the following line:

restrict default kod nomodify notrap nopeer noquery

This restricts everyone from modifying anything and prevents everyone from querying your time server. In the past "notrust" was used here too, but the function of this option has changed to mean authentication with a key is required.

Following this line, you need to tell ntpd what to allow through into your server.

This tells ntpd that 1.2.3.4 and all IP addresses from the 192.168.0.0 range will be allowed to synchronize on this server, but they will not be allowed to modify anything. All other IP addresses in the world will still obey the default restrictions (the first line in the ntp.conf).

Now, is where the stratum 2 servers that our server will synchronize with come into play. The lines in ntp.conf will be used to tell ntpd what servers we would like to use for synchronizing (these are just examples; use ntp servers that are closest to your location). Please see http://support.ntp.org/bin/view/Servers/NTPPoolServers for a list a closer servers. The iburst option is recommended, and sends a burst of packets if it cannot obtain a connection with the first attempt. The "burst" option should never be used without explicit permission and will likely result in blacklisting.

The only thing left to do is add the drift file (which keeps track of yours clocks time deviation) and the log file location:

driftfile /etc/ntp.drift
logfile /var/log/ntp.log

In case our server loses internet access, we need to add localhost as a server or it will stop serving time to the network. We add localhost as a "stratum 10" server so that it will never be used unless internet access is lost.

/etc/rc.conf

OpenNTPD

Installation

First, the OpenNTPD package must be installed from the community repository:

# pacman -S openntpd

The default configuration is actually usable if all you want is to sync the time of the local computer. For more detailed settings, the Template:Filename file must be edited:

To sync to a particular server, uncomment and edit the "server" directive. You can find the server's URL in your area at www.pool.ntp.org/zone/@.

server ntp.example.org

The "servers" directive works the same as the "server" directive, however, if the DNS name resolves to multiple IP address, ALL of them will be synced to. The default, "pool.ntp.org" is working and should be acceptable in most cases.

pool.ntp.org

Any number of "server" or "servers" directives may be used.

If you want the computer you run OpenNTPD on to also be a time server, simply uncomment and edit the "listen" directive.

For example:

listen on *

will listen on all interfaces, and

listen on 127.0.0.1

will only listen on the loopback interface.

Your time server will only begin to serve time after it has synchronized itself to a high resolution. This may take hours, or days, depending on the accuracy of your system.

If openntpd is being used to set local system time only, it may be safely backgrounded.

DAEMONS=(syslog-ng network @openntpd ...)

To see the status of NTP syncing, visit Template:Filename and look for entries with "ntpd".

OpenNTPD adjusts the clock by small amounts at a time. It is designed this way to prevent sudden, large time fluctuations in your system, which could adversely affect system services (e.g., cron jobs). Thus, it can take some time to correct the time.

If your clock is off by more than 180 seconds you can try "Template:Codeline" in the console. If ntpd is already running, you can simply restart it with Template:Codeline, as the Arch openntpd package uses the "-s" flag by default. See Template:Codeline for more info. You can also set the system clock to as close to possible to the actual time and then let OpenNTPD fine tune the time.

Making openntpd dependent upon network access

If you have intermittent network access (you roam around on a laptop, you use dial-up, etc), it does not make sense to have Template:Codeline running as a system daemon on start up. Here are a few ways you can control Template:Codeline based on the presence of a network connection. These instructions should also work for Template:Codeline found further below.

Using netcfg

If you are using netcfg, you can also start/stop openntpd as a POST_UP/PRE_DOWN command in your network profile:

Of course, you will have to specify this manually for each network profile.

Using NetworkManager dispatcher

OpenNTPD can be brought up/down along with a network connection through the use of NetworkManager's dispatcher scripts. Place the following slightly modified Template:Filename script as Template:Filename

Starting openntpd in the background could lead to synchronization errors between the actual time and the time stored on your computer. If you recognize an increasing time difference between your desktop clock and the actual time, try to start the openntpd daemon normal and not in the background.

Note: This method is an alternative to the three methods listed above. The other three methods are preferred and work better. Use this as a last resort.

This will wait 5 minutes before starting openntpd, which should give the system sufficient time to set up the network properly. If your network settings change often, you may also consider restarting the daemon regularly with cron. The next section has a few ways of controlling the daemon.