Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.

Ntp

From Gentoo Wiki
Revision as of 23:18, 5 July 2013 by A3li (Talk | contribs)

Jump to: navigation, search
External resources

NTP (Network Time Protocol) is used to synchronize the system time with other devices over the network, this usually happens in a client-server model.

Installation

Install net-misc/ntp:

→ Information about USE flags
USE flag Default Recommended Description
caps No Use Linux capabilities library to control privilege
debug No No Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see http://www.gentoo.org/proj/en/qa/backtraces.xml
ipv6 Yes Adds support for IP version 6
openntpd No Allow ntp to be installed alongside openntpd
parse-clocks No Add support for PARSE clocks
samba No Provide support for Samba's signing daemon (needed for Active Directory domain controllers)
selinux No  !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
snmp No Adds support for the Simple Network Management Protocol if available
ssl Yes Adds support for Secure Socket Layer connections
vim-syntax No Pulls in related vim syntax scripts
zeroconf No Support for DNS Service Discovery (DNS-SD)
root # emerge --ask ntp

Or alternatively, you can use net-misc/openntpd instead.

Configuration

The only configuration file is /etc/ntp.conf which is well explained with comments. Here are some of the more important settings.

Server

Here you can specify with which servers you want to synchronize your local time.

File/etc/ntp.conf

server 0.gentoo.pool.ntp.org
server 1.gentoo.pool.ntp.org
server 2.gentoo.pool.ntp.org
server 3.gentoo.pool.ntp.org
Note
Time zones and location of the server do not matter, it synchronizes the UTC time.

Per default the gentoo servers are listed and enabled. A list of available servers can be found here: ntp.org You can also define a home or company server here, given that ntpd is running and the machine is allowed to.

Permissions

To control who is allowed to synchronize with this machine and change the configuration, you can change these options.

Warning
Running ntpd without any options, allows all systems from all networks to synchronize to your NTP server.
  • access to NTP service allowed only from localhost.
File/etc/ntp.conf

# To deny other machines from changing the
# configuration but allow localhost:
restrict default nomodify nopeer
restrict 127.0.0.1
  • access to NTP service allowed only from the 192.168.0.0/24 network.
File/etc/ntp.conf

# To allow machines within your network to synchronize
# their clocks with your server, but ensure they are
# not allowed to configure the server or used as peers
# to synchronize against, uncomment this line.
#
restrict 192.168.0.0 mask 255.255.255.0 nomodify nopeer notrap

Usage

Basic tools and common usage

ntpd service

Add ntpd to the default runlevel to have the time synchronized automatically

root # rc-update add ntpd default
root #
/etc/init.d/ntp-client start

If ntpd 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 (~17min). So it is pretty common to adjust the time initially to whatever the server time is as a trusted source:

root # ntpd -g -c /etc/ntp.conf
Note
If ntpd is already running, it won't start a second time.

ntpdate

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

root # ntpdate pool.ntp.org

See also

External resources