Reach a Private LAN
Reach a NAS, a database or an admin page on a private network, from anywhere, through one machine on that network. The machine runs nfltr up with one service per LAN host and port you want to reach, and forwards nothing else. Your laptop reaches a service with nfltr cat forward, as a local port.
Goal
From your laptop, curl a web server on the LAN at http://192.168.1.20:8080/, which has no public address.
Prerequisites
- A machine on the LAN (call it the LAN machine) with the
nfltrCLI, enrolled in your account withnfltr config login. - Your laptop with the
nfltrCLI, enrolled in the same account the same way.
1. Find the target's LAN address
Use the host you want to reach. In this tutorial it is a small web server on the LAN machine itself, at the LAN machine's own address:
$ LAN_IP=$(ipconfig getifaddr en0); echo "$LAN_IP"
192.168.1.20
$ LAN_IP=$(hostname -I | awk '{print $1}'); echo "$LAN_IP"
192.168.1.20
$ echo 'hello from the LAN' > index.html
$ python3 -u -m http.server 8080
Serving HTTP on :: port 8080 (http://[::]:8080/) ...
2. Publish the LAN host and port
On the LAN machine, write a config with one service per destination. forward: is the LAN host and port that service reaches; the agent dials only the targets in the file, so nothing else on the LAN is reachable:
lan.yaml, with the LAN host's address in place of 192.168.1.20:
agent: home-lan
services:
web: { tcp: 8080, forward: "192.168.1.20:8080" }
Or write it from the address found in step 1:
$ printf 'agent: home-lan\nservices:\n web: { tcp: 8080, forward: "%s:8080" }\n' "$LAN_IP" > lan.yaml
$ nfltr up -c lan.yaml
Connected — waiting for requests... (press Ctrl+C to stop)
SERVICE TYPE AGENT ACCESS
web tcp home-lan/web nfltr cat forward home-lan/web --listen 127.0.0.1:<local-port>
More destinations are more services: nas: { tcp: 445, forward: "nas.lan:445" }, db: { tcp: 5432, forward: "10.0.0.5:5432" }. A UDP destination (DNS, a game server) is a service with udp: true, reached with nfltr cat forward --udp. Leave it running (tmux, screen or a service manager).
3. Connect from the laptop
nfltr cat forward opens a local port whose every connection is one session to the service:
$ nfltr cat forward home-lan/web --listen 127.0.0.1:18080
connect forward: listening -> home-lan/web on 127.0.0.1:18080
$ curl -s http://127.0.0.1:18080/
hello from the LAN
Browsers, git, psql or any TCP client use the local port the same way. For a single connection from a script or an ssh ProxyCommand, nfltr cat pipe home-lan/web is the session on stdin and stdout. nfltr up on the laptop can hold such mappings too (its connect: section), so a set of LAN services is one local port each, started together.
Whole-subnet routing and a SOCKS5 proxy are not offered: each destination is named on the LAN machine. Machines enrolled in an organisation can make these sessions end to end encrypted (e2ee: true and allow_group: on the service).
4. Clean up
Press Ctrl+C in the nfltr cat forward terminal, then in the nfltr up terminal on the LAN machine (and stop the demo web server).
# Ctrl+C in the nfltr cat forward terminal
# Ctrl+C in the nfltr up terminal
If it goes wrong
| You see | Meaning and fix |
|---|---|
"event":"error","code":"not_found" from nfltr cat forward | No agent home-lan with a service web is connected for your account: nfltr up is not running on the LAN machine, its agent: differs, or it uses a key of another account. |
curl gets Empty reply from server, and nfltr up logs that web is down | The LAN machine cannot connect to the forward: target: check the address and port from the LAN machine (nc -vz 192.168.1.20 8080). |
Error: … cannot reach the relay | The machine cannot reach the relay. Unset NFLTR_SERVER to use the hosted relay, or fix the address. |