How to run https://github.com/pendulum-project/ntpd-rs as a client to retrieve a time…
- User
How to run https://github.com/pendulum-project/ntpd-rs as a client to retrieve a time from NTS capable server?
- Assistant
ntpd-rsis a Rust-based Network Time Security (NTS) daemon. It can act as both an NTS server and an NTS client. To run it as a client to retrieve time from an NTS-capable server, you'll need to configure it correctly.Here's a step-by-step guide:
Prerequisites
-
Rust Toolchain: You need Rust and Cargo installed. If you don't have them, the recommended way is via
rustup:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shFollow the on-screen instructions. You might need to restart your terminal or run
source $HOME/.cargo/env. -
Git: To clone the repository.
sudo apt install git # On Debian/Ubuntu sudo yum install git # On RHEL/CentOS sudo pacman -S git # On Arch
Step 1: Get the
ntpd-rsCodeFirst, clone the
ntpd-rsrepository from GitHub:git clone https://github.com/pendulum-project/ntpd-rs.git cd ntpd-rsStep 2: Build
ntpd-rsNavigate into the cloned directory and build the project. For a production-ready binary, always use the
--releaseflag to enable optimizations.cargo build --releaseThis will compile the
ntpd-rsexecutable and place it intarget/release/ntpd-rs.Step 3: Configure
ntpd-rsas an NTS Clientntpd-rsuses a TOML configuration file. The repository provides an example for an NTS client.-
Locate the example configuration: The example file is typically named
client-nts.tomlwithin thentpd-rsdirectory. -
Create/Edit your configuration file: You can copy
client-nts.tomlor create a new file, let's saymy-client-config.toml, in thentpd-rsdirectory.Here's a basic
my-client-config.tomlthat connects to Cloudflare's NTS server:# my-client-config.toml # --- Client Configuration --- [client] enabled = true # If true, ntpd-rs will set the system clock. This usually requires root privileges. # It's recommended to run ntpd-rs as a non-root user and use a capability manager # or sudo for setting the time, or rely on other services for time synchronization. # For initial testing, you might disable this if you don't want to change system time immediately. set_system_time = true # Specify how often the client should re-synchronize (in seconds) poll_interval = 600 # Every 10 minutes # List of NTS servers to synchronize with [[client.servers]] host = "time.cloudflare.com" # A common public NTS server port = 123 # Standard NTP port nts_ke_port = 10123 # Standard NTS-KE port use_nts = true # IMPORTANT: Enable NTS for this server # You can add more servers if you wish # [[client.servers]] # host = "nts.ntp.se" # port = 123 # nts_ke_port = 10123 # use_nts = true # --- Logging Configuration (Optional but Recommended) --- [log] level = "info" # "debug", "info", "warn", "error" target = "stdout" # "stdout", "stderr", "syslog" (Unix-only)Known Public NTS-capable Servers:
time.cloudflare.comnts.ntp.sents.ntp.net.brnts.google.com(Requires specific setup, often not justuse_nts=trueinntpd-rsout of the box, due to custom certificates orhostname_override)
Important Configuration Notes:
[client]: This section enables the client functionality.set_system_time = true: This allowsntpd-rsto adjust your system clock. Be aware: Setting the system clock usually requires elevated privileges (e.g., running as root or withCAP_SYS_TIMEcapability). For testing, you might want to run it first withoutset_system_time = trueto just see the log output.[[client.servers]]: This is an array where you define each NTS server.host: The hostname or IP address of the NTS server.port: The standard NTP port (123).nts_ke_port: The NTS Key Exchange (NTS-KE) port (usually 10123).use_nts = true: Crucial! This tellsntpd-rsto use NTS for this server. If omitted orfalse, it will attempt a standard NTP connection.
[log]: Configure where and how verbose the logs are.infois a good starting point,debuggives more details for troubleshooting.
Step 4: Run
ntpd-rsNow, execute
ntpd-rsspecifying your configuration file:# From the ntpd-rs directory ./target/release/ntpd-rs --config my-client-config.toml -v--config my-client-config.toml: Tellsntpd-rsto load your specific configuration file.-v(or--verbose): Increases logging verbosity. This is very helpful to see what's happening. You can use-vvor-vvvfor even more debug output.
Permissions for setting system time: If
set_system_time = truein your config, you'll likely need to runntpd-rswith root privileges or appropriate capabilities.sudo ./target/release/ntpd-rs --config my-client-config.toml -vSecurity Note: Running any daemon as root is generally discouraged. For production, consider using a systemd service file with
CapabilityBoundingSet=CAP_SYS_TIMEor similar.Step 5: Verify Client Operation
After running, observe the output in your terminal.
- You should see messages indicating a successful NTS-KE handshake and subsequent NTP synchronization.
- Look for lines similar to:
INFO ntpd_rs::client: Initial NTS-KE handshake successful with time.cloudflare.com:10123 INFO ntpd_rs::client: Successfully synchronized with time.cloudflare.com:123, offset: ... - If
set_system_time = trueand you ran with sufficient permissions, your system time should adjust. You can verify this using:
or, on Linux systems withdatesystemd-timesyncdor similar:
You might seetimedatectl statusNTP synchronized: yesand your local time updated.
Important Considerations
-
Stop Other NTP Clients: If you have
systemd-timesyncd,ntpd,chrony, or any other NTP client already running on your system, you should stop them before runningntpd-rsto avoid conflicts.- For
systemd-timesyncd:sudo systemctl stop systemd-timesyncdandsudo systemctl disable systemd-timesyncd - For
ntpd:sudo systemctl stop ntpandsudo systemctl disable ntp - For
chrony:sudo systemctl stop chronyandsudo systemctl disable chrony
- For
-
Firewall: Ensure your firewall allows outgoing connections on TCP port
10123(NTS-KE) and UDP port123(NTP). -
Backgrounding and Systemd: For persistent operation, you should run
ntpd-rsas a background service, ideally managed bysystemd(on Linux). This would involve creating a.servicefile that startsntpd-rswith the correct configuration and permissions. -
Troubleshooting:
- "Error: Connection refused" or "TLS handshake failed": Check the server address, ports, and ensure the server is actually NTS-capable and reachable. Firewall issues are common.
- "No such file or directory": Double-check the path to your configuration file.
- "Permission denied": If trying to set system time, ensure
ntpd-rsis run with root privileges or appropriate capabilities. - Verbose Logging: Always start with
-vor-vvto get detailed output for debugging.
By following these steps, you should be able to successfully run
ntpd-rsas an NTS client and synchronize your system time with an NTS-capable server. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.