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.
|USE flag (what is that?)||Default||Recommended||Description|
||No||Use Linux capabilities library to control privilege|
||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|
||Yes||Add support for IP version 6|
||No||Allow ntp to be installed alongside openntpd|
||No||Add support for PARSE clocks|
||No||Provide support for Samba's signing daemon (needed for Active Directory domain controllers)|
||No||!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur|
||No||Add support for the Simple Network Management Protocol if available|
||Yes||Add support for Secure Socket Layer connections|
||No||Pulls in related vim syntax scripts|
||No||Support for DNS Service Discovery (DNS-SD)|
emerge --ask ntp
Or alternatively, you can use OpenNTPD instead.
to adjust ntp-client's command & upstream servers.
NTPCLIENT_CMD="ntpdate" NTPCLIENT_OPTS="-s -b -u \ 0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org \ 2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org"
Here you can specify with which servers you want to synchronize your local time for ntpd.
The default configuration is populated with
server 0.gentoo.pool.ntp.org server 1.gentoo.pool.ntp.org server 2.gentoo.pool.ntp.org server 3.gentoo.pool.ntp.org
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.
On systems, where network connection is not always available at boot (laptops etc.) it might be helpful to add the following lines to server configuration:
server 127.127.1.0 fudge 127.127.1.0 stratum 10
This sets localhost as a server with low priority, so that the daemon starts properly even without network connection and switches to using network servers when connection is established.
To control who is allowed to synchronize with this machine and change the configuration, you can change these options.
- access to NTP service allowed only from localhost. 'noquery' can be added to help prevent your server from being abused to conduct DDOS attacks
# To deny other machines from changing the # configuration but allow localhost: restrict default nomodify nopeer noquery restrict 127.0.0.1
- access to NTP service allowed only from the 192.168.0.0/24 network.
# 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
- denying access to NTP's monlist functionality, used for querying traffic stats but also exploited in a denial-of-service attack.
Basic tools and common usage
rc-service ntp-client start
To monitor status of the client.
rc-service ntp-client status
To start at boot.
rc-update add ntp-client default
This used to be the client, but its functionality is now moved into ntpd & ntp-client itself. It is purely to set the local time when started and then exits (not a service):
The server is both a client, and server. If your setup can't access net early in init, use server only instead.
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:
ntpd -g -c /etc/ntp.conf
If ntpd is already running, it won't start a second time.
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. Make sure you are not running ntp-client or ntpdate.
rc-service ntpd start
rc-update add ntpd default
To monitor status of the server.
rc-service ntpd status
To write your NTP sync time to the hardware at shutdown, and read hardware clock at start.
echo 'clock_hctosys="YES"' >> /etc/conf.d/hwclock
echo 'clock_systohc="YES"' >> /etc/conf.d/hwclock
rc-service hwclock restart
rc-update add hwclock boot
Or on a sufficiently modern kernel (3.9 or newer), you can configure Linux to handle it automatically:
Device Drivers ---> [*] Real Time Clock ---> [*] Set system time from RTC on startup and resume [*] Set the RTC time based on NTP synchronization
The hwclock init script is not needed at all with this method, which speeds up the boot/shutdown process slightly.