How can I sync my server's time to a time server?

ntpdate allows you to view or set system time from one or more NTP servers. The first thing you need to do is find a time server you can query. Here is a list of public time servers, or you can use one of the following:

  • clock.redhat.com
  • time.nist.gov
  • pool.ntp.org

For example, if you only want to query an NTP server and make sure that you can reach it, use the following command:

# ntpdate -q clock.redhat.com
server 66.187.233.4, stratum 1, offset -0.015817, delay 0.06786
21 Apr 23:29:59 ntpdate[2407]: adjust time server 66.187.233.4 offset -0.015817 sec

Note that some firewall systems do not allow NTP traffic. NTP uses UDP port 123. If you would like to query more than one server and set your system clock with the result, use the following:

# ntpdate clock.redhat.com time.nist.gov
21 Apr 23:39:31 ntpdate[19187]: step time server 66.187.233.4 offset 60.562961 sec

You can add the -v switch for verbose output.

This command is very similar to the rdate command. The ntpdate command can be used in startup scripts or cron jobs to automatically set the system time without running a dedicated server process. You will definitely want to try to retrieve the time from an NTP server with ntpdate before setting up your own NTP server. This will ensure that (a) you have connectivity (b) your firewall does not block NTP. Another thing to note about the ntpdate command is that it will not work in update mode if you are running a local NTP server process. It will work in query mode.

Your rating: None Average: 4 (2 votes)