{"id":1035,"date":"2018-06-25T10:41:40","date_gmt":"2018-06-25T05:11:40","guid":{"rendered":"http:\/\/jaipurhosting.com\/blog\/?p=1035"},"modified":"2019-04-27T11:47:26","modified_gmt":"2019-04-27T06:17:26","slug":"how-to-setup-timezone-and-ntp-on-centos-6","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/how-to-setup-timezone-and-ntp-on-centos-6\/","title":{"rendered":"How To Setup Timezone and NTP on CentOS 6"},"content":{"rendered":"<p><strong>Description&nbsp;<\/strong><\/p>\n<p>It&#8217;s important to set and maintain the <strong>time<\/strong> on servers correctly.<\/p>\n<p>Wrongly configured time will cause chaos within the server environment, such as <strong>data inconsistency<\/strong>, <strong>data synchronization failures<\/strong>, and<strong> job scheduling problems<\/strong>.<\/p>\n<p>To avoid these undesirable issues, first, you need to set a reasonable <strong>time zone<\/strong> on your server, giving your server a relatively precise local time.<\/p>\n<p>Second, for communication purposes, you can also use NTP (<strong>Network Time Protocol<\/strong>) to synchronize the time of your servers and remote NTP servers, keeping the time on your machines in perfect order.<\/p>\n<p>Now we are going to look about how to set the time zone and how to synchronize the time using NTP on a CentOS 6 x64 server<\/p>\n<p><strong>Step 1:<\/strong> Set the timezone<\/p>\n<p>Input the following command in your terminal<\/p>\n<p><strong>date<\/strong><\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# date<\/pre>\n<p>&nbsp;<\/p>\n<p>CentOS 6 OS uses the UTC time by default.<\/p>\n<p>You can modify it to any time zone as you wish, but using the local timezone of the server&#8217;s physical location is a best practice.<\/p>\n<p>If our server was running in India, then we would use the &#8220;Asia\/Kolkata&#8221; time zone:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# rm -rf \/etc\/localtime<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# ln -s \/usr\/share\/zoneinfo\/Asia\/Kolkata \/etc\/localtime<\/pre>\n<p>&nbsp;<\/p>\n<p>You can navigate to the directory <strong>\/usr\/share\/zoneinfo<\/strong> to find the appropriate time zone.<\/p>\n<p>Input date again, you will find that the local system time has changed to IST (<strong>Indian Standard Time<\/strong>) GMT+5.5.<\/p>\n<p>Next, we will write the system time info into the hardware clock.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# vi \/etc\/sysconfig\/clock<\/pre>\n<p>Modify the content of this file as below.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">ZONE=\"Asia\/Kolkata\"\nUTC=false\nARC=false<\/pre>\n<p>Save and quit.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">:wq<\/pre>\n<p>&nbsp;<\/p>\n<p>Write the system time into the hardware clock<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# hwclock --systohc --localtime<\/pre>\n<p>Input <strong>hwclock<\/strong> to see the result.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong> Upgrade NTP<\/p>\n<p>By default, the ntp daemon program has been installed and set up to run on the CentOS 6 server instance.<\/p>\n<p>For security purposes, the first thing that we should do is to upgrade it to the latest version.<\/p>\n<p>To see the ntpd version:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# ntpd --version<\/pre>\n<p>For example at the time of writing, the default installed version is &#8220;4.2.6p5&#8221;.<\/p>\n<p>Stop the ntpd service:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# service ntpd stop<\/pre>\n<p>Download the latest version of the ntp program from its official website:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# wget http:\/\/archive.ntp.org\/ntp4\/ntp-4.2\/ntp-4.2.8p2.tar.gz\n<\/pre>\n<p>Unzip and go into the newly created directory:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# tar -zxvf ntp-4.2.8p2.tar.gz<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# cd ntp-4.2.8p2<\/pre>\n<p>Install the necessary components for our installation:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# yum -y install gcc libcap-devel<\/pre>\n<p>We are going to upgrade the existing ntpd program, we need to determine the owner and group info:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# cat \/etc\/group<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# cat \/etc\/passwd<\/pre>\n<p>As you see, the ntp program belongs to the owner ntp (uid=38) and the group ntp (gid=38).<\/p>\n<p>For security purposes, update the configuration of the ntp user account:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# usermod -c \"Network Time Protocol\" -d \/var\/lib\/ntp -u 38 -g ntp -s \/bin\/false ntp<\/pre>\n<p>Compile and install the ntp program:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">.\/configure --prefix=\/usr --bindir=\/usr\/sbin --sysconfdir=\/etc --enable-linuxcaps --with-lineeditlibs=readline --docdir=\/usr\/share\/doc\/ntp-4.2.8p2 &amp;&amp; make<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">make install &amp;&amp; install -v -o ntp -g ntp -d \/var\/lib\/ntp<\/pre>\n<p>Once the installation has completed, you can check the ntpd version again:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# ntpd --version<\/pre>\n<p>As you see, the ntp program has been upgraded to the latest version &#8220;4.2.8p2&#8221;.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Configure ntp<\/p>\n<p>For better performance and security, we need to modify the default configuration:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# vi \/etc\/ntp.conf<\/pre>\n<p>In the ntp.conf configuration file, you can find the ntp servers like:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org\nserver 3.us.pool.ntp.org<\/pre>\n<p>For security purposes, we should restrict permissions.<\/p>\n<p>While still in the <strong>ntp.conf<\/strong> configuration file, find the following two rows:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# restrict default kod nomodify notrap nopeer noquery<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# restrict -6 default kod nomodify notrap nopeer noquery<\/pre>\n<p>Modify them as below:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# restrict default limited kod nomodify notrap nopeer noquery<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# restrict -6 default limited kod nomodify notrap nopeer noquery<\/pre>\n<p>Additionally, we need to add the following two rows:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# pidfile \/var\/run\/ntpd.pid<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# leapfile \/etc\/ntp.leapseconds<\/pre>\n<p>Save and quit:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">:wq<\/pre>\n<p>Reboot the system:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# reboot<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong> Configure the firewall<\/p>\n<p>Add the following sentence to the iptable configuration file <strong>\/etc\/sysconfig\/iptables<\/strong>:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# -A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT<\/pre>\n<p>Restart the firewall.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# service iptables restart<\/pre>\n<p>At this point, NTP is fully configured. The ntpd program will continually adjust the time of your server.<\/p>\n<p>You can check the time synchronization status with the following command:<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@vps ~]# ntpstat<\/pre>\n<p>&nbsp;<\/p>\n<p>We hope you\u2019ve found this useful!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description&nbsp; It&#8217;s important to set and maintain the time on servers correctly. Wrongly configured time will cause chaos within the server environment, such as data inconsistency, data synchronization failures, and job scheduling problems. To avoid these undesirable issues, first, you need to set a reasonable time zone on your server, giving your server a relatively [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1298,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1035","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1035","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1035"}],"version-history":[{"count":2,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1035\/revisions"}],"predecessor-version":[{"id":1547,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1035\/revisions\/1547"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1298"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}