Setup NTP on CentOS 7

Tech
No Comments

What’s NTP?

NTP (Network Time Protocol) is used to ensure that the clock on your computer is correct.  With newer, very time critical features, such as 2FA, this is important.  Don’t worry though, it’s very easy to synchronise the time on your server, you just need to setup NTP.

If you need a server to try this out on, we recommend our friends at Linode.

How do I setup NTP?

Firstly, you’ll need to ensure your server is set to your local timezone.  Follow this guide.

Now, install the NTP service – this is available in the standard CentOS repositories

[user@server] sudo yum -y install ntp

This will create the configuration file at /etc/ntp.conf

Use your favorite editor to check this, I always use nano.

[user@server] sudo nano /etc/ntp.conf

You need to check that there are some NTP servers from the NTP pool available (not commented out), and that your server is restricted to localhost.  Look for the following lines:

restrict 127.0.0.1
restrict ::1
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

Ctrl+o to save and ctrl+x to exit

Now, we need to set NTP to run on startup

[user@server] sudo chkconfig ntpd on

And finally, start the service.

[user@server] sudo service ntpd start

Running ‘ps -faux | grep ntp’ should now show that NTP is running and keeping your clock extremely precise for you.

Next, you can verify which servers your clock is syncronising with using:

[user@server] ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*lond-web-1.spee 87.242.168.84    2 u   53   64    7    1.523    0.636   0.377
 y.ns.gin.ntt.ne 249.224.99.213   2 u   56   64    7    0.658   -0.312   0.342
 time.videxio.ne 131.188.3.223    2 u   50   64    7    1.624    0.197   0.315
 x.ns.gin.ntt.ne 249.224.99.213   2 u   52   64    7    0.701    0.614   0.397

 

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.

Menu