# Forward a port

Open a web server that runs on one of your machines from your computer or your phone, at localhost.

A program on a machine, such as a dev server at `localhost:5173`, can only be reached on that machine. Forward its port, and `http://localhost:5173` works on your computer or phone too: chaar carries each connection to port 5173 on the machine.

Only the device you forward to can open it, because chaar listens on `localhost` there and nowhere else.

## Forward a port [#forward-a-port]

- **Desktop**

  - **From a link.** When a terminal shows a link to `localhost`, such as `http://localhost:5173`, hold `⌘` (macOS), `Windows` (Windows), `Super` (Linux) and click it. Choose **Open on this computer**: chaar forwards the port and opens the page in your browser. **Forward to another port…** lets you pick the port here first.
  - **Any port.** Right-click the machine's card in the sidebar and choose **Forward a port**, or pick **Forward a port from** and the machine's name in the command palette. Type the machine's port under **Port on** and click **Forward**. Leave **Port here** empty to use the same number, or type `0` for any free one.

- **Phone**

  - **From a link.** Tap a link to `localhost` in a terminal, then **Open on this phone**. chaar forwards the port and opens the page in a browser inside the app. **Forward to another port…** lets you pick the port on the phone first.
  - **Any port.** In a session, tap ⋯ at the top, then **Port forwarding**. Type the machine's port and tap **Forward and open**. Leave the port on this phone empty to use the same number, or type `0` for any free one.

  A green dot on ⋯ means something is forwarded from that machine to this phone.

- **Terminal**

  ```sh
  chaar forward add 5173 -m studio
  ```

  It prints the address to open, such as `http://localhost:5173`, and keeps the forward up until you press `ctrl-c`. `--local <port>` picks the port here, and `0` picks any free one. See [chaar forward](/terminal-reference#chaar-forward).

## See and stop forwards [#see-and-stop-forwards]

Every device sees what's forwarded from a machine, whichever device it goes to, and can stop any of it.

- **Desktop:** Open **Forward a port** for the machine. Everything forwarded from it is under **Forwarded from**. Yours have **Open** and **Stop**. Another device's shows its name and **Stop**.

- **Phone:** Open **Port forwarding** from ⋯. Everything forwarded from the machine is under **Forwarded**. This phone's have **Open**, and each has a stop button.

- **Terminal:** `chaar forward list` lists them, and `chaar forward remove 5173 -m studio` stops one.

A forward lasts until it's stopped, from any device, or until:

- **Desktop:** you quit the app. One you opened from a link also stops when you close that terminal tab.
- **Phone:** the app is closed.
- **Terminal:** you press `ctrl-c`.

## When something goes wrong [#when-something-goes-wrong]

- **Nothing is listening on the machine's port.** The forward starts, but the page doesn't load and the forward's row turns orange with the reason. Start the server on the machine. The desktop says **Nothing is listening on** the port, with **Try again**. `chaar forward add` prints a warning for each connection that fails.
- **The port is taken here.** Opening a link then forwards to a free port instead. On the desktop, **Opened on localhost:** names it. A page that sends you back to the first port, as sign-in pages do, needs that port freed, then **Retry on** it. In the dialog, the phone's sheet or `chaar forward add`, pick another port here, or `0`.
- **A machine shared with you.** Forwarding needs **Can run** on it: see [Share with others](/share). With **Can view**, the phone says **View only: ports can't be forwarded**, and the desktop doesn't offer it.