Overview
zeronat exposes ports on a machine behind CG-NAT through a VM with a public IP, without accounts or third-party services.
The server runs on the public host. The client runs behind NAT, dials out, and holds one control
connection. Traffic hitting a public port on the server is forwarded to the matching local service on
the client. Every connection is authenticated and encrypted with Noise (NNpsk0, X25519 +
ChaCha20-Poly1305 + BLAKE2s) keyed by a shared secret. Forwarding is terminate-and-forward at L4.
Install
curl -fsSL https://paltaio.github.io/zeronat/get.sh | sh
Picks Docker or a systemd service, generates the secret, asks what to forward, and prints the matching command to run on the machine behind CG-NAT.
docker pull ghcr.io/paltaio/zeronat
Quick start
# On the public host (VPS):
# Generate this once, then copy the same value to both hosts.
SEED="$(openssl rand -hex 32)"
ZERONAT_SEED="$SEED" zeronat server --control 2222 --client home \
--tcp 443 --tcp 80 --udp 51820
# On the host behind CG-NAT:
ZERONAT_SEED="$SEED" zeronat client --server <public-ip>:2222 --id home \
--tcp 443 --tcp 80 --udp 51820
# Generate this once, then copy the same value to both hosts.
SEED="$(openssl rand -hex 32)"
# On the public host (VPS):
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_BIND_SERVICE --security-opt no-new-privileges \
-e ZERONAT_SEED="$SEED" ghcr.io/paltaio/zeronat \
server --control 2222 --client home --tcp 443 --tcp 80 --udp 51820
# On the host behind CG-NAT; with --network host, 127.0.0.1 targets are host services:
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_BIND_SERVICE --security-opt no-new-privileges \
-e ZERONAT_SEED="$SEED" ghcr.io/paltaio/zeronat \
client --server <public-ip>:2222 --id home --tcp 443 --tcp 80 --udp 51820
Open the control port (2222, both UDP and TCP) on the server's firewall.
The seed derives every credential: the network secret, the admin secret, the discovery
credential, and one credential per client id, so --client home on the server and
--id home on the client agree with nothing else copied. The server accepts only
clients it holds a credential for; --client <id> is repeatable and the config
file takes [[clients]] entries. Ids and credentials must both be unique.
A value set on its own wins over the seed: ZERONAT_SECRET,
--client <id>:<64-HEX> (or ZERONAT_CLIENT_ID with
ZERONAT_CLIENT_SECRET), ZERONAT_ADMIN_SECRET,
ZERONAT_DISCOVERY_SECRET. To keep the seed off a client, run
zeronat derive-client <id> on the server and start the client with the lines it
prints in its environment in place of the seed:
ZERONAT_SEED="$SEED" zeronat derive-client home --dht
# ZERONAT_SECRET=<64-hex>
# ZERONAT_CLIENT_SECRET=<64-hex>
# ZERONAT_DISCOVERY_SECRET=<64-hex>
ZERONAT_SECRET is the network secret and ZERONAT_CLIENT_SECRET is that
client's credential. --dht adds the discovery credential, which a client needs only
with --server dht.
Forwarding
On the server, --tcp PORT and --udp PORT name the public ports to expose.
On the client, the same flags take a forward spec mapping that public port to a local target:
| Client spec | Forwards to |
|---|---|
--tcp 443 | 127.0.0.1:443 |
--tcp 443:8443 | 127.0.0.1:8443 |
--tcp 443:10.0.0.5:443 | 10.0.0.5:443 |
--udp works the same way. Both flags are repeatable.
Proxy protocol
Any client forward spec takes appended modifiers: SPEC[+proxy][+idle=SECS].
+proxy applies to TCP forwards only and is rejected on --udp; the client
flag --proxy enables it on every --tcp forward at once. For each public
connection, the client writes a PROXY protocol v2 header as the first bytes to the local target,
carrying the real public peer address and the public listener address the connection arrived on. The
target must be configured to expect the header; one that is not reads it as garbage at the start of
every connection.
zeronat client --server <public-ip>:2222 --tcp 443:10.0.0.5:443+proxy+idle=600
Both ends must run a release that supports +proxy. After connecting, the client
announces its per-forward options and waits for the server's acknowledgment; against a server that
never acknowledges, the client logs an error naming the affected forwards and those forwards refuse
every connection rather than relay without the header. Removing +proxy and restarting
the client restores plain relaying against any server.
Traefik cutover
For a deployment where the forward's target is Traefik: configure Traefik to trust PROXY headers
from the address the zeronat client dials from (on a Docker network typically the bridge gateway, e.g.
172.18.0.1) and restart it, then add +proxy to the client's forward specs and restart the
client. Rollback is removing +proxy again; no Traefik change is needed.
# traefik static configuration
entryPoints:
websecure:
address: ":443"
proxyProtocol:
trustedIPs:
- "172.18.0.1/32"
Traefik serves connections without a header even when trustedIPs is set, so the two
restarts can happen in either order. Any host matching trustedIPs can forge client
addresses; keep it a /32.
Once headers flow, IP-keyed middleware (geoip, allow and deny lists, rate limits) sees real public addresses; rules that matched the internal dial source stop matching.
Transparency
Per-port forwarding relays payload bytes untouched, but a service behind zeronat observes its network environment differently than the same service on a public IP:
| Behavior | On a public IP | Behind zeronat |
|---|---|---|
| TCP client address | Real peer address | The client's dial source; real address via +proxy |
| UDP peer address | Real peer address per datagram | The client's local socket, one per public source |
| Destination address | The public IP and port | The forward's target address |
| TLS | Terminated by the service | Same: passthrough, never terminated or inspected |
| TCP half-close | One direction keeps flowing | Not propagated: a FIN closes both directions |
| Reset vs orderly close | RST visible as a reset | A reset surfaces as an orderly close |
| Idle TCP lifetime | Unlimited | Unlimited while the tunnel is healthy |
| Idle UDP flow lifetime | No flow state kept | Source forgotten after max(180s, idle+60s) |
| IPv6 | As deployed | Public listeners are IPv4-only |
| UDP datagram size | Path MTU | 1442 bytes on a 1500 path over the UDP transport |
| Client disconnected | Connection refused | TCP: accepted then closed; UDP: silently dropped |
With +proxy, the PROXY v2 header carries the real peer and the public listener
address, so a parsing target recovers both. There is no PROXY protocol for UDP; when a UDP service
needs real peer addresses, use --tun.
Both relay ends probe every half idle window, so a healthy idle stream lives until its path goes
fully silent, probes included, for a whole window (default 120s, +idle=SECS per
forward). +idle also extends the UDP source lifetime; a forgotten source returns
through a fresh client socket, so the target sees a new source port.
The 1442-byte UDP limit is a 1500-byte path minus IPv4/UDP headers and tunnel framing. A WireGuard peer behind a forwarded port adds 32 more bytes: keep its MTU at 1410 or lower. The TCP transport has no per-datagram limit below 64 KB; loss becomes retransmission delay instead of drops.
Health checks: with no client connected, a TCP listener accepts and immediately closes, while a down service refuses.
Transport
The tunnel runs over UDP/KCP by default and falls back to TCP when the UDP handshake gets no reply.
Both share the control port (2222). The client picks the transport with
--transport auto|udp|tcp (default auto).
- UDP (KCP): reliable ARQ over UDP carries the control channel and TCP-forward data; loss-tolerant UDP forwards ride as raw datagrams.
- TCP: fallback for networks that block or break UDP.
On the UDP transport a conv drains its window once per round trip, so --kcp-window
sets the throughput ceiling of one forwarded connection: 256 segments of 1326 bytes caps a
connection near 110 Mbit/s over a 6.6 ms round trip. KCP runs here without congestion control,
so a window wider than the bottleneck's queue overruns it on every flush and throughput drops
instead of rising. Both ends need the same value; the effective window is the smaller of the two.
Multi-client routing
Multiple clients can connect to one server. A route maps a listener (bind_ip,
proto, port) to a client id. New connections go to the routed client;
connections already open on the previous client drain until they close. There is no round-robin,
health checking, or failover.
A client id is the id in the server's --client entry or its [[clients]]
section; the server hands it to the client when the session opens. Under a seed the client's
--id is that same id.
A client id holds one session at a time. While it is live, the server refuses another connection with the same credential; a session that has sent nothing for 40 seconds gives way to the new one.
Load listeners, routes, and identity from a file with --config:
zeronat server --config /etc/zeronat/server.toml
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_BIND_SERVICE --security-opt no-new-privileges \
-v /etc/zeronat/data:/etc/zeronat/data --env-file /etc/zeronat/.env \
ghcr.io/paltaio/zeronat server --config /etc/zeronat/data/server.toml
# server.toml
[server]
id = "zn01"
control = "0.0.0.0:2222"
seed = "<64-hex-seed>"
[[clients]]
id = "rpi-2"
[[clients]]
id = "guest"
secret = "<64-hex-client-credential>"
[[listeners]]
bind_ip = "0.0.0.0"
proto = "tcp"
port = 8080
[[routes]]
bind_ip = "0.0.0.0"
proto = "tcp"
port = 8080
client = "rpi-2"
A [[clients]] entry without a secret takes its credential from the
seed, which [server].seed holds here; --seed or
ZERONAT_SEED serves the same purpose. The seed also fills
admin_secret when the file leaves it out.
CLI --tcp/--udp forwards merge with the file's listeners. The server
rereads [[clients]] when the file is saved: an added client can
connect, and a removed client, or one given a new secret, is disconnected. Other changes to the
file take effect after a restart. A malformed config aborts startup.
Client config
Load servers, forwards, and identity from a file with --config:
zeronat client --config /etc/zeronat/client.toml
# client.toml
[client]
id = "rpi-2"
active = "home"
[[servers]]
name = "home"
addr = "203.0.113.7:2222"
seed = "<64-hex-seed>"
transport = "auto"
[[servers]]
name = "backup"
addr = "dht"
secret = "<64-hex-secret>"
credential = "<64-hex-client-credential>"
discovery = "<64-hex-discovery-credential>"
[[forwards]]
proto = "tcp"
port = 443
target = "127.0.0.1:8443"
proxy = true
idle = 600
[[pppoe]]
name = "wan"
username = "user@isp"
password_file = "/etc/zeronat/wan.pass"
Replace each secret placeholder with 64 hexadecimal characters encoding 32 bytes.
Each [[servers]] entry is a named profile with its own address, credentials, and
transport; [client].active picks the one to dial (default: the first).
A seed fills the entry's secret, discovery, and the
credential derived for [client].id, which the server lists as
--client <id>; a key set on its own wins. Without a seed,
credential defaults to secret.
[[forwards]] entries take the same options as the CLI specs: proxy is
TCP-only, idle is whole seconds. enabled = false keeps a forward in the
config but stops serving it (default true). A [[pppoe]] entry names a session that
can be spawned at runtime; one may set autostart = true to dial at boot when no
forwards are declared. [tap] or [tun] declares a device mode instead,
exclusive with forwards and PPPoE. A [tun] carrying exit_via and a
[peer] table declare peer sessions, which run alongside the
forwards and PPPoE sessions.
A file that declares any servers, forwards, PPPoE sessions, or a device is authoritative for
the whole client shape: the matching CLI flags are ignored, each with a log line. A file that
declares none leaves the CLI flags in charge. Scalars apply either way; the file's id
overrides --id.
A missing file is a normal first boot. A file that fails to parse is moved aside to
<name>.corrupt-<timestamp> and the client starts from the command line. A
file that parses but contradicts itself (an active naming no server, duplicate server
names, duplicate proto/port forwards, two autostart entries)
aborts startup, as does an unreadable file.
The file carries the per-server secrets; keep it mode 600. password_file keeps the
PPPoE password out of the config.
Admin
Inspect and change a running server over the control port:
ZERONAT_SEED="$SEED" zeronat admin --server <public-ip>:2222 show
ZERONAT_SEED="$SEED" zeronat admin --server <public-ip>:2222 add-client site-2 --generate
ZERONAT_SEED="$SEED" zeronat admin --server <public-ip>:2222 set-route tcp:443 site-2
# The seed comes from the container's env:
docker exec -it zeronat /zeronat admin --server <public-ip>:2222 show
docker exec -it zeronat /zeronat admin --server <public-ip>:2222 add-client site-2 --generate
docker exec -it zeronat /zeronat admin --server <public-ip>:2222 set-route tcp:443 site-2
A server started with --config writes each change to the file. Client changes
edit its [[clients]]; when the file has none, the --client entries are
copied into it first.
Remote admin runs on its own secret, which the seed derives. Without a seed, start the server
with --admin-secret or ZERONAT_ADMIN_SECRET, which must differ from the
network, client, and discovery credentials, and give admin the same value as
--secret or ZERONAT_ADMIN_SECRET. The server refuses remote admin when
it has neither.
It prints the server, its routes, connected clients, and active listeners. Each client lists
the forwards it announced with non-default options (tcp:443 +proxy+idle=600), and a
route shows its forward's options in the OPTIONS column.
On a terminal the same command opens an interactive console. Its PAIRS panel lists the peer pairs the server formed: the consumer, the provider, the capability, and whether the pair settled direct or relayed.
Client admin
Drive a running client over its local admin socket:
zeronat client admin # interactive console on a terminal
zeronat client admin show # print status and exit
zeronat client admin select-server backup
zeronat client admin disable-forward tcp:443
zeronat client admin add-server backup2 203.0.113.9:2222 # secret from stdin
zeronat client admin spawn-pppoe wan
docker exec -it zeronat /zeronat client admin # interactive console
docker exec -it zeronat /zeronat client admin show # print status and exit
docker exec -it zeronat /zeronat client admin select-server backup
docker exec -it zeronat /zeronat client admin disable-forward tcp:443
docker exec -it zeronat /zeronat client admin add-server backup2 203.0.113.9:2222
docker exec -it zeronat /zeronat client admin spawn-pppoe wan
The socket is /run/zeronat/client.sock, or
$XDG_RUNTIME_DIR/zeronat/client.sock when the client cannot create
/run/zeronat; --socket overrides it and [client].control
pins it. Access control is the filesystem: the socket is mode 600 in a 700 directory, so whoever
can open it drives the client; no secret is needed.
The console lists the configured server profiles with the link state on the active one, the
active session (mode and, for PPPoE, the link phase), and the forwards with their options. Its
PEERS panel, printed as Peer slots by show, lists each peer slot: the capability,
the peer on a consumer slot or provider on a providing one, the interface, the
link state, and the path once the pair settles. Selecting a server tears the current session
down and redials it against the new one, with a brief link drop.
select-server, server-list edits, and forward edits persist to the
config file when the client booted from one; spawn-pppoe/stop-pppoe are
runtime-only and do not survive a restart.
add-server and remove-server edit the server list on a running
client. The secret is read from stdin, prompted with echo off on a terminal, never taken on the
command line. Removing the active profile is refused; select another first.
enable-forward and disable-forward flip one forward without removing
it: a disabled forward stays in the config and the status listing but refuses connections until
re-enabled.
add-forward and remove-forward edit the forward list itself.
add-forward tcp:8443:10.0.0.5:8443+proxy takes the same spec as
--tcp/--udp and starts serving at once, even on a client that booted
with no forwards. A running PPPoE session is left alone; the forward starts serving once that
session stops. remove-forward tcp:8443 drops the port; connections open on it
are cut. Changing a target is remove then add.
disconnect parks the client offline: the session tears down, nothing is dialed,
and only the admin socket stays up. connect brings the boot-declared session back,
optionally naming another server, and reports the resulting mode. Offline is never persisted; a
restarted client serves what the file declares.
All ports
--tun forwards every port plus ICMP to one client over an L3 tunnel, instead of naming
ports. The server sends all inbound traffic except the control port (and any --except
ports) to the client and source-NATs the replies; the tunnel subnet is derived from the shared secret.
Both ends need --tun; it cannot be combined with --tcp/--udp or
--tap.
# Server (VPS): forward every port to the client, keep SSH on 22:
ZERONAT_SEED="$SEED" zeronat server --control 2222 --client home --tun --except 22
# Client (behind CG-NAT): local services receive on the same port:
ZERONAT_SEED="$SEED" zeronat client --server <public-ip>:2222 --id home --tun
# Server (VPS): forward every port to the client, keep SSH on 22:
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_ADMIN --cap-add NET_RAW --cap-add NET_BIND_SERVICE \
--device /dev/net/tun --security-opt no-new-privileges \
-e ZERONAT_SEED="$SEED" ghcr.io/paltaio/zeronat server --control 2222 --client home --tun --except 22
# Client (behind CG-NAT): local services receive on the same port:
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_ADMIN --cap-add NET_RAW --cap-add NET_BIND_SERVICE \
--device /dev/net/tun --security-opt no-new-privileges \
-e ZERONAT_SEED="$SEED" ghcr.io/paltaio/zeronat client --server <public-ip>:2222 --id home --tun
Forwarded traffic includes the server's own SSH; keep it reachable with
--except <ssh-port> (repeatable). The client needs no NAT: local services receive
the traffic on the same port and must listen on 0.0.0.0 or the tunnel address.
Linux only. The server needs root or CAP_NET_ADMIN (plus CAP_NET_RAW
for the iptables fallback), /dev/net/tun, and nft or
iptables to program the NAT.
Exit mode
On top of --tun, the server's --exit makes it a default-route exit:
it masquerades the client's outbound traffic onto its own uplink. --exit-iface <IF>
names the interface to masquerade out of; without it the server takes the interface its default
route uses. [server] exit and exit_iface set both from the config
file.
On the client, --exit routes this host's IPv4 traffic through the tunnel. The
server's address is pinned to the current default route as a /32, and 0.0.0.0/1
plus 128.0.0.0/1 point at the tun device, so they beat the host's own default route
on prefix length while leaving it in place. --exit-strict goes further: it deletes
the original default routes and puts ::/1 and 8000::/1 on loopback
for as long as the tunnel routes are up, so traffic stops rather than leaking out the uplink
if the tunnel drops. IPv6 sends fail on the host with ENETUNREACH, and the two
routes read as ordinary dev lo entries in ip -6 route. Teardown
restores the defaults and removes both; a crash skips it and leaves the host without a
default route.
# Server (VPS): masquerade the client's traffic out eth0:
ZERONAT_SEED="$SEED" zeronat server --control 2222 --client home \
--tun --except 22 --exit --exit-iface eth0
# Client: send this host's IPv4 traffic through the server:
ZERONAT_SEED="$SEED" zeronat client --server <public-ip>:2222 --id home --tun --exit --exit-strict
# Server (VPS): masquerade the client's traffic out eth0:
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_ADMIN --cap-add NET_RAW --cap-add NET_BIND_SERVICE \
--device /dev/net/tun --security-opt no-new-privileges \
-e ZERONAT_SEED="$SEED" ghcr.io/paltaio/zeronat \
server --control 2222 --client home --tun --except 22 --exit --exit-iface eth0
# Client: send this host's IPv4 traffic through the server:
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_ADMIN --cap-add NET_RAW --cap-add NET_BIND_SERVICE \
--device /dev/net/tun --security-opt no-new-privileges \
-e ZERONAT_SEED="$SEED" ghcr.io/paltaio/zeronat \
client --server <public-ip>:2222 --id home --tun --exit --exit-strict
--exit requires --tun on both ends; --exit-iface and
--exit-strict require --exit. In the config file,
[server] exit_iface and [tun] exit_strict carry the same
requirement.
L2 bridge (TAP)
--tap relays raw Ethernet frames over the tunnel, joining a TAP on each end into one L2
segment. It carries anything Ethernet, including PPPoE. Both ends need --tap; it cannot be
combined with --tcp/--udp.
# Near the target segment (e.g. the PPPoE concentrator):
ZERONAT_SEED="$SEED" zeronat server --control 2222 --client home --tap zn0 --bridge br0
# Behind CG-NAT, then run e.g. pppd on zn0:
ZERONAT_SEED="$SEED" zeronat client --server <public-ip>:2222 --id home --tap zn0
pppd plugin rp-pppoe.so zn0 user <user>
# Near the target segment (e.g. the PPPoE concentrator):
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_ADMIN --cap-add NET_RAW --cap-add NET_BIND_SERVICE \
--device /dev/net/tun --security-opt no-new-privileges \
-e ZERONAT_SEED="$SEED" ghcr.io/paltaio/zeronat server --control 2222 --client home --tap zn0 --bridge br0
# Behind CG-NAT; zn0 lands in the host netns, run pppd on the host:
docker run -d --name zeronat --restart unless-stopped --network host \
--cap-drop ALL --cap-add NET_ADMIN --cap-add NET_RAW --cap-add NET_BIND_SERVICE \
--device /dev/net/tun --security-opt no-new-privileges \
-e ZERONAT_SEED="$SEED" ghcr.io/paltaio/zeronat client --server <public-ip>:2222 --id home --tap zn0
pppd plugin rp-pppoe.so zn0 user <user>
--bridge <name> enslaves the TAP to an existing bridge; --tap-mtu <n>
sets the MTU (default 1400). Linux only. Needs CAP_NET_ADMIN: root,
setcap cap_net_admin+ep zeronat, or Docker
--cap-add NET_ADMIN --device /dev/net/tun (plus --device /dev/ppp for pppd,
and --cap-add NET_RAW for the iptables fallback).
The installer can build that bridge on netplan or systemd-networkd hosts: pass
--bridge-nic <iface> (or pick the interface in the wizard) and it creates the bridge,
enslaves the NIC, and persists the change. On a single-NIC server, where the uplink itself must join
the bridge, it moves that interface's address onto the bridge and waits for you to confirm you still
have access, reverting within ~30s if you do not.
Peer sessions
Two clients of one server can run a session with each other. One side provides a capability, the other names that side by client id; the server pairs them and both ends try a UDP punch. A pair that punches through runs directly between the two hosts, and one that does not runs over the server. A client on the TCP transport never punches, so its pairs are always relayed.
The session inside a pair is Noise-encrypted with the profile's secret, so a relayed pair moves ciphertext the server passes along without opening it. A direct pair and a relayed one look the same to whatever runs over them.
Peer slots run beside the client's own session with the server and pair while that client
serves forwards or sits idle. Under a --tun, --tap, or PPPoE session
the slot is recorded and pairs when the client returns to either.
A server started with a control port and its client credentials registers clients and pairs them. It carries no forwards, TAP or tun of its own, so the control port is the only one to open.
ZERONAT_SEED="$SEED" zeronat server --control 2222 --client a --client b
Peer exit
The provider sets exit = true under [peer], with an optional
exit_iface naming the interface to masquerade out of (default: the default-route
one). It opens a tun (znx0) on the pair's subnet and masquerades the consumer's
traffic onto its uplink. The consumer names the provider with exit_via under
[tun]; exit and exit_strict route this host's traffic
through the pair the same way they route it through a server. One exit provider serves one
consumer at a time; a second is refused while that pair is up.
# provider client.toml: serve one peer an exit
[peer]
exit = true
exit_iface = "eth0"
# consumer client.toml: route through that peer
[tun]
exit = true
exit_strict = true
exit_via = "office-b1c2"
A [tun] that names exit_via describes the peer session, so the
same client cannot also run a server tunnel from it, and the table takes no
address. dev names the consumer's device (default zn0).
The forwards and PPPoE sessions in the same file keep running against the server.
L2 segment
A segment provider sets segment under [peer] to the bridge
carrying the segment it shares. It opens a TAP (zns0), enslaves it to that bridge,
and switches Ethernet frames between the bridge and every consumer attached to it. Several
consumers can share one segment provider.
# provider client.toml
[peer]
segment = "br0"
znpppoe --peer <client-id> is the consumer for a segment: it opens its PPPoE
sessions over that peer's segment instead of a bridge port on the server. See
PPPoE proxy.
Attaching at runtime
The client admin attaches and detaches peer slots on a running client:
zeronat client admin attach-provider exit eth0 # serve peers an exit
zeronat client admin attach-provider segment br0 # serve peers an L2 segment
zeronat client admin attach-peer office-b1c2 --dev zn0 --exit --exit-strict
zeronat client admin detach-peer office-b1c2
zeronat client admin detach-provider exit
An attach writes the [tun] or [peer] table it declares to the
config file when the client booted from one, so it survives a restart. Detaching a provider
takes down the pairs it serves. attach-peer without --exit brings the
device up for routes you install yourself.
Linux only, on both ends. Each side opens a device, so each needs CAP_NET_ADMIN
and /dev/net/tun; an exit provider also needs nft or
iptables for the masquerade.
DHT discovery
For a server on a dynamic IP, --server dht publishes its address to the BitTorrent
Mainline DHT and the client looks it up. The lookup key is derived from a discovery credential,
separate from the secret; the published address is signed and encrypted. A holder of the
discovery credential can find the server but cannot open a session, and the secret alone can
neither publish nor read the record. Both sides need the same discovery credential, which must
differ from every secret; the seed derives one.
# Server publishes its address; IP is auto-detected from the DHT:
ZERONAT_SEED="$SEED" zeronat server --server dht --client home --tcp 443
# Client finds the server through the DHT:
ZERONAT_SEED="$SEED" zeronat client --server dht --id home --tcp 443
# Without a seed, generate the credential once and copy it to both hosts:
DISCOVERY="$(openssl rand -hex 32)"
ZERONAT_SECRET="$SECRET" ZERONAT_DISCOVERY_SECRET="$DISCOVERY" \
ZERONAT_CLIENT_ID=home ZERONAT_CLIENT_SECRET="$SECRET" \
zeronat server --server dht --tcp 443
--announce-ip <ip> overrides the detected IP and --announce-port <port>
the announced port (default: the control port) when the server sits behind a port-forward. The client
caches the last-known address and re-queries the DHT only when it stops working.
PPPoE proxy (znpppoe)
znpppoe opens many PPPoE sessions in userspace over one tunnel and exposes each as a
SOCKS5 and HTTP CONNECT egress, each with its own ISP-assigned IP. It needs no kernel interface and no
privileges. The server is a normal L2 bridge to the PPPoE segment (--tap, see above); the
proxy credentials are separate from the PPPoE login, and the username selects the egress session.
docker run -d --name znpppoe -p 127.0.0.1:1080:1080 -p 127.0.0.1:8081:8081 \
-e ZN_SEED="$SEED" -e ZN_CLIENT_ID=pppoe \
-e ZN_USER=<pppoe-user> -e ZN_PASSWORD=<pppoe-pass> \
-e ZN_PROXY_USER=proxy -e ZN_PROXY_PASS=<proxy-pass> \
ghcr.io/paltaio/znpppoe --dht --connections 50 \
--socks-listen 0.0.0.0:1080 --http-listen 0.0.0.0:8081
Both front ends share the password auth; the username picks the egress over the live sessions:
proxy round-robins, proxy_pppoe<K> pins session K, and
proxy_s<token> is sticky (one IP per token).
curl --socks5 proxy:<proxy-pass>@127.0.0.1:1080 https://ifconfig.me # rotates
curl --proxy http://proxy_sjob42:<proxy-pass>@127.0.0.1:8081 https://ifconfig.me # sticky
--peer <client-id> attaches the sessions to that client's L2 segment, served by
another zeronat client running segment in its [peer] section; the
frames ride a peer session between the two. It still names the server with --host
or --dht, since the server is what pairs them. See
Peer sessions.
ZN_SEED is the server's seed; it fills ZN_SECRET,
ZN_CLIENT_SECRET (derived for ZN_CLIENT_ID, which the server lists as
--client pppoe), ZN_DISCOVERY_SECRET, and ZN_PEER_SECRET;
a value set on its own wins.
Use --host <ip:port> instead of --dht for a fixed server. The ISP must
allow concurrent PPPoE sessions on the login. Linux image, amd64 and arm64.
Build
cargo build --release # dynamic binary
./build.sh # static musl binary
build.sh uses the nightly toolchain (rust-src component) for a
size-optimized static build.
CLI reference
zeronat server
--bind <ADDR> | Address to bind on (default 0.0.0.0) |
--control <PORT> | Control port (default 2222) |
--seed <64-HEX> | Seed for every credential left unset (or env ZERONAT_SEED): the network secret, the admin secret, the discovery credential, and the credential of each --client given as a bare id. A credential set on its own always wins |
--secret <64-HEX> | 32-byte hex secret (or env ZERONAT_SECRET, or derived from the seed) |
--client <ID>[:<64-HEX>] | Authorize a client id and credential (repeatable; or env ZERONAT_CLIENT_ID and ZERONAT_CLIENT_SECRET). A bare id takes its credential from the seed |
--admin-secret <64-HEX> | Independent remote admin secret (or env ZERONAT_ADMIN_SECRET, or derived from the seed); remote admin is disabled when none is set |
--id <ID> | Server identity label (default 0) |
--config <PATH> | Load listeners, routes, and identity from a config file |
--tcp <PORT> | Public TCP port to expose (repeatable) |
--udp <PORT> | Public UDP port to expose (repeatable) |
--tun | All-ports mode (Linux): forward every port except control plus ICMP to the client |
--except <PORT> | Port to keep on the host in --tun mode (repeatable) |
--exit | Exit mode (requires --tun): masquerade the client's outbound traffic through this host |
--exit-iface <IF> | Interface --exit masquerades out of (default: the default-route interface) |
--tap <NAME> | L2 bridge mode (Linux): create or attach this TAP device |
--tap-mtu <N> | TAP MTU (default 1400) |
--bridge <NAME> | Enslave the TAP to this existing bridge |
--kcp-window <N> | KCP window in segments for the UDP transport (default 256, range 32-4096; or env ZERONAT_KCP_WINDOW) |
--server dht | Publish this server's address to the DHT for discovery |
--discovery <64-HEX> | Discovery credential the DHT record is keyed by (or env ZERONAT_DISCOVERY_SECRET, or derived from the seed); required with --server dht |
--announce-ip <IP> | Public IPv4 to announce (default: auto-detected via DHT) |
--announce-port <P> | Public port to announce (default: control port) |
zeronat client
--server <ADDR> | Server control address host:port, or dht to discover via DHT |
--seed <64-HEX> | Seed for every credential left unset (or env ZERONAT_SEED): the network secret, the discovery credential, and this client's credential for --id. A credential set on its own always wins |
--secret <64-HEX> | 32-byte hex secret (or env ZERONAT_SECRET, or derived from the seed) |
--credential <64-HEX> | Client credential (or env ZERONAT_CLIENT_SECRET, or derived from the seed for --id; defaults to --secret) |
--discovery <64-HEX> | Discovery credential of the server's DHT record (or env ZERONAT_DISCOVERY_SECRET, or derived from the seed); required with --server dht |
--id <ID> | Client id. With a seed-derived credential it is sent as-is and must equal the id in the server's --client entry; otherwise it is a prefix a host suffix is appended to (default: short hostname) |
--config <PATH> | Load servers, forwards, and identity from a config file |
--tcp <SPEC> | Forward TCP: PORT | PORT:LOCALPORT | PORT:HOST:PORT, with optional +proxy and +idle=SECS (repeatable) |
--udp <SPEC> | Forward UDP, same spec as --tcp; +idle only, +proxy is TCP-only (repeatable) |
--proxy | Send a PROXY protocol v2 header on every --tcp forward |
--kcp-window <N> | KCP window in segments for the UDP transport (default 256, range 32-4096; or env ZERONAT_KCP_WINDOW) |
--transport <MODE> | auto | udp | tcp (default auto) |
--tun | All-ports mode (Linux): receive every forwarded port on local services |
--exit | Exit mode (requires --tun): route this host's IPv4 traffic through the server |
--exit-strict | Strict exit (requires --exit): delete the default routes and put IPv6 on loopback while the routes are up |
--tap <NAME> | L2 bridge mode (Linux): create or attach this TAP device |
--tap-mtu <N> | TAP MTU (default 1400) |
--bridge <NAME> | Enslave the TAP to this existing bridge |
zeronat client admin
show | Print the running client's status (default command) |
select-server <NAME> | Switch the active server profile |
add-server <NAME> <ADDR> | Add a server profile, secret from stdin; --transport auto|udp|tcp |
remove-server <NAME> | Remove a server profile; the active one is refused |
enable-forward <PROTO:PORT> | Enable a forward, e.g. tcp:443 |
disable-forward <PROTO:PORT> | Disable a forward without removing it |
add-forward <PROTO:SPEC> | Add an enabled forward, e.g. tcp:443:10.0.0.5:8443+proxy+idle=600 |
remove-forward <PROTO:PORT> | Remove a forward; connections open on it are cut |
connect [NAME] | Leave offline mode and bring up the boot session |
disconnect | Tear the session down; nothing dials until connect |
spawn-pppoe <NAME> | Bring up the named PPPoE session |
stop-pppoe <NAME> | Stop the named PPPoE session and return to the base mode |
attach-peer <PEER-ID> | Exit through the named peer; --exit routes this host's IPv4 traffic through the pair, --exit-strict hardens it, --dev <NAME> names the device |
attach-provider exit|segment [<NAME>] | Serve a capability to peers; NAME is the masquerade interface for exit (default: the default-route one) and the bridge for segment, which is required |
detach-peer <PEER-ID> | Remove the consumer slot exiting through that peer |
detach-provider exit|segment | Stop providing a capability; its pairs go down |
--socket <PATH> | Admin socket path |
zeronat admin
show | Print the server's current topology (default command) |
add-listener <PROTO:PORT> | Open a public port, e.g. tcp:443; --bind <IP> (default 0.0.0.0) |
remove-listener <PROTO:PORT> | Close a public port; a port set by --tcp/--udp is refused |
set-route <PROTO:PORT> <CLIENT-ID> | Send the port's new connections to that client |
clear-route <PROTO:PORT> | Remove the port's route |
add-client <ID> | Authorize a client; the credential is read from stdin, generated and printed with --generate, or derived from the server's seed with --derive |
set-client-secret <ID> | Replace a client's credential, taken as for add-client; its live session is dropped |
remove-client <ID> | Revoke a client and drop its live session |
disconnect <ID> | Drop a client's live session; it may reconnect |
--server <ADDR> | Server control address host:port |
--secret <64-HEX> | 32-byte admin secret (or env ZERONAT_ADMIN_SECRET, or derived from env ZERONAT_SEED, or either one read from /etc/zeronat/.env) |
zeronat derive-client
<ID> | The client id, as the server lists it under --client. Prints ZERONAT_SECRET (the network secret) and ZERONAT_CLIENT_SECRET (this client's credential) as KEY=VALUE lines |
--seed <64-HEX> | The seed (or env ZERONAT_SEED) |
--dht | Also print ZERONAT_DISCOVERY_SECRET, for a client that runs with --server dht |
Scope
Built for a single operator with one shared secret. The secret is one master key: any client can derive the server key and other client keys, so there is no per-client isolation or revocation. It is not hardened against a hostile public internet: no connection rate limiting and unbounded session tracking. Acceptable for self-owned infrastructure.
MIT, Copyright (c) 2026 Palta Studios.