---
title: Quick start
description: 'Two NixOS hosts joined into one mesh: keys, trust document, config and service.'
url: https://ranet3.com/docs/quick-start/
updated: "2026-12-02"
root: https://ranet3.com/llms.txt
---

# Quick start

> This page may contain unreviewed machine generated text. Use with care.

Two NixOS hosts joined into one mesh: keys, trust document, config and service.

This page joins 2 NixOS hosts into one mesh. Host A runs the node
`example/alpha` at `192.0.2.1`, and host B runs `example/bravo` at `192.0.2.2`.
Each dials and answers the other on UDP port 13000, holds an address of
`203.0.113.0/24` on its tun and announces it.
[Running it as a service](https://ranet3.com/docs/service/index.md) lists the module's options, and
[the configuration reference](https://ranet3.com/docs/configuration-reference/index.md) every key.

Use the [host flake](https://ranet3.com/docs/service/index.md#the-hosts-flake) on each host, with flakes
enabled as that section describes. Obtain the binary on each host and on a
separate signing machine as [getting started](https://ranet3.com/docs/getting-started/index.md) describes.

## Keys

Each host makes its own Ed25519 key and prints its public half as padded base64
DER SubjectPublicKeyInfo:

```sh
sudo install -d -m 0700 /var/lib/ranet3
sudo openssl genpkey -algorithm ed25519 -out /var/lib/ranet3/key.pem
sudo chmod 0600 /var/lib/ranet3/key.pem
sudo openssl pkey -in /var/lib/ranet3/key.pem -pubout -outform DER | openssl base64 -A
```

Keep each private key on its own host. The document gives each device a separate
node record and public key, as [key files](https://ranet3.com/docs/trust/index.md#key-files) describes.

On the signing machine, generate a separate authority key once:

```sh
ranet3 key generate --type ed25519 --out authority.pem
```

Save the public key printed by this command for both hosts' `auth.authority`.
Keep `authority.pem` private on the signing machine, outside the Nix store.
Neither host needs the authority private key.

## Trust document

On the signing machine, write `document.json` with the following structure.
Replace `ALPHA_PUBLIC_KEY` and `BRAVO_PUBLIC_KEY` with the public keys printed
on their respective hosts. Replace the example endpoint addresses with the
addresses the hosts can dial:

```json
{
  "nodes": [
    {
      "endpoints": [
        {
          "address": "192.0.2.1",
          "family": "ip4",
          "id": "0",
          "port": 13000
        }
      ],
      "key": "ALPHA_PUBLIC_KEY",
      "name": "example/alpha"
    },
    {
      "endpoints": [
        {
          "address": "192.0.2.2",
          "family": "ip4",
          "id": "0",
          "port": 13000
        }
      ],
      "key": "BRAVO_PUBLIC_KEY",
      "name": "example/bravo"
    }
  ]
}
```

Canonicalize it to the member order the signer requires, without whitespace or a
trailing newline, then sign it once:

```sh
jq -c -j -S . document.json > document.canonical.json
ranet3 trust init document.canonical.json --key authority.pem --out trust.cose
```

The output path must not exist. Replace `AUTHORITY_PUBLIC_KEY` below with the
public key printed by `key generate`, then verify the signed file:

```sh
ranet3 trust verify trust.cose --authority AUTHORITY_PUBLIC_KEY
```

Copy this same `trust.cose` to `/var/lib/ranet3/trust.cose` on both hosts. The
daemon reads the signed file, not either authored JSON file. Do not run
`trust init` separately for each host, since each invocation creates a new mesh
identifier. Use [successor signing](https://ranet3.com/docs/cli/index.md#signed-trust-commands) when changing
membership.

Each endpoint carries the address the other host dials, and a `port` equal to
the node's own `link.port`, which the daemon does not check, as
[endpoint](https://ranet3.com/docs/trust/index.md#endpoint) says.

## Config and service

Host A imports the module and writes its settings:

```nix
{
  imports = [ inputs.ranet3.nixosModules.ranet3 ];

  networking.ranet3 = {
    enable = true;
    openFirewall = true;
    settings = {
      node = "example/alpha";
      overlay = [ "203.0.113.0/24" ];
      auth = {
        key = "/var/lib/ranet3/key.pem";
        trust = "/var/lib/ranet3/trust.cose";
        authority = [ "AUTHORITY_PUBLIC_KEY" ];
      };
      link = {
        port = 13000;
        endpoints = [
          {
            serial = "0";
            family = "ip4";
          }
        ];
        listen = true;
      };
      dial.all = true;
      cap = {
        table.addresses = [ "203.0.113.1/32" ];
        route.announce = [ "203.0.113.1/32" ];
      };
    };
  };
}
```

Replace `AUTHORITY_PUBLIC_KEY` with the signing authority's public key on both
hosts. Host B writes the same settings with `example/bravo` as `node` and
`203.0.113.2/32` in both address lists.

- `inputs.ranet3` is `github:ranet3/ranet3` as an input of the host's own flake,
  which [the host's flake](https://ranet3.com/docs/service/index.md#the-hosts-flake) binds.
- `dial.all` dials every other node the trust document names, and `link.listen`
  answers the other host's dial, so each host dials and answers.
- `openFirewall` lets UDP 13000 in through `networking.firewall`.
- `cap.table.addresses` puts the node's address on its tun, and
  `cap.route.announce` announces it. Without the announcement the session still
  forms and carries nothing to that address, as
  [getting started](https://ranet3.com/docs/getting-started/index.md#running) gives.
- `overlay` names the prefix the mesh numbers its nodes from, as
  [configuration](https://ranet3.com/docs/configuration/index.md#structure) describes.

In the [host flake](https://ranet3.com/docs/service/index.md#the-hosts-flake), name the configuration
`nixosConfigurations.alpha` on host A and `nixosConfigurations.bravo` on host B
instead of `nixosConfigurations.gateway`. Host A runs the first line to switch,
and host B the second:

```sh
sudo nixos-rebuild switch --flake /etc/nixos#alpha
sudo nixos-rebuild switch --flake /etc/nixos#bravo
```

A daemon that starts before its private key or signed file exists waits for
them, as [restarts and the network](https://ranet3.com/docs/service/index.md#restarts-and-the-network)
describes. It verifies the snapshot and saves it in its own state directory as
`trust.store`. Keep that store across restarts, and do not copy it between
hosts. [Trust order](https://ranet3.com/docs/trust/index.md#order-and-refusals) describes selection and
refusals.

## Checking it

On either host:

```sh
sudo ranet3 status
sudo ranet3 sessions
sudo ranet3 routes
```

`status` reports the held snapshot, initially at height 1. `sessions` lists a
session with the other node, and `routes` lists the other node's address once
its announcement arrives. [Command line](https://ranet3.com/docs/cli/index.md#reading-state) lists the other
views.

To carry the LANs behind the 2 hosts, follow
[a site behind each node](https://ranet3.com/docs/sites/index.md).
