FreeBSD Time/Clock Synchronization with NTP server
Wednesday, May 30th, 2007FreeBSD use the Network Time Protocol (NTP) for synchronising the clocks of computer systems over packet-switched, variable-latency data networks. NTP uses UDP port 123. If you have one computer or single server then you can easily synchronization time with other NTP servers. All you need is ntp client called ntpdate. It is use to set the date and time via NTP servers.
Step # 1: Install NTP
# pkg_add -rv ntp
OR
# cd /usr/ports/net/ntp # make; make install
Step # 2: Pick appropriate NTP Servers
Visit public ntp timeserver list to pick up your NTP server.
Step # 2: Open UDP port 123 at firewall
If you are running FreeBSD ipfilter firewall then you need to open the UDP port 123. Just add following rule to your firewall script:
pass out quick on lnc0 proto udp from YOUR-SERVER to any port = 123 keep state
OR
pass out quick on lnc0 proto udp from YOUR-SERVER to TIME-SERVER-IP port = 123 keep state
For example, my FreeBSD workstation IP is 192.168.1.16 and 61.246.176.131 is IP of NTP server then my rule is in ipf.conf file as follows:
pass out quick on lnc0 proto udp from 192.168.1.16 to 61.246.176.131 port = 123 keep state
Step # 4: Test clock Synchronization
Just run ntpdate command as follows to see you can set date and clock via NTP:
a) Set wrong date (Mon Dec 13 4:27 pm)
# date 0412131627
b) Now set correct date with ntp:
# ntpdate -v -b in.pool.ntp.org
13 Dec 16:27:50 ntpdate[997]: ntpdate 4.2.0-a Thu Nov 3 07:34:22 UTC 2005 (1)
25 Jan 12:35:47 ntpdate[997]: step time server 61.246.176.131 offset 35237275.965726 sec
c) You can verify that correct data is setup:
# date
Wed Jan 25 12:36:21 IST 2006
Step # 5 : Enable date and time/ clock Synchronization at boot time
You need to set ntpdate via /etc/rc.local file.
# vi /etc/rc.local
Append following line to it:
ntpdate_enable=”YES”
ntpdate_hosts=”asia.pool.ntp.org”
Save the file. Make sure you have correct ntpdate_hosts server entry.

























