• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, May 10, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System CentOS

Setup Timezone and NTP on CentOS 6

How VPS by How VPS
October 1, 2019
in CentOS
0
0
SHARES
21
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Introduction
  2. Prerequisites
  3. Step 1: Set the timezone
  4. Step 2: Upgrade NTP
  5. Step 3: Configure ntp
  6. Step 4: Configure the firewall
  7. Want to contribute?


Introduction

For server administrators, it’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 precise local time. Second, for communication purposes, you can also use NTP (Network Time Protocol) to synchronize the time of your servers and remote NTP servers, keeping the time on your machines in perfect order.

In this article, I will show you how to set the time zone and how to synchronize the time using NTP on a CentOS 6 x64 server.

Prerequisites

I assume that you have deployed a CentOS 6 x64 Vultr server instance from scratch and have logged in as root.

Step 1: Set the timezone

Input the following command in your terminal:

date

As you see, the Vultr CentOS 6 x64 OS uses the UTC time by default. You can modify it to any time zone as you wish, but using the local timezone of the server’s physical location is a best practice.

If our server was running in China, then we would use the “Asia/Shanghai” time zone:

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

You can navigate to the directory /usr/share/zoneinfo to find the appropriate time zone. There is an excellent resource on Wikipedia for timezone listings.

Input date again, you will find that the local system time has changed to CST (China Standard Time) GMT+0800.

Next, we will write the system time info into the hardware clock.

vi /etc/sysconfig/clock

Modify the content of this file as below.

ZONE="Asia/Shanghai"
UTC=false
ARC=false

Save and quit.

:wq

Write the system time into the hardware clock.

hwclock --systohc --localtime

Input hwclock to see the result.

Step 2: Upgrade NTP

By default, the ntp daemon program has been installed and set up to run on the Vultr CentOS 6 x64 server instance. For security purposes, the first thing that we should do is to upgrade it to the latest version.

To see the ntpd version:

ntpd --version

At the time of writing, the default installed version is “4.2.6p5”.

Stop the ntpd service:

service ntpd stop

Download the latest version of the ntp program from its official website:

wget http://archive.ntp.org/ntp4/ntp-4.2/ntp-4.2.8p2.tar.gz

Unzip and go into the newly created directory:

tar -zxvf ntp-4.2.8p2.tar.gz
cd ntp-4.2.8p2

Install the necessary components for our installation:

yum -y install gcc libcap-devel

Because we are going to upgrade the existing ntpd program, we need to determine the owner and group info:

cat /etc/group
cat /etc/passwd

As you see, the ntp program belongs to the owner ntp (uid=38) and the group ntp (gid=38).

For security purposes, update the configuration of the ntp user account:

usermod -c "Network Time Protocol" -d /var/lib/ntp -u 38 -g ntp -s /bin/false ntp

Compile and install the ntp program:

./configure --prefix=/usr --bindir=/usr/sbin --sysconfdir=/etc --enable-linuxcaps --with-lineeditlibs=readline --docdir=/usr/share/doc/ntp-4.2.8p2 && make
make install && install -v -o ntp -g ntp -d /var/lib/ntp

Once the installation has completed, you can check the ntpd version again:

ntpd --version

As you see, the ntp program has been upgraded to the latest version “4.2.8p2”.

Step 3: Configure ntp

For better performance and security, we need to modify the default configuration:

vi /etc/ntp.conf

In the ntp.conf configuration file, you can find the ntp servers like:

server 1.time.constant.com
server 2.time.constant.com
server 3.time.constant.com

For faster synchronization speed, you can change these servers to the ones in the region or even in the country of your datacenter. For example, in United States, you can use:

server 0.us.pool.ntp.org
server 1.us.pool.ntp.org
server 2.us.pool.ntp.org
server 3.us.pool.ntp.org

More NTP pool time servers can be found on the NTP support website.

For security purposes, we should restrict permissions. While still in the ntp.conf configuration file, find the following two rows:

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

Modify them as below:

restrict default limited kod nomodify notrap nopeer noquery
restrict -6 default limited kod nomodify notrap nopeer noquery

Additionally, we need to add the following two rows:

pidfile   /var/run/ntpd.pid
leapfile  /etc/ntp.leapseconds

Save and quit:

:wq

Reboot the system:

reboot

Step 4: Configure the firewall

Add the following sentence to the iptable configuration file /etc/sysconfig/iptables:

-A  INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT

Restart the firewall.

service iptables restart

At this point, NTP is fully configured. The ntpd program will continually adjust the time of your server.

If needed, you can check the time synchronization status with the following command:

ntpstat

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

How to Install Crate.IO on CentOS 7

Next Post

How to Install OpenLiteSpeed and PHP 7 on CentOS 7

Next Post

How to Install OpenLiteSpeed and PHP 7 on CentOS 7

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet