Polls

Topics

How to: FreeBSD Setup Time / Clock Synchronization with NTP server and ntpdate command

Posted by Vivek on Wednesday January 25, 06 @12:49 pm

FreeBSD use the Network Time Protocol (NTP) for synchronizing 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.

FreeBSD: Install NTP Client

Use any one of the following command to install NTP:

# pkg_add -rv  ntp

OR

# cd /usr/ports/net/ntp
# make; make install

Pick appropriate NTP Servers

Visit public ntp timeserver list to pick up your NTP server.

Open UDP port 123 at firewall

If you are running FreeBSD ipfilter firewall, 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

FreeBSD test clock synchronization

Just run ntpdate command as follows to see you can set date and clock via NTP:
Set wrong date (Mon Dec 13 4:27 pm):

# date 0412131627

Now set correct date with ntp client:

# 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

You can verify that correct data is setup:

# date

Output:

Wed Jan 25 12:36:21 IST 2006

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 and close the file. Make sure you have correct ntpdate_hosts server entry.

See also:

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in...

Discussion on This Article:

  1. fink Says:

    how can i tell what date the tutorial was written, or what version of of software was used?

  2. nixcraft Says:

    This is one is written on FreeBSD 6.0 but it should work on any version. This entry was written on Jan-25-2006.

    Hope this helps.

  3. Linux or FreeBSD command to display system time and date | Frequently Asked Questions Says:

    [...] Please see previous articles for time synchronization under Linux or FreeBSD [...]

  4. batso Says:

    i have problem. i can’t configuration & check NTP server.
    Help Me. My config:
    install /usr/ports/net/ntp
    make install
    install finish
    my server ip address:192.168.0.1/24
    1./etc/rc.conf
    ntpdate_enable=”YES”
    ntpdate_program=”/usr/local/bin/ntpdate”
    ntpdate_flags=”-b”
    ntpd_enable=”YES”
    ntpd_program=”/usr/local/bin/ntpd”
    2./etc/ntp.conf
    server 0.asia.pool.ntp.org
    server 1.asia.pool.ntp.org
    server 2.asia.pool.ntp.org
    server 3.asia.pool.ntp.org
    server 192.168.0.1
    broadcast 192.168.0.255
    driftfile /var/db/ntp.drift
    logfile /var/log/ntp.log

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , ~ Last updated on: September 13, 2007

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.