Port Forwarding: Reach Devices Behind NAT (SSH, iptables, FRP)

The customer's Android box needs adb, a Windows machine needs Remote Desktop, PHP needs an Xdebug breakpoint, and they all sit behind NAT where you can't reach them. Nodekeeper builds port forwarding into the panel: a few clicks bring an internal port out to your public server, and SSH and FRP reconnect by themselves after a network drop. This guide walks through SSH, iptables and FRP with the same internal demo machine, with a screenshot and a real connection for every step, and ends with adb, Remote Desktop and Xdebug.

Cover of the port forwarding video Watch the video: reach devices behind NATYouTube · 6:01 · opens in a new tab
Who this is for

Developers and admins who need to reach devices inside a customer's or company's network from outside. No iptables or frp configuration by hand: everything is done in the panel.

What you need
  • A server with a public IP and Nodekeeper installed, called the master below
  • The internal address and port of the device you want (for example 10.255.0.25:9001)
  • For SSH: a machine inside the network the master can SSH into; for FRP: a second Nodekeeper installed inside the network
What you will have
  • Connect to master-address:port from outside and land on the internal device
  • SSH and FRP forwards reconnect by themselves after a network drop
  • Start, stop and check rules any time in the panel

First: which of the three methods

Forwarding is under System Services → Forwarding and has three methods. Pick one from the table and follow its section below:

MethodWhenOn the customer sideKeep in mind
SSHThe master can SSH into a machine inside the customer networkNothing to installCan also reach services that only listen on 127.0.0.1
iptablesThe master can already reach the target directly (for example over a private network link)Nothing to installForwarded by the kernel; cannot forward to 127.0.0.1; other firewall rules on the master may block it
FRPThe customer network has no way in at allA Nodekeeper inside the network connects out to the masterNo inbound port and no port mapping needed on the customer side
Terms explained
Master
The public server with Nodekeeper installed. Computers outside connect to it.
Internal network / NAT
A company's or customer's LAN. Devices there can reach the internet but nobody outside can reach them: they have no public address and sit behind the router's address translation (NAT).
Port forwarding
Opening a port on the master and passing whatever connects to it on to a port of an internal device.
Local Bind IP / Port
The port the master opens to the outside. 0.0.0.0 means any address of the master.
Destination IP / Port
The device and port you finally want. With SSH the destination is seen from the SSH machine, so 127.0.0.1 means that machine itself.
  1. Open the forwarding page

    Log in to the master's panel and open System Services → Forwarding in the left menu. Add Forwarding and Batch Import are at the top right.

    The Port Forwarding page: a search box, Batch Import and Add Forwarding buttons, and an empty rule list
    You should see:

    An empty rule list. If it says you have no port-forwarding permission, ask an administrator to grant it to your user group.

  2. Meet the demo setup

    The three sections below use the same demo machine inside the customer network (10.255.0.25). It runs a small service: port 9001 is open to the internal network, 9000 listens only on its own 127.0.0.1. Connecting directly from outside times out:

    The outside computer connects to the internal address directly
    $ nc -v 10.255.0.25 9001
    nc: connectx to 10.255.0.25 port 9001 (tcp) failed: Operation timed out

Method 1: SSH (nothing to install on the customer side)

The master logs in to the internal machine over SSH and brings the port out through that encrypted connection. All you need on the customer side is a machine the master can SSH into.

Terms explained
SSH tunnel
Using an SSH login connection to carry traffic for other ports too. The connection is encrypted; if it drops, Nodekeeper reconnects it.
  1. Add a forwarding rule with type SSH

    Click Add Forwarding, set Forward Type to SSH, then fill in:

    • Name: anything that helps you recognise it, for example lan-demo-ssh.
    • SSH Host, SSH Port, SSH Account: the internal machine's SSH address, port and account (the master must be able to reach it). Set Login Method to Password or Private Key and paste the password or the whole key; it is not shown again after saving, and leaving it blank when editing keeps it.
    • Local Bind IP 0.0.0.0, Local Bind Port 19000: the port the master opens.
    • Destination IP 127.0.0.1, Destination Port 9000: seen from the SSH machine, that is its own port 9000. Other internal machines it can reach work here too.
    • Enable Compression only affects SSH forwards and helps on slow links; leave the multi-node sync group at no sync.
    The Add Forwarding dialog with Forward Type SSH: name lan-demo-ssh, SSH host 10.255.0.25, port 2222, account demo, password login (field empty), local bind 0.0.0.0:19000, destination 127.0.0.1:9000, no sync group
  2. Save, then Start

    Click Save: the rule appears in the list as Stopped. Click Start on that row; if the status doesn't change, refresh the list. View shows the whole rule and when it was last active.

    The forwarding list: lan-demo-ssh, type SSH, local bind 0.0.0.0:19000, destination 127.0.0.1:9000, status Stopped, with View, Edit, Start and Delete
    Forwarding Details: name, type SSH, local bind and destination, status Running, SSH host and account, login method, created and last active times
    You should see:

    The status is Running and Last Error is empty.

Something wrong? Check this table

What you seeWhyWhat to do
It never gets to Running and Last Error shows somethingThe master cannot reach the SSH machine, or the account, password or key is wrong.Check SSH host, port and login against Last Error; Edit, Save and Start again.
Running, but still unreachable from outsideThe master's firewall doesn't allow the local bind port. Forwarding does not open ports for you.Open the port as in the next section.

Open the port, then test from outside (all three methods)

A forwarding rule only forwards; it does not open the port in the firewall. Without that, outside computers still can't connect.

  1. Allow the forwarding ports in the System Firewall

    In the left menu open System Security → System Firewall and click Open port: Direction Inbound, Action Allow, Port 19000, End Port 19002 (the demo ports of all three methods at once), Proto TCP, a Description that says what it is for, then Save.

    If only you need it, put your own public IP in Source IP / CIDR so nobody else can connect. If the master is a cloud server, open the same ports in the provider's security group too.

    The System Firewall Open port form: Direction Inbound, Action Allow, Port 19000 to 19002, Proto TCP, Description port forwarding demo, Source IP / CIDR empty, Save at the bottom right
  2. Connect to the master's port 19000 from outside

    On a computer outside, connect to port 19000 of the master with nc (or telnet) and type a line. The internal demo machine gets it at once:

    outside computer → master 19000 → SSH → demo machine 127.0.0.1:9000
    $ nc master.example.com 19000
    Hello! This is the demo machine inside the customer network, you reached port 9000. Type something:
    hi, I am outside, coming in over the SSH tunnel
    the internal demo machine got: hi, I am outside, coming in over the SSH tunnel
    
    # on the demo machine
    05:34:12 new connection from 127.0.0.1:51388 (port 9000)
    05:34:14   received: hi, I am outside, coming in over the SSH tunnel
    05:34:17 disconnected: 127.0.0.1:51388
    You should see:

    The outside computer gets the demo machine's reply and the demo machine logs the connection. SSH forwarding works.

Method 2: iptables (forwarded by the kernel)

If the master can already reach the target directly, for example over a private network link, let the kernel forward the traffic with no program in between.

Terms explained
Kernel forwarding (DNAT)
The Linux kernel rewrites the destination of packets arriving at a master port and sends them straight to the target. There is no program in the middle, so nothing needs to reconnect.
  1. Add a forwarding rule with type iptables

    Set Forward Type to iptables, Local Bind IP 0.0.0.0, Local Bind Port 19001; Destination IP is the demo machine's internal address 10.255.0.25, Destination Port 9001. Save, then Start.

    The Add Forwarding dialog with Forward Type iptables: name lan-demo-nat, local bind 0.0.0.0:19001, destination 10.255.0.25:9001, no sync group
  2. Connect to 19001 from outside

    Port 19001 was opened in the previous section. Connect:

    The forwarding list: lan-demo-nat (iptables, 0.0.0.0:19001 → 10.255.0.25:9001) and lan-demo-ssh (SSH, 0.0.0.0:19000 → 127.0.0.1:9000), both Running
    outside computer → master 19001 → kernel → demo machine 10.255.0.25:9001
    $ nc master.example.com 19001
    Hello! This is the demo machine inside the customer network, you reached port 9001. Type something:
    hi again, this time via iptables
    the internal demo machine got: hi again, this time via iptables
    
    # on the demo machine
    05:34:20 new connection from 10.255.0.1:63384 (port 9001)
    05:34:22   received: hi again, this time via iptables
    05:34:24 disconnected: 10.255.0.1:63384
    You should see:

    Both rules are Running in the list, and both the outside computer and the demo machine show the exchange.

Something wrong? Check this table

What you seeWhyWhat to do
Destination 127.0.0.1 doesn't workThe iptables method cannot forward to 127.0.0.1.If the target only listens on itself, use the SSH method.
Running, but unreachable from outsideOther firewall rules on the master block the forward, or the master cannot actually reach the target.First check on the master that the target address and port are reachable; then check the master's other firewall rules. If it can't reach the target, use SSH or FRP.

Method 3: FRP (the customer network has no way in)

Both methods above need the master to reach the customer network. When it can't at all, use FRP: put a Nodekeeper inside the customer network and let it connect out to the master. The customer side opens no inbound port and needs no port mapping.

Terms explained
FRP server (frps)
Installed on the master; waits for the internal machine to connect.
FRP client
Runs automatically on the internal Nodekeeper when you add an FRP forwarding rule, and connects out to the master's server.
Auth Token
The shared password between server and client; both must match. Treat it like a password.
Remote Port (remotePort)
The port the master opens; outside computers connect to it.
Local IP / Local Port (localIP / localPort)
The target, seen from the internal Nodekeeper.
  1. Install the FRP server on the master

    In the master's panel open System Services → FRP. If FRP is not installed yet, the page says so; click Install FRP Server.

    The FRP page: FRP is not installed, a one-line description and the Install FRP Server button
  2. One-click install

    The installer detects the architecture, downloads the latest FRP, generates a random port and token and registers it as a system service. If GitHub is slow where you are, fill in a GitHub Mirror URL. Click Start Install and wait for it to finish.

    The Install FRP Server dialog: Configure, Installing, Complete; it auto-detects the architecture, downloads the latest version, generates a random port and token and registers a system service; an optional GitHub Mirror URL field; Start Install
  3. Start it, note the port and token, open the port

    After installing, click Start: the status becomes Running. Note the TCP port under Ports and the Auth Token; the internal side needs them. Open this listening port in the System Firewall as well (the TCP port for the TCP protocol; for KCP or QUIC also open UDP on the KCP / QUIC port shown, 15332 and 15333 in the screenshot).

    FRP Management: FRP Server (frps) Running, version 0.72.0, ports TCP / KCP / QUIC 15332, Auth Token redacted; Start, Stop, Edit Config, View Log and Reinstall at the top right
    You should see:

    Status Running, with the port and token shown.

  4. Add an FRP rule on the internal Nodekeeper

    Switch to the panel of the Nodekeeper inside the customer network and install FRP there the same way under System Services → FRP (without it, adding an FRP rule says the FRP service is not installed). Then System Services → Forwarding → Add Forwarding, Forward Type FRP:

    • FRP Server Address: the master's address; FRP Server Port and Auth Token: copied from the previous step. Transport Protocol TCP.
    • Remote Port (remotePort) 19002: the port the master opens.
    • Local IP (localIP) 10.255.0.25, Local Port (localPort) 9001: the target.

    Save, then Start.

    The Add Forwarding dialog with Forward Type FRP: name lan-demo-frp, FRP server address (redacted), FRP server port 15332, auth token empty, transport protocol TCP, remote port 19002, local IP 10.255.0.25, local port 9001
  5. Connect to the master's port 19002 from outside

    On the internal Nodekeeper the FRP rule is Running. From outside, connect to port 19002 of the master:

    The internal Nodekeeper's forwarding list: lan-demo-frp, type FRP (TCP), remote port 19002, destination 10.255.0.25:9001 → master (address redacted):15332, Running
    outside computer → master 19002 → FRP → demo machine 10.255.0.25:9001
    $ nc master.example.com 19002
    Hello! This is the demo machine inside the customer network, you reached port 9001. Type something:
    hi, this time via FRP
    the internal demo machine got: hi, this time via FRP
    
    # on the demo machine
    05:34:29 new connection from 10.255.0.25:36324 (port 9001)
    05:34:31   received: hi, this time via FRP
    05:34:33 disconnected: 10.255.0.25:36324
    You should see:

    The internal demo machine gets it again, without any inbound port opened on the customer side.

Something wrong? Check this table

What you seeWhyWhat to do
Adding an FRP rule says the FRP service is not installedFRP is not installed on this internal Nodekeeper yet.Click Go to install FRP, install it, then add the rule.
The FRP rule starts but Last Error shows somethingIt cannot reach the master's FRP server: wrong address, port or token, or the master's firewall doesn't allow the FRP port.Copy the port and token again from the master's FRP page; open that port in the master's System Firewall.
Running, but master port 19002 is unreachable from outsideThe master doesn't allow the remote port.Open 19002 in the master's System Firewall (and the cloud security group).

Real use: adb, Remote Desktop, Xdebug

Once a rule works, every client connects to master-address:port-on-the-master. The examples assume you have already forwarded the target port to the master as shown above.

  1. adb for an Android box

    Forward the box's adb port (usually 5555) to a master port such as 19005, then on your computer:

    adb connect master.example.com:19005
    adb devices
    You should see:

    adb devices lists master.example.com:19005, and it works as if it were plugged in locally.

  2. Windows Remote Desktop

    Forward Windows' port 3389 to a master port (for example 19006) and enter master.example.com:19006 as the computer in the Remote Desktop client.

  3. PHP Xdebug breakpoints (the other direction)

    With Xdebug the server connects to your IDE, the opposite direction: on the Nodekeeper in your network add an FRP rule that brings your IDE's port 9003 to a remote port on the master, then point PHP at that master port. In php.ini (remote port 19003 here):

    xdebug.mode=debug
    xdebug.client_host=master.example.com
    xdebug.client_port=19003
    This lineWhat it does and why
    xdebug.mode=debugTurns on step debugging.
    xdebug.client_host=master.example.comPHP connects to the master instead of your computer (your computer is behind NAT, PHP can't reach it).
    xdebug.client_port=19003The remote port of that FRP rule on the master; it carries the connection back to your IDE's 9003.

When you are done

  • Stop the rule and close the firewall port when you are done: Stop or Delete it in the list, then remove the allow rule in the System Firewall. An open port stays visible to scanners.
  • Drops take care of themselves: if an SSH or FRP forward drops, it reconnects once the network is back.
  • Many rules: Batch Import takes one rule per line with fields separated by |; the dialog shows the format and an example for each method. You can also tick several rules in the list and start, stop or delete them together.

Frequently asked questions

Which method should I pick?
If the master can SSH into the machine, use SSH: nothing to install on the customer side. If the master reaches the target directly and you don't need 127.0.0.1, iptables works. If there is no way in at all, use FRP.
What happens when the network drops?
SSH and FRP forwards reconnect by themselves when the network is back. iptables forwarding is done by the kernel and has no connection to restore.
Does the customer have to open a port or set up port mapping?
SSH needs the master to reach that SSH machine; FRP needs nothing, because the internal Nodekeeper connects out; iptables needs the master to reach the target directly.
The rule is running. Why can't I connect from outside?
Most often the master's firewall doesn't allow the local bind (or remote) port. Forwarding does not open ports for you: allow it under System Security → System Firewall, and in the cloud security group.
How do I make it reachable only for me?
Fill Source IP / CIDR in the firewall allow rule with your own public IP; stop the rule and remove the allow rule as soon as you are done.
Can member accounts use forwarding?
An administrator has to grant the port-forwarding permissions to their user group; without them the forwarding page says to contact an administrator.