The gateway how-to said the mesh firewall baseline gates port forwards and that a fips.d drop-in restricts them. It does neither: the gateway rewrites a forwarded connection's destination in prerouting, so the packet takes the forward path, while fips.nft and its drop-ins hook input only. With the baseline loaded, every mesh node that reaches the gateway reaches every port forward. The how-to now says so and gives a restriction that works: a separate table with a forward-hook chain that matches the post-DNAT target address and port, scoped to the mesh interface through its own fips_if define, ending in a drop of other translated connections, loaded alongside the baseline through a fips-firewall.service drop-in. On OpenWrt it points at the packaged zone's src fips rule instead. The mesh firewall how-to and the fips.nft header say port forwards are outside the baseline, and the how-to's TUN rename section says to change the restriction's fips_if too. The gateway troubleshooting step and the host-a-service tutorial no longer describe the input baseline as gating port forwards. Also corrected: the gateway design document attributed the virtual-IP source on replies to the per-mapping SNAT, which only sees the first packet of a new flow sourced from a mapped mesh address; conntrack reversing the DNAT is what does it. It also said port forwards are validated on every config reload, but the gateway has no reload. The configuration reference said the gateway terminates forwarded connections; the kernel translates and forwards them.
19 KiB
Deploy fips-gateway (Manual Linux-Host Setup)
fips-gateway is a separate service that runs alongside the FIPS
daemon and bridges a non-FIPS LAN to the FIPS mesh in two
independent directions: outbound (LAN clients reach mesh
services through DNS proxy + virtual-IP NAT) and inbound (mesh
peers reach LAN services through 1:1 port forwards on fips0).
This guide covers the manual Linux-host deployment path —
wiring DNS forwarding, route distribution, and firewall integration
on a server or non-OpenWrt router by hand.
Running OpenWrt? Use the tutorial instead. The OpenWrt ipk ships with the
gateway:block pre-populated and the init script automates dnsmasq forwarding, RA route distribution, and the global IPv6 prefix onbr-lan. The OpenWrt path is the canonical deployment of this feature; this how-to is the secondary path for operators with a different LAN-edge box (a Linux server already serving DHCP/DNS, a custom router distribution, etc.).
For the gateway design (NAT pipeline, virtual IP pool lifecycle, DNS
resolution flow), see ../design/fips-gateway.md.
For the full gateway.* configuration block, see the
Gateway section of
the configuration reference. For the fips-gateway binary's CLI
flags, see ../reference/cli-fips-gateway.md.
The two halves
The gateway exposes two independent features that share a common
control plane (the same binary, the same nftables table inet fips_gateway, the same control socket /run/fips/gateway.sock, the
same gateway.* config block). You can configure either half on its
own or both together.
-
Outbound gateway (LAN → mesh). Non-FIPS LAN workstations resolve
<npub>.fipsnames against the gateway's DNS listener and receive AAAA answers from the gateway's virtual-IP pool. Outbound traffic to those addresses is DNAT'd to the real mesh address and SNAT'd (masqueraded) ontofips0under the gateway's mesh identity. The audience is unmodified LAN clients. -
Inbound gateway (mesh → LAN). A static
(listen_port, proto) → [target_addr]:target_porttable — configured ingateway.port_forwards[]— exposes selected LAN services to the mesh as<gateway-npub>.fips:<listen_port>. Mesh peers connect to the gateway's mesh address; the gateway DNATs to the LAN target and masquerades on the LAN side so return traffic flows through conntrack. The audience is mesh peers reaching a service that happens to live on this LAN.
The two halves are independent. Configure the outbound half if you want LAN clients to reach the mesh; configure the inbound half if you want mesh peers to reach into the LAN; configure both if you want both.
Common gateway-host setup
Both halves require the same host preparation. Work through this section first, then jump to whichever half (or both) you need.
FIPS daemon prerequisites
The gateway runs alongside a fips daemon on the same host:
- The daemon must be running with the TUN adapter enabled (the
fips0interface must exist). - The daemon's DNS resolver must be enabled (
dns.enabled: true, default) and reachable fromfips-gateway. By default that means[::1]:5354(IPv6 loopback). The gateway's defaultdns.upstreammatches this; a v4 upstream like127.0.0.1:5354cannot reach a daemon bound on[::1]:5354because Linux IPv6 sockets bound to explicit::1do not accept v4-mapped traffic.
If the daemon is not yet running with these features, set up the daemon first — see persistent-identity.md and ../reference/configuration.md.
Kernel sysctls
sudo sysctl -w net.ipv6.conf.all.forwarding=1
sudo sysctl -w net.ipv6.conf.all.proxy_ndp=1
forwarding lets the host route IPv6 packets between the LAN
interface and fips0. proxy_ndp lets the gateway answer Neighbor
Solicitation requests for virtual-pool addresses so LAN clients can
resolve their link-layer addresses (only relevant for the outbound
half, but harmless if you only run the inbound half).
Persist via a drop-in:
sudo tee /etc/sysctl.d/60-fips-gateway.conf <<'EOF'
net.ipv6.conf.all.forwarding = 1
net.ipv6.conf.all.proxy_ndp = 1
EOF
sudo sysctl --system
Capability
fips-gateway requires CAP_NET_ADMIN to manage its nftables table
(inet fips_gateway) and proxy-NDP entries. The packaged systemd
unit (fips-gateway.service) runs as root, which satisfies this. For
non-package installs, set the file capability:
sudo setcap cap_net_admin+ep /usr/bin/fips-gateway
Pool route
At startup fips-gateway adds local <pool-cidr> dev lo to the
local routing table. This tells the kernel to accept packets
destined for pool addresses as locally-owned, enabling the NAT
processing path. The route is cleaned up on shutdown. You do not
need to install it manually; if you see "destination unreachable"
errors for pool addresses on the gateway host, verify the route is
present:
ip -6 route show table local | grep <pool-cidr>
Minimum configuration
In /etc/fips/fips.yaml, populate the gateway block with at minimum
enabled: true, pool, and lan_interface:
gateway:
enabled: true
pool: "fd01::/112"
lan_interface: "enp3s0"
Pick a pool CIDR that does not overlap with any address space in
use on the LAN. The gateway routes the whole prefix to itself, so a
name whose mesh address (in fd00::/8) lies inside it cannot be
reached and gets SERVFAIL; a /112 makes that vanishingly unlikely.
The /112 size yields 65 535 usable
addresses, the most the pool uses whatever the CIDR width. The
gateway holds at most 1000 live mappings at once and admits new
names at up to 10 per second after a burst of 50. At 1000 live
mappings, a new name replaces the oldest mapping that has never
carried traffic, and gets SERVFAIL only when every mapping has
carried traffic; a new name beyond the rate limit gets SERVFAIL.
This minimum config is enough to start the gateway. The dns.* block
is optional and defaults to listen: "[::1]:5365" and
upstream: "[::1]:5354". The full block — including dns.*,
pool_grace_period, conntrack.*, and port_forwards[] — is
documented in
../reference/configuration.md#gateway-gateway.
Start the service
sudo systemctl enable --now fips-gateway
Verify the unit came up:
sudo systemctl status fips-gateway
sudo journalctl -u fips-gateway -e
The startup log will report Gateway config loaded,
DNS upstream is reachable, Created nftables table 'fips_gateway',
and finally fips-gateway running. The unit's ExecStartPre waits up
to 30 s for fips0 to appear, which covers the cold-boot race where
the daemon is still bringing up its TUN.
Configure the outbound half
The outbound half lets LAN clients resolve .fips names and reach
mesh destinations. Three operator decisions are involved: pool CIDR,
DNS listen address, and how LAN clients learn the route to the pool
and the resolver address.
Choose the pool CIDR
gateway:
pool: "fd01::/112"
Constraints:
- Must not overlap with any LAN-side IPv6 prefix already in use.
- A name whose mesh address (in
fd00::/8) lies inside the pool prefix getsSERVFAIL, since the gateway routes the whole prefix to itself; a/112makes that vanishingly unlikely. /112is the practical width — wider just wastes address space because the pool never uses more than 65 535 addresses. Narrower is fine if you want a smaller pool; one narrower than/118(1023 usable addresses) runs out before the 1000-mapping ceiling is reached, and one smaller than 1000 + 10 x (TTL + grace) addresses (2,200 at the defaults, so any pool narrower than a/116) can be exhausted by one LAN host naming new names; the gateway warns at start. After a crash or a kill (not a clean stop or restart), a pool with fewer than 512 free addresses (a/119or narrower, or a/118with more than about 500 addresses in use) refuses every new name for the DNS TTL plus the grace period, 2 minutes at the defaults, while it waits out answers the previous run may have given.
Choose the DNS listen address
gateway:
dns:
listen: "[::1]:5365"
upstream: "[::1]:5354"
ttl: 60
Common cases:
- Another resolver on the host (the canonical case): the default
listen: "[::1]:5365"is loopback-only on an unprivileged port, so it never conflicts with dnsmasq, systemd-resolved, or BIND holding 53. Configure the existing resolver to forward.fipsqueries to[::1]:5365and you are done — this is what the OpenWrt ipk does automatically. On OpenWrt the init script readsgateway.dns.listenand points dnsmasq at whatever port it sets. - No other resolver on the host: set
listen: "[::]:53"explicitly and LAN clients can query the gateway directly. - systemd-resolved is on port 53: the default already side-steps
this — leave the listen address at
[::1]:5365and configure the stub or a small forwarder to delegate.fipsto the gateway. If you would rather have the gateway on 53 directly, disable the systemd stub listener (DNSStubListener=noin/etc/systemd/resolved.conf) and switchlistento"[::]:53". See troubleshoot-gateway.md. - Bind on the LAN address only:
listen: "192.168.1.1:53"exposes the resolver only to LAN clients, not loopback.
The gateway returns REFUSED for any non-.fips query — clients
that point at it directly need a fallback resolver, or you should
front it with a stub forwarder.
Distribute the route to LAN clients
Each LAN client must route the gateway's pool CIDR to the gateway's LAN-side IPv6 address. Three options, in order of preference for production:
-
RA Route Information Option (RFC 4191). If the LAN's RA daemon (
radvd,dnsmasq --enable-ra, OpenWrt'sodhcpd) supports publishing route options, configure it to advertise the pool CIDR with the gateway as next-hop. Clients pick this up automatically. -
Static route on the LAN router. If clients route through a central LAN router, add a static route entry there — the router then handles forwarding to the gateway. The exact syntax depends on the router OS.
-
Per-host static route (testing or single-client deployments):
sudo ip -6 route add fd01::/112 via fe80::<gateway-link-local>%<iface> # or, if the gateway has a stable global LAN address: sudo ip -6 route add fd01::/112 via <gateway-lan-addr>
Distribute the resolver to LAN clients
LAN clients also need to send .fips queries to the gateway. Two
patterns:
-
Forward
.fipsfrom the LAN's main resolver. If the LAN runs Pi-hole, Unbound, dnsmasq, or systemd-resolved as the central resolver, configure a conditional forward forfips.. Unbound example:forward-zone: name: "fips." forward-addr: <gateway-lan-addr>@53dnsmasq example:
server=/fips/<gateway-lan-addr>Clients keep their existing DNS settings; only
.fipsqueries are diverted. -
Point clients directly at the gateway. Simpler for testing, but the gateway returns
REFUSEDfor non-.fipsqueries, so each client must also have a fallback resolver configured.
Verify the outbound path
From a LAN client:
dig @<gateway-lan-addr> hostname.fips AAAA
# Expect an AAAA from the pool CIDR
ping6 hostname.fips
# Should succeed via the gateway
If either step fails, see troubleshoot-gateway.md.
Configure the inbound half
The inbound half exposes a LAN-side service to mesh peers. Configured
under gateway.port_forwards[]:
gateway:
port_forwards:
- listen_port: 8080
proto: tcp
target: "[fd12:3456::10]:80"
- listen_port: 2222
proto: tcp
target: "[fd12:3456::20]:22"
- listen_port: 5353
proto: udp
target: "[fd12:3456::10]:53"
Field reference:
listen_port— port on the gateway'sfips0mesh-side address that mesh peers connect to. Must be non-zero. Each(listen_port, proto)pair must be unique across the list (the same port on TCP and UDP is allowed; the same port twice on the same proto is rejected at config-load time).proto—tcporudp.target— IPv6 LAN destination as[addr]:port. IPv4 targets are rejected at parse time by the YAML deserializer (the field is typedSocketAddrV6). If the LAN host is reachable only by IPv4, put a small IPv6-aware reverse proxy in front of it on the gateway itself.
Worked example: HTTP and DNS
Suppose the gateway runs on a LAN with an HTTP server at
[fd12:3456::10]:80 and a recursive resolver at
[fd12:3456::10]:53, and you want mesh peers to reach them as
<gateway-npub>.fips:8080 (HTTP) and <gateway-npub>.fips:5353
(DNS). Add to the gateway's fips.yaml:
gateway:
port_forwards:
- listen_port: 8080
proto: tcp
target: "[fd12:3456::10]:80"
- listen_port: 5353
proto: udp
target: "[fd12:3456::10]:53"
Reload:
sudo systemctl restart fips-gateway
From any mesh peer (the host name gateway is whatever the gateway's
npub maps to in the local hosts file or via Nostr advert):
curl http://gateway.fips:8080/
dig @gateway.fips -p 5353 example.com A
Each mesh-side request enters fips0 on the listen port, gets DNAT'd
to the LAN target, and the LAN-side masquerade rule rewrites the
source to the gateway's LAN address so return traffic flows back
through conntrack.
Compose with the mesh firewall
The mesh firewall baseline (/etc/fips/fips.nft, see
enable-mesh-firewall.md) does not gate
port forwards. The gateway rewrites a forwarded connection's
destination to the LAN target in its prerouting chain, so the kernel
routes the packet through the forward hook to the LAN. The baseline
hooks input only, and drop-ins under /etc/fips/fips.d/ are included
into that same input chain, so neither sees forwarded traffic. With
the baseline loaded and nothing else, every mesh node that can reach the
gateway can reach every configured port forward, and a fips.d rule
such as ip6 saddr <addr> tcp dport 8080 accept has no effect on it.
To restrict who can use a port forward, load a table of your own with a
forward-hook chain. For the worked example above, allowing one mesh
node to use both forwards:
# /etc/fips/port-forwards.nft
# The node's tun.name, as in /etc/fips/fips.nft.
define fips_if = "fips0"
define allowed_peers = { fd97:1111:2222:3333:4444:5555:6666:7777 }
add table inet fips_port_forwards
flush table inet fips_port_forwards
table inet fips_port_forwards {
chain forward {
type filter hook forward priority 0; policy accept;
# Only connections arriving from the mesh.
iifname != $fips_if return
ct state established,related accept
# Filter rules see the packet after the gateway rewrote its
# destination: match the target address and port, not listen_port.
ip6 saddr $allowed_peers ip6 daddr fd12:3456::10 tcp dport 80 accept
ip6 saddr $allowed_peers ip6 daddr fd12:3456::10 udp dport 53 accept
# Every other port-forwarded connection from the mesh.
ct status dnat counter drop
}
}
Connections from the mesh that the gateway did not translate, and LAN
clients' own connections out to the mesh and their replies, pass this
chain unchanged. A drop in any chain on the forward hook is final, so
the order of this table against the gateway's own inet fips_gateway
table does not matter.
Load it with the firewall service, so it comes and goes with the baseline:
sudo systemctl edit fips-firewall.service
[Service]
ExecStartPost=/usr/sbin/nft -f /etc/fips/port-forwards.nft
ExecReload=/usr/sbin/nft -f /etc/fips/port-forwards.nft
ExecStopPost=-/usr/sbin/nft delete table inet fips_port_forwards
Then sudo systemctl reload-or-restart fips-firewall.service. The
drop counter shows refused connections:
sudo nft list table inet fips_port_forwards
On OpenWrt the packaged firewall zone already passes port forwards
through fw4's forward chain; restrict them there with a src fips
rule matching the target's port instead (see
packaging/openwrt-ipk/README.md).
Verify the inbound path
From a mesh peer (any FIPS node):
curl -v http://<gateway-npub>.fips:8080/
A successful response confirms the full path: mesh ingress on
fips0, DNAT to the LAN target, LAN-side masquerade, and conntrack-
tracked return. If it fails, see
troubleshoot-gateway.md.
Operate and verify
fips-gateway exposes its own control socket at
/run/fips/gateway.sock, separate from the daemon's
/run/fips/control.sock. There is no fipsctl gateway subcommand —
talk to it directly:
echo '{"command":"show_gateway"}' | sudo nc -U /run/fips/gateway.sock
echo '{"command":"show_mappings"}' | sudo nc -U /run/fips/gateway.sock
show_gateway returns pool counters (pool_total, pool_allocated,
pool_active, pool_draining, pool_free), nat_mappings,
dns_listen, uptime_secs, and the active config snapshot.
show_mappings returns the per-allocation list with virtual IP, mesh
address, npub-derived node_addr, dns name, state (Allocated,
Active, Draining), session count, and ages. For the full schema
see ../reference/control-socket.md#gateway-command-catalog.
The journal is the other primary signal:
sudo systemctl status fips-gateway
sudo journalctl -u fips-gateway -e
Expect MappingCreated/MappingRemoved debug lines as DNS-driven
allocations come and go (run with --log-level debug to see them),
and Final pool status on shutdown. Errors in adding NAT rules or
proxy-NDP entries surface here.
See also
- ../tutorials/deploy-fips-gateway.md — the canonical, package-driven OpenWrt deployment path.
- ../design/fips-gateway.md — gateway design, NAT pipeline, virtual IP pool lifecycle, security considerations.
- Gateway section of
the configuration reference — full
gateway.*block. - ../reference/cli-fips-gateway.md —
fips-gatewaybinary CLI flags. - Gateway command catalog
in the control-socket reference — JSON schema for
show_gatewayandshow_mappings. - troubleshoot-gateway.md — diagnostic recipes grouped by half.
- enable-mesh-firewall.md — mesh-firewall baseline and drop-ins (needed when exposing inbound ports).