Managing Time On A Linux Server

Reading Time: 2 minutesThe time on your dedicated server might not be something you think about every day, but it is vitally important to keeping every piece of your server running in sync. Since it is so crucial, a lot of effort has been made by Linux developers to make it run smoothly without much effort. However, there are a few things you are going to be able to want to do with time on your server. This article assumes that you have root ssh access to a dedicated server. The following instructions for changing the time or timezone will not work on a Virtual Private Server.

Checking The Time On Your Server

On the command line on your server, you can run the date command to see the date, time, and timezone in that instant: [root@host]# date Tue Oct 12 16:20:19 EDT 2010 By default, date shows (in order): the day of the week, the month, the date, the time, the timezone, and the year.

Keeping Your Server Time In Sync With The World

This is almost completely automated. A program on your server called NTP constantly checks a timeserver on the Liquid Web network, whose sole job is to provide other servers on our network an accurate time. The only time that the automatic setup would not work is if for some reason the NTP daemon had crashed. To test, run the following command: ntpdate time.liquidweb.com If the NTP daemon is not running, the output will look something like this: [root@host]# ntpdate time.liquidweb.com 12 Oct 16:38:23 ntpdate[6260]: adjust time server 64.91.251.155 offset 0.001434 sec If you see a response that looks like that, run the following to restart the NTP daemon: [root@host]# /etc/init.d/ntpd start Starting ntpd: [ OK ] If, on the other hand, you get this response: [root@host]# ntpdate time.liquidweb.com 12 Oct 16:37:05 ntpdate[6250]: the NTP socket is in use, exiting Then NTP is working as it should, and you will not need to start the NTP daemon.

Changing The Timezone On Your Server

You may find that while your server is physically located in the Eastern timezone of the United States, visitors to your server are coming primarily from a different timezone. You can use NTP to change the timezone on your server as well. cd /usr/share/zoneinfo ls This will give you a list of available time zones to choose from. Some items in the list are directories which have even more time zones in them to choose from. Pick the one that you want to switch to. For this example, we will move the server time to Amsterdam. cp /etc/localtime /etc/localtime-old rm /etc/localtime These commands make a backup of your current timezone file, and then remove it. ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime This links your server’s timezone to the Amsterdam timezone file. /etc/init.d/ntpd restart This restarts the NTP daemon. After this restart, run date to check to see if the timezone has indeed been changed. [root@host]# date Tue Oct 12 23:01:58 CEST 2010 You can see that unlike our previous example, where the timezone was EDT, date now shows CEST as the timezone.

That About Covers It

While there are some more complex things you can do with the time on your server, showing the time on the server, manually syncing it with ntpdate, and updating the timezone cover nearly every problem you might encounter in the day-to-day operation of your server. === Liquid Web’s Heroic Support is always available to assist customers with this or any other issue. If you need our assistance please contact us: Toll Free 1.800.580.4985 International 517.322.0434 support@liquidweb.com https://manage.liquidweb.com/
Refer a friend and get hosting credit!