Although FreeBSD started shipping NTP preinstalled from around FreeBSD 7x all setup and ready to launch. I still prefer installing it from ports, the reason? Well it just seems more right to install it from an updated ports tree than to rely o the preinstalled version. Also for some strange reason I still hear people struggling to get the one shipped with FreeBSD working properly.
Now before we start we need to prepare a bit first. We need to do what has become known in my world as the “search path stunt”. In short this means we need to “rearrange” the search path for the current shell being used for root. This will come in handy later as well if you plan on installing other software. Note we are not removing stuff only rearranging things. Well actually we are removing “games” from the search path, nut we are rearranging as well. If you want to keep “games” in there fine. If not change your roots profile like below. I am making the vague assumption the you will be using the Bash shell here. The file you need to edit is this one /root/.bashrc
If you have not created a .bashrc file do so first. The lazy approach would be something like this.
cd /root cp .profile bashrc
Right find the following highligtet line allmost at the top in the .bashrc config file. The .bashrc file is located in /root
# remove /usr/games if you want PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:$HOME/bin; export PATH # Setting TERM is normally done through /etc/ttys. Do only override # if you're sure that you'll never log in via telnet or xterm or a # serial line.
Change that line i.e. the “search path” to look like this.
# remove /usr/games if you want PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$HOME/bin; export PATH # Setting TERM is normally done through /etc/ttys. Do only override # if you're sure that you'll never log in via telnet or xterm or a # serial line.
NTP needs perl to be installed on your system. If you are running the Bash shell you already have perl installed. If not NTP will install perl as a dependency. Right now that this is settled lets install NTP.
cd /usr/ports/net/ntp && make install clean BATCH=yes
After the installation is done we need to adjust what “time” servers we want to sync with. For the lazy ones out there you can go with the defaults if you like. If you wish to use other servers you can modify the NTP configuration file located here etc/ntp.conf
The default servers in case you mess up are.
server 0.freebsd.pool.ntp.org iburst server 1.freebsd.pool.ntp.org iburst server 2.freebsd.pool.ntp.org iburst server 3.freebsd.pool.ntp.org iburst
You can find more servers related to your timezone [here]
Below are the servers I use when running NTP. The ones marked with # are alternative servers just in case.
server 0.pool.ntp.org server 1.pool.ntp.org server 2.pool.ntp.org server 3.pool.ntp.org # server 0.europe.pool.ntp.org # server 1.europe.pool.ntp.org # server 2.europe.pool.ntp.org # server 3.europe.pool.ntp.org # server 0.dk.pool.ntp.org # server 1.dk.pool.ntp.org # server 2.dk.pool.ntp.org # server 3.dk.pool.ntp.org
Also while in the etc/ntp.conf file you need to specify where the drift file as well as log file are to be stored. Add the following 2 lines.
driftfile /var/db/ntpd.drift logfile /var/log/ntp.log
Important do not create the drift file. The system will take care of this. It may take up to an hour in order for the system to have enough information in order to create a drift file. Until the drift file has been created you may see warnings on your log files. They will go away though once the drift file has been created.
Now let’s make sure the NTP starts after reboot. Add the following lines to /etc/rc.conf
We are not ready to start NTP.
Wait for about 5 to 10 mins and check the status of NTP.
ntpq -p localhost
If NTP is working you should get an output very similar to the one below.
remote refid st t when poll reach delay offset jitter ======================================================================================== +freesbee.wheel 188.8.131.52 2 u 986 1024 377 4.506 0.708 0.123 ntp.ngdc.net 184.108.40.206 2 u 995 1024 377 0.993 -1.658 0.191 *n1.taur.dk .GPS. 1 u 26 1024 377 5.548 1.208 0.114 +zdani.szn.dk 220.127.116.11 2 u 31 1024 377 5.107 7.315 0.549
Oh btw if you are running a firewall remember to allow outgoing traffic for port 123 (udp).
And we are done here.