Configuration and routing
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.On this page
All flextunnel guides
Commands
| Command | Does |
|---|---|
server start | Run a server. |
client start | Run a client: its proxy listeners, destinations and port forwards. |
client control | Attach the read-only terminal control panel to a running client. |
client nc | Relay stdin and stdout through a running client to a host:port (for ssh's ProxyCommand). |
client help | Show 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
| Flag | Meaning |
|---|---|
-c, --config FILE | Load settings from a TOML file; flags override it. |
--default-config | Load ~/.config/flextunnel/server.toml. |
--secret-file FILE | The server's identity key. |
--authorized-keys-file FILE | The authorized client public keys, one ed25519-pub:… per line. |
--relay-url URL (repeatable), --relay-auth-token TOKEN, --relay-quic-addr-discovery BOOL | Custom relays, as the relay_* keys. See Relays. |
--quick | An 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
| Flag | Meaning |
|---|---|
-c, --config FILE | Load settings from a TOML file; flags override it. Without it, ~/.config/flextunnel/client.toml is used if it exists. |
--socks-port PORT | Run the SOCKS5 listener on 127.0.0.1:PORT. Off unless set. |
--http-port PORT | Run the HTTP proxy listener on 127.0.0.1:PORT. Off unless set. |
--auth-key SECRET / --auth-key-file FILE | The 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 BOOL | Custom relays for every destination that names none of its own. See Relays. |
--idle-timeout SECS | How long an unused connection is kept (default 300; 0 never closes it). |
--quick | An 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 nameclient 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.tomlA 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
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 = 5432Top-level keys
| Key | Type, default | Meaning |
|---|---|---|
name | string, "default" | This client's instance name, used by client control and client nc to find it. |
socks_port | port, off | SOCKS5 listener on 127.0.0.1. |
http_port | port, off | HTTP proxy listener on 127.0.0.1. |
auth_key_file | path | This 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_urls | list of URLs, the default relays | Custom relays. See Relays. |
relay_auth_token | string | Bearer token sent to every custom relay. |
relay_quic_addr_discovery | bool, true | Whether the custom relays serve QUIC address discovery. |
idle_timeout_secs | seconds, 300 | How long an unused connection is kept. 0 never closes it. |
[[destinations]] | tables, at least one | The servers this client reaches, one table each. |
[[forwards]] | tables, none | Port forwards |
[[destinations]]
| Key | Type, default | Meaning |
|---|---|---|
name | string, required | A unique DNS label (no dots). <name>.localhost.flextunnel.internal reaches the server's own loopback. |
server_node_id | string, required | The server's endpoint ID (from flextunnel show-iroh-id). |
routed_domains | list, empty | Names sent through this server: exact, *.suffix or *. See Routing. |
routed_cidrs | list, empty | Networks or bare IPs sent through this server. |
auth_key_file | path, the top-level one | A key file for this destination only. |
relay_urls | list, the top-level ones | Relays for this destination only, with its own relay_auth_token and relay_quic_addr_discovery. See Per-destination relays. |
[[forwards]]
| Key | Type, default | Meaning |
|---|---|---|
label | string, empty | Display only. |
local_port | port, required | The port to listen on, on 127.0.0.1 and ::1. |
remote_host | string, required | A destination's <name>.localhost.flextunnel.internal, or a host a destination routes. |
remote_port | port, required | The 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
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"| Key | Type, default | Meaning |
|---|---|---|
secret_file | path, required | The server's identity key, from flextunnel generate-iroh-key. |
authorized_keys_file | path | The authorized client keys, one ed25519-pub:… per line. Without it no client is authorized. |
relay_urls | list of URLs, the default relays | Custom relays. See Relays. |
relay_auth_token | string | Bearer token sent to every custom relay. |
relay_quic_addr_discovery | bool, true | Whether the custom relays serve QUIC address discovery; set it the same on the clients. |
routed_domains | list, empty | Names clients may reach through this server. See What a server accepts. |
routed_cidrs | list, empty | Networks or bare IPs clients may reach through this server. |
[host_aliases] | table, none | See 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.
The client picks the destination
[[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:
- A destination's
<name>.localhost.flextunnel.internal: that server's loopback. - The rest of
flextunnel.internal: the client's own status pages. - An exact
routed_domainsentry, then the longest*.suffix, then*. For an IP, the longest matchingrouted_cidrsprefix. - Nothing matches: the proxy listeners connect directly from this device, while a port forward or
client ncis 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
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_domainsand IPs onlyrouted_cidrs, so*never covers an IP, and an IP inrouted_domainsis 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:
[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 bareThe 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.0keeps 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 = falseon 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:
[[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 = falseMore 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.confWhere 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.tomlUnder systemd, see Run it as a service.