Of course! Running ntpd-rs as a client with Network Time Security (NTS) is one of its primary features. NTS provides cryptographic security for NTP, preventing spoofing and man-in-the-middle attacks.
Here is a step-by-step guide on how to install, configure, and run ntpd-rs as an NTS client.
Summary of Steps
- Install
ntpd-rs: Either by building from source or using a package manager.
- Create a Configuration File: Specify the NTS-capable servers you want to use.
- Run the Daemon: Start the
ntpd-rs service.
- Verify the Connection: Check the logs and use
ntp-ctl to confirm it's using NTS.
Step 1: Install ntpd-rs
You have two main options for installation.
Option A: Install via Package Manager (Recommended & Easiest)
Many modern Linux distributions now include ntpd-rs in their repositories.
Installing this way will usually set up the systemd service file and a default configuration directory for you.
Option B: Build from Source
If your distribution doesn't have a package or you want the latest version, you can build it from source.
- Install Rust Toolchain: If you don't have it, install
rustup.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
- Install Build Dependencies: You'll need a C compiler and
pkg-config.
# On Debian/Ubuntu
sudo apt install build-essential pkg-config
# On Fedora/CentOS
sudo dnf install gcc make pkg-config
- Clone and Build
ntpd-rs:
git clone https://github.com/pendulum-project/ntpd-rs.git
cd ntpd-rs
cargo build --release
The compiled binaries will be in target/release/. The main ones are ntpd-rs (the daemon) and ntp-ctl (the control utility). You would then need to copy these to a system path like /usr/local/bin/.
Step 2: Configure the Client
ntpd-rs uses a TOML configuration file. The default location is /etc/ntpd-rs/ntpd.toml. If you installed from a package manager, this file might already exist. If not, create the directory and the file.
sudo mkdir -p /etc/ntpd-rs
sudo nano /etc/ntpd-rs/ntpd.toml
Here is a minimal configuration for an NTS client. Paste this into the file:
# /etc/ntpd-rs/ntpd.toml
# Specify which network interfaces to listen on for monitoring tools.
# "localhost" is a safe default.
listen_on = ["localhost"]
# --- Server Section ---
# This is where you define the time servers to connect to.
# For NTS, you must specify the NTS-KE port (TCP/4460).
[[server]]
# Cloudflare's public NTS service.
# The ":4460" is crucial for the NTS Key Establishment (NTS-KE) protocol.
address = "time.cloudflare.com:4460"
nts = "required" # Enforce the use of NTS for this server.
[[server]]
# Netnod's public NTS service (Sweden).
address = "ntp.se:4460"
nts = "required"
[[server]]
# A server from the NTPool project that supports NTS.
# The pool will automatically resolve to an NTS-enabled server.
address = "ntp.pool.org:4460"
nts = "required"
Key Points about the Configuration:
[[server]]: Each block defines one server pool.
address = "...": This is the hostname or IP address of the server. Crucially for NTS, you must specify the NTS Key Establishment port, which is 4460. The actual time synchronization will happen over NTP's standard UDP port 123, but the initial secure handshake uses TCP/4460.
nts = "required": This tells ntpd-rs that it must successfully complete an NTS handshake with this server before using it for time synchronization. If the handshake fails, the server will be ignored.
Step 3: Run ntpd-rs
Before running ntpd-rs as a system service, it's a good idea to disable any other NTP daemons to avoid conflicts.
# Example for disabling chrony or systemd-timesyncd
sudo systemctl stop chronyd
sudo systemctl disable chronyd
sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd
Now, start and enable the ntpd-rs service.
sudo systemctl start ntpd-rs
sudo systemctl enable ntpd-rs # To make it start on boot
Step 4: Verify It's Working
There are two main ways to check if ntpd-rs is running correctly and using NTS.
1. Check the System Logs
Use journalctl to view the logs. The -f flag will follow the log in real-time.
sudo journalctl -u ntpd-rs -f
Look for lines indicating a successful NTS handshake. You should see messages like:
NTS-KE handshake successful with...
Associated with time.cloudflare.com
Time stepped by ... ms or Adjusting clock frequency...
2. Use the ntp-ctl Utility
This is the best way to see the status of your peer connections.
ntp-ctl peers
The output will look something like this:
Remote St T When Poll Reach Delay Offset Jitter
==================================================================================================
~time.cloudflare.com 16 u - 64 0 0.000 0.000 0.000
~ntp.se 16 u - 64 0 0.000 0.000 0.000
~ntp.pool.org 16 u - 64 0 0.000 0.000 0.000
The most important indicator is the tilde ~ at the beginning of the remote host's name.
~ (Tilde): Indicates a successful NTS-authenticated peer. This confirms you are using NTS!
* (Asterisk): Indicates the "syspeer" that the clock is currently synchronized to.
+ (Plus): Indicates a "candidate" peer, a good server that could be used for synchronization.
After a few minutes, the output should update to show real delay, offset, and jitter values, and one of the peers will be marked with a *.
Remote St T When Poll Reach Delay Offset Jitter
==================================================================================================
*~time.cloudflare.com 1 u 23 64 377 15.431 -0.123 0.543
+~ntp.se 1 u 25 64 377 28.987 0.056 0.811
This output confirms you are synchronized to time.cloudflare.com via a secure NTS connection.
Troubleshooting
- Firewall Issues: Ensure your firewall allows outbound TCP traffic on port 4460. This is required for the initial NTS handshake. It also needs to allow outbound and inbound UDP traffic on port 123 for the actual NTP communication.
- Service Fails to Start: Check
journalctl -u ntpd-rs for error messages. Most often, this is due to a syntax error in your /etc/ntpd-rs/ntpd.toml file or a conflict with another NTP service.
- No Peers Appear or Reach is 0: This usually points to a network or firewall issue. Use
ping and traceroute to check basic connectivity to the servers. Double-check the firewall rules for ports 4460/tcp and 123/udp.