which ntpd |
Hopefully, you will get back an answer like /usr/sbin/ntpd. Note that as it's a system command, you might have to be root or do an su - to find it. (Note that it is an su - with a hyphen after the su. This gives you root's $PATH). If you have ntpd go to step 3, otherwise, go to step 2.
cd /etc vi ntp.conf |
We are about to create a configuration file. In FreeBSD 5.x this is /etc/ntp.conf. It might, in other distributions, be called ntpd.conf. (I don't recollect seeing it anywhere, but I'm not sure. Note that in some distributions, the file might already be there--it might be in /etc or sometimes in an /etc/ntp directory) To check the names of the necessary files for your distribution, check man ntpd. My ntp.conf reads
server 0.pool.ntp.org server 1.pool.ntp.org server 2.pool.ntp.org driftfile /var/db/ntpd.drift |
servers pool.ntp.org |
I believe the servers, as opposed to server, keyword is for openntpd, which is from OpenBSD and used by many Linux distributions. FreeBSD's base ntpd doesn't seem to recognize the servers keyword, requiring its ntp.conf to be as I have shown above, with server, rather than servers, and listing multiple servers from the ntp.org pool.
Whether one uses openntpd with the servers keyword, or the older version, with server and listing multiple servers, this configuration file tells the ntpd daemon to check the time with any of the servers in the group at pool.ntp.org. To get an idea of the servers being used, you can use
ntpq -p |
If you wish to keep any other boxes on your network (or off it) from accessing your ntp daemon add
restrict default ignore |
Add ntpd to services to begin at startup. This will vary with distribution. We have a guide to some common ones here.
In most distributions, you can now start it by simply typing
ntpd |
at a command prompt.
In FreeBSD 5.x at least, it is started from /etc/rc.conf. One adds the line
ntpd_enable="YES" |
(In FreeBSD at least you can leave the driftfile line out of ntp.conf and it will create one by default in /var/db. With some Linux distros, you might have to specify a driftfile. The /var/db/ntpd.drift is the FreeBSD default, it might be different in your Linux distribution. Another common location is /etc/ntpd/ntpd.drift)
netstat -an | grep 123 |
If I get back something like
udp4 0 0 *.123 *.* |
I know that it's working.
In FreeBSD, one usually sets ntpd from rc.conf. If for some reason your computer's clock is really off (dying cmos battery or whatever) and the time difference is too great, ntpd might not work. One solution is to run ntpdate once at startup. If you're going to do this, it will look for the server in /etc/ntp.conf, but you would want to add the -b flag. So, one could have these lines in /etc/rc.conf
ntdate_enable="YES" ntpdate_flags="-b" ntpd_enable="YES" |
Note that the ntpdate line is above the ntpd line. If you call ntpdate and ntpd is running it will die with an error message.
The other solution is using (on most operating systems) the -s flag. This will cause ntpd to set the time, even if it is completely off. On OpenBSD for example, one can add the line
ntpd_flags="-s" |
|
Congratulations you're done.