Synchronize the system clock to Network Time Protocol (NTP) under Fedora or Red Hat Linux

Posted on in Categories Linux, RedHat/Fedora Linux, Sys admin, Tips, Ubuntu Linux last updated May 5, 2006

The Network Time Protocol daemon (ntpd) program is a Linux operating system daemon. It sets and maintains the system time of day in synchronism with time servers (Mills).

You need to configure ntpd via /etc/ntp.conf configuration file. The file is well documented and you easily configure it.

Install ntpd

If ntpd is not installed use any one of the following command to install ntpd:
# yum install ntpOR# up2date ntp

Configuration

You should at least set following parameter in /etc/ntp.conf config file:
server <Time Server Name or IP Address>

For example, open /etc/ntp.conf file using vi text editor:
# vi /etc/ntp.conf
Locate server parameter and set it as follows:
server pool.ntp.org

Save the file and restart the ntpd service:
# /etc/init.d/ntpd start

You can synchronize the system clock to an NTP server immediately with following command:
# ntpdate pool.ntp.org
Output:

 5 May 14:36:01 ntpdate[5257]: adjust time server 61.206.115.3 offset -0.343242 sec

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

20 comment

  1. Hi ,
    I am getting message as NTP socket in use , exiting … I am getting this message after I started the ntp service .

    Do you know what it is ? any solution ?

    Gururaj

  2. I had the same problem with Gururaj, until I found out that I need to stop the NTP service first.
    /etc/init.d/ntpd stop
    Then only ntpdate pool.ntp.org will work.

    Why is this so when the instruction says to “Save the file and restart the ntpd service” then
    “You can synchronize the system clock to an NTP server immediately with following command:” ?

    The instructions doesn’t work in that order.

  3. Hi, wanted to sync up my (SentOS)VM with NTP. Followed the above mentioned steps, but did not get the intended (described) results. Instead , I got the following errors :
    [[email protected] America]# /etc/init.d/ntpd start
    Starting ntpd: <–Good ! No error !!
    [[email protected] ~]# ntpdate pool.ntp.org
    9 Mar 10:16:09 ntpdate[7372]: the NTP socket is in use, exiting
    [[email protected] ~]# ntpdate pool.ntp.org
    9 Mar 10:16:17 ntpdate[7375]: the NTP socket is in use, exiting
    [[email protected] ~]# rdate -s aa.bb.cc.dd
    rdate: couldn't connect to host aa.bb.cc.dd: No route to host
    I ended up fixing the issue , by date command ( as below ):
    [[email protected] America]# date
    Fri Mar 9 10:27:33 PST 2012 <–This date was incorrect
    [[email protected] etc]# date 030918402012
    Fri Mar 9 18:40:00 PST 2012 <–This is correct date [same as other servers]
    Also bounced the box to recheck if the above date sticks and it does ! Hence sharing this info and good news. Kindest regards,

  4. Comment by Sameed Worked for me.. here is my system output.

    [[email protected]~]# ntpdate
    11 Mar 17:11:11 ntpdate[31328]: the NTP socket is in use, exiting

    [[email protected]~]# date
    Mon Mar 11 17:11:17 CDT 2013

    [[email protected]~]# ntpdate -u
    11 Mar 17:29:29 ntpdate[31551]: step time server offset 979.012426 sec

    [[email protected]~]# date
    Mon Mar 11 17:29:35 CDT 2013

    1. not sure.. why my command was truncated in my comments so re posting.. I used:

      “ntpdate [our internal server ip]” – Failed

      “ntpdate -u [our internal server ip]” – worked.

  5. run:
    sntp -P no -r pool.ntp.org

    DO NOT use ntpdate anymore:

    ntpdate pool.ntp.org
    !!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!

    The ntpdate program is deprecated and should not be used any more.

  6. I am using SLES 11.1

    !!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!

    The ntpdate program is deprecated and should not be used any more. To
    quote the upstream ntp developers:

    “The functionality ntpdate offered is now provided by the ntpd daemon
    itself. If you call ntpd with the command line option -q it will
    retrieve the current time and set it accordingly.”

    Please check the Network Time Protocol (NTP) daemon man page and
    http://support.ntp.org/bin/view/Dev/DeprecatingNtpdate
    for further information.

    You can replace the ntpdate call with “rcntp ntptimeset” to achieve an
    inital poll of the servers specified in /etc/ntp.conf.

    The program /usr/sbin/sntp offers comparable functionality to ntpdate.

    ======

    sntp -P no -r [our internal server ip] ===> Worked

  7. Hallo Sir,

    How to set all my servers time table as my own server time in my Network ??? Is it possible & How ??? Can you please tell me the answer please … I am desperately want the replay sir…. THANKS in Advance.

Leave a Comment