Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What script or program is needed to keep a unix system date correct? I find that my linux servers are behind a few minutes from actual time.

share|improve this question
add comment

migrated from stackoverflow.com Nov 5 '09 at 21:44

This question came from our site for professional and enthusiast programmers.

8 Answers

Use ntpd.

From manpage:

The ntpd daemon synchronizes the local clock to one or more remote NTP servers, and can also act as an NTP server itself, redistributing the local time.

share|improve this answer
add comment

You're looking for ntp. Here's some info for installing and configuring it on Ubuntu.

share|improve this answer
add comment

We use ntpdate - which I think is a lot lighter weight than the full ntp.

I have a cron job that runs "ntpdate my.ntp.server > /dev/null" a couple times per day to keep things in sync.

If it is important that your time be adjusted gradually (rather than synched immediately), then ntp would be your better option.

Note that if this is a virtual machine, time drift is a common problem, and there might be some included "tools" that allow you to sync time with the host machine - usually a better option.

share|improve this answer
    
+1 for the mentioning of how this issue happens more on virtual machines. I've used a service set to do this more regularly but cron obviously works great too. –  sparks Nov 5 '09 at 22:58
add comment

ntpd, as others have pointed out, is the obvious choice to keep the clock in sync once it's set. However, you'll probably also want "ntpdate" to set it initially from a good network time source, as ntp won't adjust the clock if it's more than a couple minutes out of sync.

Both should be available from the package manager of the Linux distro you're using.

share|improve this answer
add comment

You would need the network time protocol deamon link

share|improve this answer
add comment

Also, you might try adjtime

share|improve this answer
add comment

I`m using exactly this crontab entry.

*/10    *       *       *       *       root    /usr/sbin/ntpdate time.fu-berlin.de > /dev/null 2>&1

time.fu-berlin.de is a server in germany, you can use it also but I suggest using a timeserver nerer to you.

share|improve this answer
add comment

If you are going to use ntp, which recommendation I would second (er, third; well, Nth), you will need a timeserver. If your organization does not have one, you can use pool.ntp.org.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.