NTP, also known as a “Network Time Protocol,” is an Internet time protocol used to sync computer time with network time. NTP is built on UDP and uses port 123 for communication, while NTP clients use port 1023. NTP can be installed on any operating system and uses time from an external source to maintain time within its local internal clock. Generally, NTP is required for many distributed applications where time synchronization is a must between all nodes.
In this post, we will show you how to install NTP on Arch Linux.
In This Article
Step 1 – Configure Repository
By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirrorlist configuration file:
Remove all lines and add the following lines:
## Score: 0.7, United States Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch ## Score: 0.8, United States Server = http://lug.mtu.edu/archlinux/$repo/os/$arch Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch ## Score: 0.9, United Kingdom Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch ## Score: 1.5, United Kingdom Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch ## Score: 6.6, United States Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch ## Score: 6.7, United States Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch ## Score: 6.8, United States Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch ## Score: 7.1, India Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch ## Score: 10.1, United States Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch
Save and close the file, then update all the package indexes with the following command:
Step 2 – Basic Time Commands
You can use the date command to view the data and time on your server.
You will get the following output.
Wed Jan 4 11:05:42 AM UTC 2023
As you can see, the timezone is set to UTC. To list all time zones, run the following command.
You can set the timezone to America/New_York using the following command.
timedatectl set-timezone America/New_York
You can also verify time synchronization on your server using the following command.
You should see that time synchronization is active on your server.
Local time: Wed 2023-01-04 06:07:10 EST Universal time: Wed 2023-01-04 11:07:10 UTC RTC time: Wed 2023-01-04 11:07:11 Time zone: America/New_York (EST, -0500) System clock synchronized: yes NTP service: active RTC in local TZ: no
Before installing NTP, you will need to disable time synchronization. You can disable it with the following command.
timedatectl set-ntp no
You can verify it with the following command.
Local time: Wed 2023-01-04 06:07:52 EST Universal time: Wed 2023-01-04 11:07:52 UTC RTC time: Wed 2023-01-04 11:07:53 Time zone: America/New_York (EST, -0500) System clock synchronized: yes NTP service: inactive RTC in local TZ: no
Step 3 – Install and Configure NTP
By default, the NTP package is available in the Arch Linux default repository. You can install it with the following command.
pacman -S ntp
Once NTP is installed, edit the NTP default configuration file:
Change the default NTP server pool with your nearest server.
server 0.asia.pool.ntp.org server 1.asia.pool.ntp.org server 2.asia.pool.ntp.org server 3.asia.pool.ntp.org
Save and close the file, then restart NTP to apply the changes.
systemctl restart ntpd
Now, verify time synchronization with the following command.
If everything is fine, you will get the following output.
remote refid st t when poll reach delay offset jitter ============================================================================== 22.214.171.124 ( .INIT. 16 u - 64 0 0.000 +0.000 0.000 time.firstlink. 126.96.36.199 2 u 3 64 1 268.468 -4.858 0.000 time.cloudflare 10.15.13.248 3 u 6 64 1 2.406 -0.133 0.000 ns.tu.ac.th 188.8.131.52 2 u 6 64 1 264.671 +7.973 0.000
In this post, we explained how to install an NTP server on Arch Linux. You can now install NTP in your local network to synchronize system time with internet time. You can test your NTP server on dedicated server hosting from Atlantic.Net!