flextunnelguides

Configuration and routing

The commands, flags and config keys of the flextunnel CLI, how a request picks its server, and when connections open and close. New to it? Start with Get started with the CLI. The design is in the architecture notes.

Commands

CommandDoes
server startRun a server.
client startRun a client: its proxy listeners, destinations and port forwards.
client controlAttach the read-only terminal control panel to a running client.
client ncRelay stdin and stdout through a running client to a host:port (for ssh's ProxyCommand).
client helpShow the client subcommands and their help.
generate-iroh-key [-o FILE] [--force] [--json]Generate a server identity key, to stdout without -o. --force overwrites an existing file.
show-iroh-id --secret-file FILE [--json]Print the endpoint ID of a key. -c or --default-config reads secret_file from a server config instead.

Client auth keys come from the separate flexaccess-keys command (generate-auth-key, show-auth-key).

server start

FlagMeaning
-c, --config FILELoad settings from a TOML file; flags override it.
--default-configLoad ~/.config/flextunnel/server.toml.
--secret-file FILEThe server's identity key.
--authorized-keys-file FILEThe authorized client public keys, one ed25519-pub:… per line.
--relay-url URL (repeatable), --relay-auth-token TOKEN, --relay-quic-addr-discovery BOOLCustom relays, as the relay_* keys. See Relays.
--quickAn ephemeral one-off server for a single client. See A quick throwaway tunnel.

One server runs per identity key: servers with different keys run side by side, while a second start of the same key is refused.

client start

FlagMeaning
-c, --config FILELoad settings from a TOML file; flags override it. Without it, ~/.config/flextunnel/client.toml is used if it exists.
--socks-port PORTRun the SOCKS5 listener on 127.0.0.1:PORT. Off unless set.
--http-port PORTRun the HTTP proxy listener on 127.0.0.1:PORT. Off unless set.
--auth-key SECRET / --auth-key-file FILEThe client key, inline or as a file, for every destination that names no key file of its own.
--relay-url URL (repeatable), --relay-auth-token TOKEN, --relay-quic-addr-discovery BOOLCustom relays for every destination that names none of its own. See Relays.
--idle-timeout SECSHow long an unused connection is kept (default 300; 0 never closes it).
--quickAn ephemeral session, paired with server start --quick. See A quick throwaway tunnel.

Destinations exist only in the config, so client start always runs off one (except with --quick). With neither a SOCKS5 nor an HTTP port, the client serves only its port forwards, client nc and the control panel.

Running more than one client

One client reaches every server you configure, so one is usually enough. To run a second, give its config a different name and different ports.

client control and client nc

Both find a running client by the name in ~/.config/flextunnel/client.toml (or default), by the name in another config with -c FILE, or directly with -n NAME. client control is the control panel.

flextunnel client nc HOST PORT                # the client from ~/.config/flextunnel/client.toml
flextunnel client nc -c work.toml HOST PORT   # the client started from a specific config
flextunnel client nc -n work HOST PORT        # or by the client's name

client nc opens one tunnel to HOST:PORT and relays it to stdin and stdout. The host is routed like a port forward, and it works with no proxy port configured. For the ssh setup, see ssh through the tunnel.

Configuration files

flextunnel server start -c server.toml
flextunnel server start --default-config     # ~/.config/flextunnel/server.toml
flextunnel client start -c client.toml
flextunnel client start --socks-port 1080    # loads ~/.config/flextunnel/client.toml

A flag overrides the file, and a list given as a flag replaces the file's list. Unknown keys are rejected, and paths take ~. Destinations, forwards, routed lists and host aliases are config-file only. Annotated examples: client.toml.example and server.toml.example.

client.toml

client.toml
socks_port    = 1080
auth_key_file = "~/.config/flextunnel/client.key"

[[destinations]]
name           = "office"
server_node_id = "SERVER_ENDPOINT_ID"
routed_domains = ["*.corp.example"]
routed_cidrs   = ["10.0.0.0/8"]

[[destinations]]
name           = "nas"
server_node_id = "NAS_ENDPOINT_ID"

[[forwards]]
label       = "db"
local_port  = 5432
remote_host = "db.corp.example"
remote_port = 5432

Top-level keys

KeyType, defaultMeaning
namestring, "default"This client's instance name, used by client control and client nc to find it.
socks_portport, offSOCKS5 listener on 127.0.0.1.
http_portport, offHTTP proxy listener on 127.0.0.1.
auth_key_filepathThis client's key file, from flexaccess-keys generate-auth-key. Its public entry (flexaccess-keys show-auth-key) goes in each server's authorized keys file.
relay_urlslist of URLs, the default relaysCustom relays. See Relays.
relay_auth_tokenstringBearer token sent to every custom relay.
relay_quic_addr_discoverybool, trueWhether the custom relays serve QUIC address discovery.
idle_timeout_secsseconds, 300How long an unused connection is kept. 0 never closes it.
[[destinations]]tables, at least oneThe servers this client reaches, one table each.
[[forwards]]tables, nonePort forwards

[[destinations]]

KeyType, defaultMeaning
namestring, requiredA unique DNS label (no dots). <name>.localhost.flextunnel.internal reaches the server's own loopback.
server_node_idstring, requiredThe server's endpoint ID (from flextunnel show-iroh-id).
routed_domainslist, emptyNames sent through this server: exact, *.suffix or *. See Routing.
routed_cidrslist, emptyNetworks or bare IPs sent through this server.
auth_key_filepath, the top-level oneA key file for this destination only.
relay_urlslist, the top-level onesRelays for this destination only, with its own relay_auth_token and relay_quic_addr_discovery. See Per-destination relays.

[[forwards]]

KeyType, defaultMeaning
labelstring, emptyDisplay only.
local_portport, requiredThe port to listen on, on 127.0.0.1 and ::1.
remote_hoststring, requiredA destination's <name>.localhost.flextunnel.internal, or a host a destination routes.
remote_portport, requiredThe port to connect to.

Port forwards

Each [[forwards]] table listens on localhost:local_port and connects to remote_host:remote_port through the destination that routes remote_host. A forward never connects directly, so a host no destination routes is a startup error. To change forwards, edit the config and restart the client.

To reach a port on the server machine itself (like ssh's -L 8080:localhost:80), use remote_host = "office.localhost.flextunnel.internal": it needs no config on either side. Spelling it 127.0.0.1 or localhost makes it an ordinary target that both the destination and the server must route.

Forwards bind loopback only. For another local address, see Custom bind addresses.

server.toml

server.toml
secret_file          = "./server.key"
authorized_keys_file = "./authorized_keys"

# Top-level keys must come before the [host_aliases] table.
routed_domains = ["*.corp.example"]
routed_cidrs   = ["10.0.0.0/8"]

[host_aliases]
"printer.corp.example" = "192.168.1.50"
KeyType, defaultMeaning
secret_filepath, requiredThe server's identity key, from flextunnel generate-iroh-key.
authorized_keys_filepathThe authorized client keys, one ed25519-pub:… per line. Without it no client is authorized.
relay_urlslist of URLs, the default relaysCustom relays. See Relays.
relay_auth_tokenstringBearer token sent to every custom relay.
relay_quic_addr_discoverybool, trueWhether the custom relays serve QUIC address discovery; set it the same on the clients.
routed_domainslist, emptyNames clients may reach through this server. See What a server accepts.
routed_cidrslist, emptyNetworks or bare IPs clients may reach through this server.
[host_aliases]table, noneSee Host aliases.

A server that finds a duplicate client or server ID records it in ~/.config/flextunnel/blocklist.json and will not start while its own ID is listed. Delete the entry once the conflict is fixed.

Routing

The client decides which server a request goes to; the server decides whether to accept it. Each side has its own lists.

your appcurl · browser · sshhost name, not IP (socks5h)local proxySOCKS5 / HTTP on 127.0.0.1most specific rule winsexact › longest *.suffix › *IPs: longest CIDR prefixoffice*.corp.examplenas10.0.0.0/8no rulematchesQUICQUICoffice serverchecks its ownallowlistnas serverchecks its ownallowlistdirectfrom thisdeviceallowedallowedtargetwiki.corp.exampletarget10.0.0.7targetexample.comnot on a server's list → refused, nothing dialedport forwards and client nc never go direct
The client picks the destination without being connected to anything; the server only decides whether to accept.

The client picks the destination

client.toml
[[destinations]]
name           = "office"
server_node_id = "SERVER_ENDPOINT_ID"
routed_domains = ["*.corp.example", "httpbin.org"]
routed_cidrs   = ["10.0.0.0/8", "192.168.1.5"]

[[destinations]]
name           = "lab"
server_node_id = "LAB_ENDPOINT_ID"
routed_domains = ["*.dev.corp.example"]

For each request, the most specific match wins:

  1. A destination's <name>.localhost.flextunnel.internal: that server's loopback.
  2. The rest of flextunnel.internal: the client's own status pages.
  3. An exact routed_domains entry, then the longest *.suffix, then *. For an IP, the longest matching routed_cidrs prefix.
  4. Nothing matches: the proxy listeners connect directly from this device, while a port forward or client nc is refused.

So api.corp.example goes to office and x.dev.corp.example to lab. Nesting is fine, but the same rule on two destinations is rejected at startup. For a full tunnel through one server:

routed_domains = ["*"]
routed_cidrs   = ["0.0.0.0/0", "::/0"]

What a server accepts

server.toml
routed_domains = ["*.corp.example", "httpbin.org"]
routed_cidrs   = ["10.0.0.0/8", "192.168.1.5"]

A server rejects any target not on its lists ("connection not allowed"), so a route must be on both the client's destination and the server. Its own loopback and status page are always reachable, so a server with no lists is valid: clients reach just that machine. List host alias names here too.

How entries match

  • Domain entries are exact (example.com), wildcard (*.example.com, subdomains only), or *, case-insensitive. CIDR entries take a bare IP as a single host.
  • Hostnames match only routed_domains and IPs only routed_cidrs, so * never covers an IP, and an IP in routed_domains is a config error.

Keeping the two sides in step

Each time a destination connects, the client reads that server's lists and flags any of its rules the server does not route, in the log and on its status page. The desktop app can fill a destination's lists from the server with Fetch from server.

Host aliases

A server can map hostnames to addresses on its own network, so clients reach internal hosts by a name of your choosing:

server.toml
[host_aliases]
"printer.corp.example" = "192.168.1.50"   # another host on the server's network
"*.svc.corp.example"   = "192.168.1.60"   # any subdomain of svc.corp.example
"local.corp.example"   = "127.0.0.1"      # the server's own loopback
"node6.corp.example"   = "2001:db8::50"   # IPv6, written bare

The server rewrites a matching name to the value and keeps the port. Keys are exact names or *.suffix wildcards (an exact key wins); write IPv6 values without brackets. The name must be routed by the client's destination and allowed by the server, and sent unresolved (socks5h://).

Connection lifecycle

A client holds no connection to a server until something is sent to it.

  • First use connects. A request for a destination that is not connected is held while the client connects, for up to 45 seconds.
  • Idle disconnects. A connection with no open stream for idle_timeout_secs (default 300) is closed. 0 keeps it.
  • Reconnects are on demand. A lost connection is retried with backoff only while requests are waiting; otherwise the next request redials.
  • A down server is not a reason to exit. Only requests for that destination fail; the rest keep working.

If the first request after an idle period is noticeably slow, raise idle_timeout_secs. The control panel and status page show each destination's state and last error. Details are in the connection policy.

The proxy listeners

The SOCKS5 listener supports CONNECT only (no UDP). The HTTP proxy handles HTTPS and any TCP by CONNECT, and plain HTTP by forwarding. Both bind 127.0.0.1 and are unauthenticated, so any local user can use them: run the client on a machine you trust.

flextunnel client start -c client.toml --http-port 8081

https_proxy=http://127.0.0.1:8081 curl https://wiki.corp.example/

Which listener each tool needs is in Use the proxy from your apps.

Relays

Both ends connect directly when they can and through a relay when they cannot, using the public iroh relays by default. One custom relay is enough. Configure the same relay URLs on the server and all its clients.

relay_urls       = ["https://relay-a.example"]
relay_auth_token = "shared-relay-secret"   # optional
  • Failover requires at least two distinct relays.
  • Custom relays turn off internet discovery; clients find the server through the relays instead.
  • For relays behind a Cloudflare Tunnel or another HTTP-only front, set relay_quic_addr_discovery = false on the server and its clients, or each start waits out a probe timeout.

Per-destination relays

A destination with its own relay_urls uses only its own token and discovery setting, so servers on different relays can share one client:

client.toml
[[destinations]]
name                      = "nas"
server_node_id            = "NAS_ENDPOINT_ID"
auth_key_file             = "~/.config/flextunnel/nas.key"
relay_urls                = ["https://relay-c.example"]
relay_auth_token          = "nas-relay-secret"
relay_quic_addr_discovery = false

More in the shared docs: relays and address lookup, self-hosting a relay, and home-relay failover.

Faster on Linux: raise the UDP buffer limit

Linux's default UDP buffer limit is too small for fast transfers. Raise it on both ends, then restart flextunnel:

sudo sysctl -w net.core.rmem_max=7500000 net.core.wmem_max=7500000

# keep it across reboots
printf 'net.core.rmem_max=7500000\nnet.core.wmem_max=7500000\n' | sudo tee /etc/sysctl.d/90-udp-buffers.conf

Where you cannot change the sysctl, granting flextunnel CAP_NET_ADMIN (in a systemd system unit, AmbientCapabilities=CAP_NET_ADMIN) has the same effect.

Logging

Logs go to stderr at info. Set RUST_LOG to change that:

RUST_LOG=flextunnel=debug flextunnel client start -c client.toml

Under systemd, see Run it as a service.