Make sure your Linux servers' date and time are correct and synchronized

Nowadays, most people assume that all modern computers and operating systems have network time synchronization set up properly and switched on by default. However, this is not the case with many Linux servers—especially if you didn't install Linux and configure it yourself (as would be the case with most cloud-based OS images like those used to generate new servers on Linode).

After setting up a new server on Linode or some other Linux VPS or dedicated server provider, you should always do the following to make sure the server's timezone and date and time synchronization are configured and working correctly:

  1. Set the server's timezone correctly. Basically, create a symbolic link from /etc/localtime to the proper timezone file inside /usr/share/zoneinfo/.
  2. Make sure ntp is installed using your system's package manager (for example, on CentOS/RHEL: $ sudo yum install ntp to install it if it's not installed already).
  3. Make sure ntpd is set to run on startup: $ sudo /sbin/chkconfig ntpd on
  4. (Optional: Choose different/region-specific NTP servers and place them inside /etc/ntp.conf, replacing the default servers that are in there).
  5. Make sure your iptables firewall is set to accept UDP traffic on port 123:
    $ sudo iptables -I INPUT -p udp --dport 123 -j ACCEPT
    $ sudo iptables -I OUTPUT -p udp --sport 123 -j ACCEPT
  6. Test ntp with ntpdate: $ sudo ntpdate pool.ntp.org. This should show that there was an offset from the current system clock and the value retrieved over the Internet.
  7. Start ntpd, and your server should be happily in-sync, hopefully within a second or less at all times, with clocks around the world! $ sudo service ntpd start

These instructions were tested on CentOS 5.x and 6.x. Other distributions should be similar.