Ntp

Article description::is an implementation of the [[Network Time Protocol.]]

Emerge
Install the suite of NTP programs:

Alternatively OpenNTPD can be used instead of.

Ntp-client
The service is used for one-time sync, usually during bootup, because  takes time to correct a large clock skew, or may even refuse to do so if the skew is too large. Starting the ntp-client service will run the sync only once and then exit. It is then expected that is used for maintaining the time until the next reboot.

To adjust 's command and upstream servers, edit the configuration file. The default configuration is populated with:

Server
In the servers that will be used to synchronize the local time for  can be specified. The default configuration is populated with:

By default the Gentoo servers are listed and enabled. A list of available servers can be found on ntp.org. A home or company server here can be used, if is running and the machine is allowed access.

On systems where a network connection is not always available at boot (laptops, etc.), it might help to add the following lines to server configuration:

This sets localhost as a server with low priority, so that the daemon starts properly even without a network connection and switches to using network servers when a connection is established.

Permissions
Permission are used to control who is allowed to synchronize or change permissions.

Access to NTP service allowed only from localhost. can be added to help prevent the server from being abused to conduct DDOS attacks:

Access to NTP service allowed only from the 192.0.2.0/24 network:

Denying access to NTP's monlist functionality, used for querying traffic stats but also exploited in a denial-of-service attack.

Usage
Basic tools and common usage.

ntp-client
To start the ntp-client:

To view the status of the client:

To have the client start at boot:

ntpdate
This used to be the client, but its functionality is now moved into and  itself. It is purely to set the local time when started and then exits (not a service):

Server
The server is both a client, and server. If the setup can not access net early in init, use server only instead.

ntpd service
If is run as a service, the time will automatically synchronize as long as the difference between the local time and the time on the server is less than 1000s (~17 mins). So it is pretty common to adjust the time initially to whatever the server time is as a trusted source:

Add ntpd to the default runlevel to have the time synchronized automatically. There is no need to run a client when the service is running. In this case verify that or  are not in any runlevels.

When it is confirmed the configuration is clear from or, add the  service:

To monitor status of the server:

External resources

 * http://www.ntp.org/
 * https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon
 * https://wiki.archlinux.org/index.php/systemd-timesyncd
 * https://blog.hboeck.de/archives/863-Dont-update-NTP-stop-using-it.html
 * http://phk.freebsd.dk/time/20140926.html