Skip to content

Docs

Run your own relay

Last updated

Set up a relay on your own server so your devices can sync across networks without a VPN, and without n0's public relays.

What a relay is for

Devices on the same network, or on a VPN like Tailscale, reach each other directly. Devices on different networks usually can't, because routers block connections from outside. A relay is a server both can reach: it introduces them so they can connect directly, and passes their traffic along when they can't.

Relays are off unless you turn one on. Public relays uses n0's servers; My own relay uses one you run, so nobody else sees which of your devices connect, or when.

What your relay sees. Everything your devices send each other is end-to-end encrypted, so the relay can't read it. It sees each device's IP address and Node ID, and when they connect. Only pairing and sync go through the peer network, never your SSH sessions or file transfers, so a small server is plenty.

Before you start

  • A server all your devices can reach: a small VPS, or a home server with a port forward.
  • A domain name pointing at it, such as relay.example.com.
  • Docker with Compose on the server.

TerminalLynx runs n0's standard relay server, iroh-relay, from its official Docker image. There's nothing TerminalLynx-specific to install: the files below are a tested setup for it.

The certificate must be a public one, such as Let's Encrypt. TerminalLynx trusts the same certificate authorities as Firefox, not your operating system's store, so self-signed and company-internal certificates won't work. On a company network Let's Encrypt can't reach, see On-prem and firewalled networks.

Choose a setup

Behind a reverse proxyStandalone
Use it whenYou already run Caddy, Nginx or Traefik on port 443Nothing else on the server uses ports 80 and 443
CertificateYour proxy'sThe relay gets its own from Let's Encrypt
Ports to openNone besides your proxy's80/tcp, 443/tcp and 7842/udp
Direct connectionsUsualMore often: it tells devices their public address, which helps behind stricter routers

Both work. Devices that can't connect directly send their traffic through the relay, so the standalone setup only changes how often that's needed.

Behind a reverse proxy

  1. On the server, make a folder for the relay and fetch the two files into it:
    curl -O https://terminallynx.com/relay/behind-proxy/docker-compose.yml
    curl -O https://terminallynx.com/relay/behind-proxy/relay.toml
  2. Start it with docker compose up -d. The relay listens on 127.0.0.1:3340, for your proxy only.
  3. Point an HTTPS site at it, with your hostname in place of relay.example.com. Caddy needs three lines; Nginx needs the WebSocket headers and long timeouts shown, because each device keeps a connection open to the relay. For Traefik, use the labels in docker-compose.yml instead.
  4. Check it: curl https://relay.example.com/ping should answer with status 200.
docker-compose.ymlDownload
# A TerminalLynx relay behind your own reverse proxy.
# Guide: https://terminallynx.com/docs/own-relay
#
#   docker compose up -d
#
# The relay listens on 127.0.0.1:3340 only. Point your proxy's HTTPS site (Caddyfile, nginx.conf or the Traefik labels
# below) at it, then choose "My own relay" in TerminalLynx and enter https://relay.example.com.
services:
  relay:
    # Keep this on the iroh version TerminalLynx uses (1.3 for TerminalLynx 1.3).
    image: n0computer/iroh-relay:v1.3.0
    restart: unless-stopped
    command: ["--config-path", "/config/relay.toml"]
    environment:
      # Without this the relay logs nothing, not even certificate errors. See them with: docker compose logs -f
      - RUST_LOG=info
    volumes:
      - ./relay.toml:/config/relay.toml:ro
    ports:
      # Remove this line if your proxy runs in Docker on the same network (Traefik below, or Caddy/Nginx in a container
      # pointing at http://relay:3340).
      - "127.0.0.1:3340:3340"
    # Traefik users: uncomment, set your hostname and entrypoint/resolver names, and put this service on Traefik's
    # network. Traefik passes WebSocket upgrades through with no extra settings.
    # labels:
    #   - traefik.enable=true
    #   - traefik.http.routers.tlx-relay.rule=Host(`relay.example.com`)
    #   - traefik.http.routers.tlx-relay.entrypoints=websecure
    #   - traefik.http.routers.tlx-relay.tls.certresolver=letsencrypt
    #   - traefik.http.services.tlx-relay.loadbalancer.server.port=3340
relay.tomlDownload
# iroh-relay config for running behind a reverse proxy (Caddy, Nginx or Traefik) that handles HTTPS.
# Guide: https://terminallynx.com/docs/own-relay
# Checked against iroh-relay 1.3.0, the version TerminalLynx 1.3 is built with.

# Plain HTTP: there's no [tls] section, so the proxy must terminate HTTPS. (iroh-relay has no enable_tls setting;
# TLS is on exactly when a [tls] section is present.)
# IPv4 inside the container: Docker networks often have IPv6 turned off, and binding "[::]" then fails ("Address
# family not supported"). The proxy reaches the relay over IPv4 either way.
http_bind_addr = "0.0.0.0:3340"

# QUIC address discovery needs the relay's own TLS certificate, which a proxy setup doesn't have. Devices still find
# each other and hole-punch without it; see standalone/ for a relay that offers it.
enable_quic_addr_discovery = false

# Optional: only let your own devices use this relay. List the Node ID of every device that should use it, yours and
# your teammates' (each device has its own: Network & peers shows it, with a copy button). Others are refused.
# Keep this line above the [sections] below, or TOML files it under the section and the relay ignores it.
# access.allowlist = ["<node id of device 1>", "<node id of device 2>"]

# Prometheus metrics, on the container's port 9090. docker-compose.yml doesn't publish it.
enable_metrics = true
metrics_bind_addr = "0.0.0.0:9090"

# A cap on new connections per second, so a scanner can't flood the relay. Each TerminalLynx device keeps one
# connection open, so these are far above what a home or a team needs.
[limits]
accept_conn_limit = 50.0
accept_conn_burst = 100
CaddyfileDownload
# Caddy gets the certificate and passes WebSocket upgrades through on its own. Replace the hostname with yours.
relay.example.com {
	reverse_proxy 127.0.0.1:3340
}
nginx.confDownload
# Nginx site for the relay. Replace the hostname and certificate paths with yours (certbot's paths shown).
# Leave HTTP/2 off for this site (no "http2" on the listen lines): the relay's WebSocket needs HTTP/1.1.
# Devices hold one WebSocket open to the relay at /relay, so the upgrade headers and long timeouts matter.

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name relay.example.com;

    ssl_certificate     /etc/letsencrypt/live/relay.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/relay.example.com/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:3340;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_buffering off;
        proxy_read_timeout 1h;
        proxy_send_timeout 1h;
    }
}

On a private network or VPN only? You can skip the proxy and the domain: see plain HTTP on the internal network.

Standalone

  1. Point the domain at the server, and open 80/tcp, 443/tcp and 7842/udp in its firewall.
  2. Make a folder for the relay and fetch the two files into it:
    curl -O https://terminallynx.com/relay/standalone/docker-compose.yml
    curl -O https://terminallynx.com/relay/standalone/relay.toml
  3. In relay.toml, set hostname to your domain and contact to an email address for Let's Encrypt.
  4. Start it with docker compose up -d. It asks Let's Encrypt for a certificate the first time; watch with docker compose logs -f.
  5. Check it: curl https://relay.example.com/ping should answer with status 200.

It uses host networking so the relay sees devices' real addresses, which needs Docker on Linux rather than Docker Desktop. While you try things out, prod_tls = false uses Let's Encrypt's staging server, which won't lock you out after a few failed attempts. TerminalLynx doesn't trust staging certificates, so set it back totrue once the relay starts cleanly.

docker-compose.ymlDownload
# A TerminalLynx relay on a server of its own, with its own Let's Encrypt certificate.
# Guide: https://terminallynx.com/docs/own-relay
#
#   docker compose up -d
#
# Then choose "My own relay" in TerminalLynx and enter https://relay.example.com (the hostname in relay.toml).
services:
  relay:
    # Keep this on the iroh version TerminalLynx uses (1.3 for TerminalLynx 1.3).
    image: n0computer/iroh-relay:v1.3.0
    restart: unless-stopped
    command: ["--config-path", "/config/relay.toml"]
    environment:
      # Without this the relay logs nothing, not even certificate errors. See them with: docker compose logs -f
      - RUST_LOG=info
    # Host networking, so QUIC address discovery sees devices' real addresses and ports rather than Docker's.
    # Docker Desktop on macOS and Windows doesn't support it; run this on a Linux server.
    network_mode: host
    volumes:
      - ./relay.toml:/config/relay.toml:ro
      - certs:/data/certs

volumes:
  certs:
relay.tomlDownload
# iroh-relay config for a server of its own, with no reverse proxy: the relay gets its own Let's Encrypt certificate
# and offers QUIC address discovery. Checked against iroh-relay 1.3.0.
# Guide: https://terminallynx.com/docs/own-relay
#
# Needs 80/tcp (certificate challenge), 443/tcp (the relay) and 7842/udp (QUIC address discovery) free and open.
# Replace the hostname and contact below.

# "[::]" listens on IPv4 and IPv6. If the relay won't start with "Address family not supported", the server has IPv6
# turned off: change "[::]" to "0.0.0.0" here and in [tls].
http_bind_addr = "[::]:80"

# Tells devices which public address and port their UDP traffic comes from, which helps them connect directly
# through harder NATs. Needs the [tls] section.
enable_quic_addr_discovery = true

# Optional: only let your own devices use this relay. List the Node ID of every device that should use it, yours and
# your teammates' (each device has its own: Network & peers shows it, with a copy button). Others are refused.
# Keep this line above the [sections] below, or TOML files it under the section and the relay ignores it.
# access.allowlist = ["<node id of device 1>", "<node id of device 2>"]

# Metrics on localhost only. Reach them over SSH, or remove these two lines to turn them off.
enable_metrics = true
metrics_bind_addr = "127.0.0.1:9090"

[tls]
https_bind_addr = "[::]:443"
quic_bind_addr = "[::]:7842"
cert_mode = "LetsEncrypt"
hostname = "relay.example.com"
contact = "admin@example.com"
# Certificates are kept here (a volume in docker-compose.yml) so a restart doesn't request new ones.
cert_dir = "/data/certs"
# Let's Encrypt's production server. Set to false while trying things out: staging certificates aren't trusted by
# TerminalLynx, but they show the setup works without using up Let's Encrypt's rate limits.
prod_tls = true

[limits]
accept_conn_limit = 50.0
accept_conn_burst = 100

On-prem and firewalled networks

Let's Encrypt usually checks that you own a domain by connecting to your server from the internet, which a firewalled company network doesn't allow. TerminalLynx doesn't accept certificates from a company's own certificate authority yet, so there are two ways to run a relay there.

Option 1: plain HTTP on the internal network

No domain and no certificate. Use the files from Behind a reverse proxy, without a proxy:

  1. In docker-compose.yml, change the ports line to the server's internal address, such as "10.0.5.20:3340:3340".
  2. Start it with docker compose up -d, and check it from a device: curl http://10.0.5.20:3340/ping should answer with status 200.
  3. In TerminalLynx, use http://10.0.5.20:3340 as the relay's URL. A hostname from internal DNS works too.

HTTPS would add less than it seems here. Devices encrypt everything they send each other with their own keys, and check each other's Node IDs, so neither the relay nor anyone on the network can read or change your data either way. Without HTTPS, someone on the network path could see which devices use the relay, and block it. Add the allowlist so other machines on the network can't use it.

Many security policies require TLS for every service, whatever it carries. If yours does, use option 2.

Option 2: a public certificate through Let's Encrypt's DNS check

Let's Encrypt can check a domain through DNS instead: the certificate tool adds a temporary record at your DNS provider, and nothing connects to your server. You need:

  • A domain on public DNS that you control, such as relay.corp.example.com. It can point to an internal address, or exist only in your internal DNS: Let's Encrypt only looks at the temporary record.
  • API access to that DNS provider: Cloudflare, Route 53, Azure DNS and most others work.
  • Outbound HTTPS from the machine that gets the certificate, to Let's Encrypt and the DNS provider's API.

With Caddy, Caddy gets and renews the certificate itself. It needs a Caddy build with your provider's DNS module: pick it on caddyserver.com/download, or build with xcaddy build --with github.com/caddy-dns/cloudflare. Then use this Caddyfile with the reverse proxy setup:

relay.corp.example.com {
	tls {
		dns cloudflare {env.CLOUDFLARE_API_TOKEN}
	}
	reverse_proxy 127.0.0.1:3340
}

Without a proxy, get the certificate with certbot's DNS plugin for your provider, then run the relay with it:

  1. Get the certificate:
    certbot certonly --dns-cloudflare --dns-cloudflare-credentials ~/.secrets/cloudflare.ini -d relay.corp.example.com
  2. Make a folder for the relay and fetch the two files into it:
    curl -O https://terminallynx.com/relay/own-cert/docker-compose.yml
    curl -O https://terminallynx.com/relay/own-cert/relay.toml
  3. In relay.toml, change relay.example.com in the two certificate paths to your hostname.
  4. Start it with docker compose up -d. Devices need to reach 443/tcp, and 7842/udp for direct connections.
  5. Check it: curl https://relay.corp.example.com/ping should answer with status 200.

certbot renews the certificate a month before it expires, and the relay reads it again once a day, so renewals need nothing from you.

docker-compose.ymlDownload
# A TerminalLynx relay with a certificate you get yourself, such as through Let's Encrypt's DNS check.
# Guide: https://terminallynx.com/docs/own-relay#on-prem
#
#   docker compose up -d
#
# Then choose "My own relay" in TerminalLynx and enter https://relay.example.com (your certificate's hostname).
services:
  relay:
    # Keep this on the iroh version TerminalLynx uses (1.3 for TerminalLynx 1.3).
    image: n0computer/iroh-relay:v1.3.0
    restart: unless-stopped
    command: ["--config-path", "/config/relay.toml"]
    environment:
      # Without this the relay logs nothing, not even certificate errors. See them with: docker compose logs -f
      - RUST_LOG=info
    # Host networking, so QUIC address discovery sees devices' real addresses and ports rather than Docker's.
    # Docker Desktop on macOS and Windows doesn't support it; run this on a Linux server.
    network_mode: host
    volumes:
      - ./relay.toml:/config/relay.toml:ro
      # certbot's folder, whole: the files under live/ are links into archive/. If your certificate is elsewhere,
      # mount its folder instead and change the paths in relay.toml.
      - /etc/letsencrypt:/etc/letsencrypt:ro
relay.tomlDownload
# iroh-relay config for a relay with a certificate you get yourself, for networks Let's Encrypt can't reach in:
# Let's Encrypt's DNS check (certbot, acme.sh), or a certificate bought from a public authority.
# Guide: https://terminallynx.com/docs/own-relay#on-prem
# Checked against iroh-relay 1.3.0.
#
# Needs 443/tcp (the relay) and 7842/udp (QUIC address discovery) reachable from your devices.
# The certificate must be from a public authority: TerminalLynx doesn't trust company-internal ones.

# "[::]" listens on IPv4 and IPv6. If the relay won't start with "Address family not supported", the server has IPv6
# turned off: change "[::]" to "0.0.0.0" here and in [tls].
# With TLS on, this port only answers network probes; change it if something else uses port 80.
http_bind_addr = "[::]:80"

# Tells devices which public address and port their UDP traffic comes from, which helps them connect directly
# through harder NATs. Needs the [tls] section.
enable_quic_addr_discovery = true

# Optional: only let your own devices use this relay. List the Node ID of every device that should use it, yours and
# your teammates' (each device has its own: Network & peers shows it, with a copy button). Others are refused.
# Keep this line above the [sections] below, or TOML files it under the section and the relay ignores it.
# access.allowlist = ["<node id of device 1>", "<node id of device 2>"]

# Metrics on localhost only. Reach them over SSH, or remove these two lines to turn them off.
enable_metrics = true
metrics_bind_addr = "127.0.0.1:9090"

[tls]
https_bind_addr = "[::]:443"
quic_bind_addr = "[::]:7842"
# Reads the certificate and key below, and reads them again once a day, so a renewed certificate is picked up
# without a restart.
cert_mode = "Reloading"
# PEM files: the certificate with its chain, and its private key. These are certbot's paths, as docker-compose.yml
# mounts them; replace relay.example.com with your hostname.
manual_cert_path = "/etc/letsencrypt/live/relay.example.com/fullchain.pem"
manual_key_path = "/etc/letsencrypt/live/relay.example.com/privkey.pem"

[limits]
accept_conn_limit = 50.0
accept_conn_burst = 100

If the relay's server has no internet access at all, get the certificate on a machine that does, and copy fullchain.pem and privkey.pem over before it expires: every 60 days or so for Let's Encrypt. A certificate bought from a public authority such as DigiCert or Sectigo works the same way and lasts longer. Put the files where relay.toml points, or change the paths.

Either way, devices must use the certificate's hostname in the relay's URL, such as https://relay.corp.example.com, not the server's IP address.

Use it in TerminalLynx

  1. In the sidebar, under Manage, open Network & peers…
  2. Set Relay to My own relay, enter https://relay.example.com, and save.
  3. Do the same on each of your devices, and on your teammates' if you share a team. The Relay row shows Connected once a device reaches it.

Devices still connect directly on the same network or over a VPN, and keep syncing that way if the relay is down.

Keep strangers off it

Anyone who knows the URL can use a relay. They can't read or change your data, but they can use your bandwidth. To let in only your own devices, list their Node IDs near the top of relay.toml:

access.allowlist = ["<node id of device 1>", "<node id of device 2>"]
  • Each device has its own Node ID, shown under This device in Network & peers with a copy button. List every device that should use the relay, teammates' included, and add new ones as they join.
  • Keep the line above [limits] and [tls]. Below them, it becomes part of that section and the relay ignores it without a warning.
  • Run docker compose restart after changing it.

A device that isn't listed shows Can't be reached, and that the relay refused it.

Updating

Keep the relay on the iroh version your TerminalLynx is built with: v1.3.x for TerminalLynx 1.3. To update, change the image: line in docker-compose.yml and rundocker compose up -d.

Troubleshooting

When a device can't use the relay, its Relay row in Network & peers shows Can't be reached with the reason, and it tries again every 30 seconds.

  • "Can't reach the relay", with a connection or name error, or no answer within 10 seconds: check the URL, the DNS record and the firewall, and that curl https://relay.example.com/ping works from that device's network.
  • "Can't reach the relay" with a certificate error: the certificate isn't from a public authority, or it's from Let's Encrypt's staging server.
  • "Answered, but not as a relay": the URL reaches a web server, but not the relay behind it. Check that your proxy points at 127.0.0.1:3340 and that the relay is running: docker compose ps.
  • "The relay refused this device": the relay has an allowlist and this device's Node ID isn't on it.
  • The relay won't start, with "Address family not supported": the server has IPv6 turned off. Change [::] to 0.0.0.0 in relay.toml.

The relay logs what it's doing: docker compose logs -f.