Service Name
ntpd
Description
This service executes the Network Time Protocol (NTP) daemon ntpd. The purpose is to synchronize the time of the local computer to a NTP server or other reference time source such as a radio or satellite receiver or modem. The NTP time protocol provides accuracies typically within a millisecond on LANs and up to a few tens of milliseconds on WANs relative to Coordinated Universal Time (UTC) via a Global Positioning Service (GPS) receiver. The Linux NTP package is a complete implementation of the Network Time Protocol (NTP) version 4, but also retains compatibility with prior versions 1, 2, and 3.
The NTP system uses two main roles for participating computers: server or client. Time servers supply time to one or more NTP clients. NTP clients use the reference time from one or more NTP servers to determine the local time. This scheme allows an NTP client to reject bogus time from an NTP server, to compensate for network-induced delays and to determine which NTP server has the best time. An NTP client may also serve as an NTP server for other machines.
The ntpd program operates by exchanging messages through UDP port 123 with one or more configured servers at designated poll intervals. The program requires several exchanges from the majority of chosen servers so the signal processing and mitigation algorithms can accumulate and groom the data before setting the local clock. Ensure that UDP port 123 is not blocked by firewall rules.
Usually each country provides an official time reference. In the USA, the National Institute of Standards (NIST) provides this service. The national time reference is called a tier 1 server. NTP servers who use this source for their reference time are called tier 2 servers. NTP servers who connect to tier 2 servers are known as tier 3 servers, and so on. NTP clients who use their own atomic clocks are also called tier 1 servers. NTP clients must connect to an NTP server to synchronize their clocks. Some ISPs provide NTP server access to their clients, but publicly-accessible servers at pool.ntp.org are also available. Higher-tier NTP servers are usually no less accurate than their lower-tier counterparts, which can get overburdened. Many companies implement their own NTP server by connecting to external NTP servers, reducing the load on these external servers.
The Linux NTP service is quite configurable. Comprehensive on-line documentation is supplied in both ntpd manual pages and /usr/share/doc/ntp-[version] documentation.
Service Control
This service is handled by init.d script /etc/init.d/ntp. Its usage is as follows:
# /sbin/service ntpd usage: /etc/init.d/ntpd {start|stop|restart|condrestart|status}
Start the service as follows:
# service ntpd start ntpd: Synchronizing with time server: [ OK ] Starting ntpd: [ OK ]
Stop the service as follows:
# service ntpd stop Shutting down ntpd: [ OK ]
Check if the serivce is started or stopped:
# service ntpd status ntpd is stopped
If the service is started, then restart it; otherwise do nothing. Typically used only by the RPM install scripts.
# service ntpd condrestart Shutting down ntpd: [ OK ] Starting ntpd: [ OK ]
Determine which system run levels the service is active:
# /sbin/chkconfig --list ntpd ntpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
Configuration
Ordinarily, ntpd reads the ntp.conf configuration file at startup time in order to determine the synchronization sources and operating modes. It is also possible to specify a working, although limited, configuration entirely on the command line, obviating the need for a configuration file.
Usually, the configuration file is installed in the /etc directory, but could be installed elsewhere (see the -c conffile command line option). The file format is similar to other Unix configuration files – comments begin with a # character and extend to the end of the line; blank lines are ignored.
The default ntp.conf file looks like this:
# cat /etc/ntp.conf tinker panic 0 restrict 127.0.0.1 restrict ::1 restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery server 0.pool.ntp.org server 1.pool.ntp.org server 2.pool.ntp.org driftfile /var/lib/ntp/drift disable monitor
In addition, ntpd daemon can be run with various options. In order to add command line options to the ntpd service (/etc/init.d/ntpd), one has to edit /etc/sysconfig/ntpd file and add the desired option to the OPTIONS variable, and restart the service via ‘service ntpd restart’.
For example, the -x argument is mandatory for RAC configurations and the /etc/sysconfig/ntpd file looks as:
# cat /etc/sysconfig/ntpd # Command line options for ntpd OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"
You can check the settings from that /etc/sysconfig/ntpd file but it will not be reliable if the ntpd process is started manually for some reason. To check the arguments you can use command line:
# ps -o args -p `cat /var/run/ntpd.pid` COMMAND /usr/sbin/ntpd -u ntp:ntp -x -u ntp:ntp -p /var/run/ntpd.pid -g
Configuration Files
/etc/ntp/ntp.conf – the default name of the configuration file
/var/lib/ntp/drift – the default name of the drift file
/etc/ntp/keys – the default name of the key file
/etc/sysconfig/ntpd – setting command line options for ntpd daemon