Post details: Network Time Protocol Daemon
08/12/06
Network Time Protocol Daemon
The NTP is designed to keep clocks on multiple servers synchronized to Atomic Time and is a great tool for Server Administrators. You may be asking why a tool like this is important or why it would be necessary. Well the answer is very simple; over time, time keeping devices tend to "drift" off of an accurate measure. For instance, the watch on your wrist will drift over time and this is still a problem that occurs even on the most modern computers.
Prerequisites
- The examples in this article are all shown on FreeBSD 6.x
- The NTPd is part of the FreeBSD base files. You can install the daemon from ports but that is not covered in this document
- A CLI editor such as ee
- Additional files and references may be found at the end of the article
Setup
The only required file is /etc/ntp.conf. To be able to use the NTPd this file is a must. There are two parts to this file; however, the second part is not necessary since it is covered in the start command. Below I have listed my ntp.conf, but you will want to look up your own time servers to use. Another thing to note is the option 'logconfig all'. You may wish to comment this out to maintain smaller log files.
# This is the configuration file for NTP
# (Network Time Protocol). More info at
# www.NTP.org
# This computer will act as a stratum 2 time
# server by referencing the following
# stratum 1 time servers:
server time.nist.gov prefer
server time-b.timefreq.bldrdoc.gov
server time-a.timefreq.bldrdoc.gov
server nist1.aol-va.truetime.com
server nist1.columbiacountyga.gov
server clock.via.net
# Log Configuration
logconfig all
logfile /var/log/ntp.log
The next step is to edit /etc/rc.conf so that we can start NTPd as soon as the server starts up. To do this, open the file with your favorite editor and add the following lines to the end. The first line tells the the system to enable NTPd. The second line instructs the server to sync when initially started. Pretty simple stuff.
# NTPd
ntpd_enable="YES"
ntpd_sync_on_start="YES"
Starting NTPd
Now there's not much left to do except start the server. That can be accomplished by using the RC script /etc/rc.d/ntpd.
baku# /etc/rc.d/ntpd status
ntpd is not running.
baku# /etc/rc.d/ntpd start
Starting ntpd.
baku# /etc/rc.d/ntpd status
ntpd is running as pid 50037.
baku#
You can verify that the server is running with a couple of quick checks. You can tail the log file or you can look in the process list. Another check is using the date command.
baku# ps x | grep ntp
50037 ?? Ss 0:00.10 /usr/sbin/ntpd -g -p /var/run/ntpd.pid -f /var/db/ntpd.drift
50045 ?? S 0:00.00 /usr/sbin/ntpd -g -p /var/run/ntpd.pid -f /var/db/ntpd.drift
baku# date
Fri Aug 11 18:25:52 CDT 2006
baku#
Earlier I mentioned that the second part of the configuration file wasn't necessary. The reasoning for this is because of the command issued from the RC script to start the daemon above. The switch and file (-f /var/db/ntpd.drift) are there to keep a log of your clock's tendency to drift and compensates for it.
Conclusion
See, that wasn't very hard now was it? Keeping your time accurate is very useful. There are more things you can do with NTPd like securing your daemon so that your network is the only one with access to it. You can also leave it open to share your daemon as a Stratum 2 server. These are more advanced techniques, but that's for another article.
References
Network Time Protocol
NTP Public Services Project
Clock Synchronization with NTP
This post is licensed under a
Creative Commons License.
Comments:
This post has 2 feedbacks awaiting moderation...
Leave a comment: