> ## Documentation Index
> Fetch the complete documentation index at: /llms.txt
> Use this file to discover all available pages before exploring further.

# Port forwarding

> Open a raw TCP or UDP port on a machine, for databases, game servers, and anything that is not HTTP.

A raw port forward opens a TCP or UDP port on the machine's public address and sends it straight to a port inside the machine. Use it for a Postgres database, an SSH daemon, a game server, or any other protocol that is not HTTP.

## How it works

[Proxies](/guides/proxies.md) terminate TLS and route **HTTP** by domain, which suits web apps and APIs. A raw port forward works one layer down: the packets pass through untouched.

```text
myapp.boxd.sh:48211  ->  your machine, port 5432 (Postgres)
```

The public port is allocated for you from the **40000 to 60000** range. The endpoint is the machine's existing DNS name (`<machine>.boxd.sh`, which resolves to the proxy IP) on that allocated port. A machine in [New York](/guides/regions.md) uses `<machine>.nyc.boxd.sh`.

## Add a raw port forward

From your laptop:

```bash
boxd machine proxy add --vm myapp --port 5432 --raw
```

```text
published myapp.boxd.sh:48211 → 5432 (tcp)
```

Anything listening on `5432` inside the machine is now reachable at `myapp.boxd.sh:48211`. For example, a Postgres client:

```bash
psql -h myapp.boxd.sh -p 48211 -U postgres
```

## Protocols

A forward is TCP by default. Use `--udp` for UDP, or pass both flags to serve TCP **and** UDP on the same allocated public port:

```bash
boxd machine proxy add --vm myapp --port 5432 --raw             # TCP (default)
boxd machine proxy add --vm myapp --port 9999 --raw --udp       # UDP
boxd machine proxy add --vm myapp --port 7777 --raw --tcp --udp # both, one public port
```

Adding a forward again for a port that already has one keeps the same public port and updates the protocol set.

## List and remove

```bash
boxd machine proxy list                   # subdomain proxies and raw port forwards
boxd machine proxy remove 5432 --vm myapp # remove a forward, free the public port
```

## From inside a machine

The in-machine CLI has its own command for raw port forwards, `boxd machine expose`. It targets the machine you are in unless you name another one:

```bash
boxd machine expose 5432            # the current machine
boxd machine expose myapp2 5432     # another machine
boxd machine expose 7777 --tcp --udp
boxd machine expose --list          # all your raw port forwards
boxd machine expose 5432 --remove   # remove a forward
```

`boxd machine expose` does not exist in the laptop CLI. See the [CLI reference](/cli/commands.md#raw-tcp-and-udp-ports) for the full flag list.

## Limits

* **Up to 3 raw port forwards per machine.** Each allocated public port serves one port inside the machine, in one or both protocols. Remove one before adding a fourth.
* **Owner-only.** Only the machine's owner can add, list, or remove its forwards.
* **Persistent.** Forwards persist across reboots and are removed automatically when the machine is deleted.
* **Hibernated machines don't wake on raw ports yet.** It's on the roadmap. A hibernated machine does wake on an HTTPS request, an SSH connection, `boxd machine exec` or `boxd machine wake`, and a machine on [standby](/guides/suspend-resume.md) wakes on raw-port traffic too. So wake it one of those ways first, or keep a machine that serves a raw port from hibernating: `boxd machine config set myapp auto-hibernate.timeout 0`.

> [!NOTE]
>
> A raw port forward is for non-HTTP traffic. If you are serving a website or an HTTP API, use an [HTTPS proxy](/guides/proxies.md) instead. You get TLS and a clean `https://<machine>.boxd.sh` URL.
