Skip to content
The Chat Archive
gemini-2.5-flash· Google LMArena Human Preference 140K

How to run https://github.com/pendulum-project/ntpd-rs as a client to retrieve a time…

  1. User

    How to run https://github.com/pendulum-project/ntpd-rs as a client to retrieve a time from NTS capable server?

  2. Assistant

    ntpd-rs is 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

    1. 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 | sh
      

      Follow the on-screen instructions. You might need to restart your terminal or run source $HOME/.cargo/env.

    2. 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-rs Code

    First, clone the ntpd-rs repository from GitHub:

    git clone https://github.com/pendulum-project/ntpd-rs.git
    cd ntpd-rs
    

    Step 2: Build ntpd-rs

    Navigate into the cloned directory and build the project. For a production-ready binary, always use the --release flag to enable optimizations.

    cargo build --release
    

    This will compile the ntpd-rs executable and place it in target/release/ntpd-rs.

    Step 3: Configure ntpd-rs as an NTS Client

    ntpd-rs uses a TOML configuration file. The repository provides an example for an NTS client.

    1. Locate the example configuration: The example file is typically named client-nts.toml within the ntpd-rs directory.

    2. Create/Edit your configuration file: You can copy client-nts.toml or create a new file, let's say my-client-config.toml, in the ntpd-rs directory.

      Here's a basic my-client-config.toml that 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.com
      • nts.ntp.se
      • nts.ntp.net.br
      • nts.google.com (Requires specific setup, often not just use_nts=true in ntpd-rs out of the box, due to custom certificates or hostname_override)

      Important Configuration Notes:

      • [client]: This section enables the client functionality.
      • set_system_time = true: This allows ntpd-rs to adjust your system clock. Be aware: Setting the system clock usually requires elevated privileges (e.g., running as root or with CAP_SYS_TIME capability). For testing, you might want to run it first without set_system_time = true to 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 tells ntpd-rs to use NTS for this server. If omitted or false, it will attempt a standard NTP connection.
      • [log]: Configure where and how verbose the logs are. info is a good starting point, debug gives more details for troubleshooting.

    Step 4: Run ntpd-rs

    Now, execute ntpd-rs specifying your configuration file:

    # From the ntpd-rs directory
    ./target/release/ntpd-rs --config my-client-config.toml -v
    
    • --config my-client-config.toml: Tells ntpd-rs to load your specific configuration file.
    • -v (or --verbose): Increases logging verbosity. This is very helpful to see what's happening. You can use -vv or -vvv for even more debug output.

    Permissions for setting system time: If set_system_time = true in your config, you'll likely need to run ntpd-rs with root privileges or appropriate capabilities.

    sudo ./target/release/ntpd-rs --config my-client-config.toml -v
    

    Security Note: Running any daemon as root is generally discouraged. For production, consider using a systemd service file with CapabilityBoundingSet=CAP_SYS_TIME or 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 = true and you ran with sufficient permissions, your system time should adjust. You can verify this using:
      date
      
      or, on Linux systems with systemd-timesyncd or similar:
      timedatectl status
      
      You might see NTP synchronized: yes and your local time updated.

    Important Considerations

    1. 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 running ntpd-rs to avoid conflicts.

      • For systemd-timesyncd: sudo systemctl stop systemd-timesyncd and sudo systemctl disable systemd-timesyncd
      • For ntpd: sudo systemctl stop ntp and sudo systemctl disable ntp
      • For chrony: sudo systemctl stop chrony and sudo systemctl disable chrony
    2. Firewall: Ensure your firewall allows outgoing connections on TCP port 10123 (NTS-KE) and UDP port 123 (NTP).

    3. Backgrounding and Systemd: For persistent operation, you should run ntpd-rs as a background service, ideally managed by systemd (on Linux). This would involve creating a .service file that starts ntpd-rs with the correct configuration and permissions.

    4. 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-rs is run with root privileges or appropriate capabilities.
      • Verbose Logging: Always start with -v or -vv to get detailed output for debugging.

    By following these steps, you should be able to successfully run ntpd-rs as an NTS client and synchronize your system time with an NTS-capable server.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.