This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
Launching a new virtual private server provides the user with a clock. You can see the time on your server with the command, date. Furthermore, you can adjust the server’s time zone, if needed, with the command export TZ=America/New_York,modifying the time zone to match your location.
Although the built in clock is helpful for keeping track of events on the server itself, it may begin to cause issues if the virtual server has to work with external machines. Emails sent out from a misconfigured server may arrive 3 minutes in the past on another, or users granted access only at certain times of the day, may find themselves blocked because of a time mismatch.
In order to resolve this, servers can be synced using the NTP protocol, matching their time to a reference time that servers around the world agree upon. This can be set up by installing the ntp daemon on the VPS— the program will automatically, slowly shift the server clock to match the reference one. Another method of fixing the time is to run ntpdate which automatically matches the time on the server with that of the central time. However, ntpdate is not an action that should be taken regularly because it syncs the virtual server’s time so quickly, the jump in time may cause issues with time sensitive software. Therefore, it is best to run this only once, prior to setting up NTP, and then let NTP take over—otherwise, if the server’s time is too far off, NTP may not launch altogether.
sudo ntpdate pool.ntp.org
NTP needs port 123 to be open in order to work.
The easiest way to ensure that your time remains up to date is to install the Network Time Protocol daemon.
You can download it from apt-get.
sudo apt-get install ntp
Once the program is installed, open up the configuration file:
sudo nano /etc/ntp.conf
Find the section within the configuration that lists the NTP Pool Project servers. The section will look like this:
server 0.ubuntu.pool.ntp.org server 1.ubuntu.pool.ntp.org server 2.ubuntu.pool.ntp.org server 3.ubuntu.pool.ntp.org
Each line then refers to a set of hourly-changing random servers that provide your server with the correct time. The servers that are set up are located all around the world, and you can see the details of the volunteer servers that provide the time with the
command. You should see something like the following:
remote refid st t when poll reach delay offset jitter ============================================================================== -mail.fspproduct 188.8.131.52 2 u 50 128 377 1.852 2.768 0.672 *higgins.chrtf.o 184.108.40.206 2 u 113 128 377 14.579 -0.408 2.817 +mdnworldwide.co 220.127.116.11 2 u 33 128 377 47.309 -0.572 1.033 -xen1.rack911.co 18.104.22.168 2 u 44 128 377 87.449 -5.716 0.605 +europium.canoni 22.214.171.124 2 u 127 128 377 75.755 -2.797 0.718
Although these servers will accomplish the task of setting and maintaining server time, you set your time much more effectively by limiting the ntp to the ones in your region (europe, north-america, oceania or asia), or even to the ones in your country, for example in America:
You can find the list international country codes (although not all of the countries have codes) here
Once all of the information is in the configuration file, restart ntp:
sudo service ntp restart
NTP will slowly start to adjust the virtual private server’s time.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.