Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Install an NTP server in GNU/Linux

Leer en espanol
Install an NTP server in GNU/Linux

Table of contents

Network Time Protocol (NTP) is a internet protocol to synchronize the clocks of the computer systems through the routing of packets in networks with latency variable. NTP uses UDP like your transport layer, using the port 123. It is designed to resist the effects of variable latency.

We install the necessary software

Redhat and derivatives

Bash
yum install ntpdate ntp

Debian and derivatives

Bash
apt-get install ntp

We make a backup of the configuration

Bash
cp /etc/ntp.conf /etc/ntp.conf-bck

We access the configuration file and comment on the servers that are configured by default and add ours.

text
#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
server 3.es.pool.ntp.org

server 0.europe.pool.ntp.org

server 2.europe.pool.ntp.org

We can also restrict the clients which can query our NTP server:

text
# Hosts on local network are less restricted.

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

We allow port 123 on the firewall 

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

We start the service

chkconfig ntpd on

We add it to the beginning

Redhat and derivatives

text
chkconfig ntpd on

Debian and derivatives

sql
update-rc.d ntp enable

We check the operation

text
ntpq -p

remote refid st t when poll reach delay offset jitter

============================================================================

ntp.redimadrid. 193.147.107.33 2 u 32 64 7 2.310 489875. 13.455

fry.celeborn.de 152.103.15.66 2 u 38 64 7 36.664 489872. 13.327

mail.grain.ru 89.109.251.21 2 u 42 64 7 102.040 489877. 20.947

All the best

:wq!

Comments