How to configure time on Centos


There are several ways in which you can set date and time on a Linux machine.
To view the current date and time use the date command:

Linux date and time
The kernel will usually set its timezone and clock based on the hardware clock. Even if this method is not so accurate because the clock will develop a drift, it’s one way to set the timezone. You can view the hardware clock by typing
hwclock -r
Linux tutorial

You can use the following syntax to set time and date:
date -s “10 OCT 2015 14:00:00”
date -set “10 OCT 2015 14:00:00”

Setting the time in Linux
You can also format the timezone or set specific fields just like in the following example:
date +%Y%m%d -s “20140113”

date +%T -s “15:00:00”

date +%T%p -s “3:00:00AM”

Linux setting the time


Once you set the localtime, you can configure the hardware clock to use it by executing the following command:
hwclock –hctosys –localtime
To change the timezone, you will need to create a symbolic link between a timezone file from /usr/share/zoneinfo/ and /etc/localtime. First remove the already existing localtime file by executing rm /etc/localtime and then ln -sf /usr/share/zoneinfo/Europe/Bucharest /etc/localtime:

Linux symbolic link
You can also export the variable using the following command: export TZ=Europe/Bucharest or use the tzselect command and follow the indications:
Configure time in Linux
If your server is part of a network that has an NTP service or you want to syncronize your machine with an Internet time server, you will need to install ntp by executing yum install ntp:
NTP server
Modify the /etc/ntpd.conf file and add the NTP servers that you desire
Network Time Protocol Server
Now start the service by executing /etc/init.d/ntpd start or service ntpd start. At boot time run ntupdate server_name to sync with the NTP server. Don’t forget to run the NTP daemon at boot time.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s