> For the complete documentation index, see [llms.txt](https://rosemary-2.gitbook.io/rosemary-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rosemary-2.gitbook.io/rosemary-docs/tutorials/basic-tunnel.md). Agents can also search and read this documentation through its [MCP server](https://rosemary-2.gitbook.io/rosemary-docs/~gitbook/mcp).

# Basic Tunnel

***

This tutorial walks through setting up a transparent tunnel between your machine and a remote host using Rosemary. By the end, you will be able to reach the remote network directly with any tool you already use. No proxy settings, no proxychains, no configuration changes to your applications.

***

### What You Need

| Component        | Requirement                                                                   | Role            |
| ---------------- | ----------------------------------------------------------------------------- | --------------- |
| Operator machine | Root or Administrator access                                                  | Runs the server |
| Remote host      | Any shell access                                                              | Runs the agent  |
| Connectivity     | Agent must reach the server on `2048/udp` (QUIC); dashboard/API on `1024/tcp` | -               |

***

### Step 1 - Start the Server

On your operator machine, start Rosemary with root privileges:

```bash
sudo rosemary
```

On first run, Rosemary auto-generates an encryption key and prints everything you need:

```
2026/04/24 10:00:00 Server login key: xK9mP2qL...base64...==
2026/04/24 10:00:00 Dashboard: http://0.0.0.0:1024
2026/04/24 10:00:00 Agent transport (QUIC): 0.0.0.0:2048/udp
```

**Copy the key.** You will need it when you deploy the agent.

If you want to set your own key instead of using the auto-generated one:

```bash
sudo rosemary -key YOUR_BASE64_KEY
```

To generate a valid key manually:

```bash
openssl rand -base64 32 | tr '+/' '-_' | tr -d '='
```

***

### Step 2 - Deploy the Agent

Transfer the agent binary to the remote host using whatever method you have available: SCP, curl, wget, or a file upload through a web shell.

```bash
scp agent-linux-amd64 user@remote-host:/tmp/
```

Then connect to the remote host and run the agent:

```bash
./agent-linux-amd64 -s <your-server-ip>:2048 -k YOUR_BASE64_KEY
```

To run it silently in the background and keep it running after you close your session:

```bash
./agent-linux-amd64 -s <your-server-ip>:2048 -k YOUR_BASE64_KEY -b
```

When the agent starts it will:

1. Connect to your server over QUIC (UDP)
2. Complete the authentication handshake using the shared key
3. Discover all local subnets from its network interfaces
4. Register with the server and receive an agent ID
5. Begin waiting for traffic to forward

***

### Step 3 - Verify the Connection

On your server terminal, check that the agent registered:

```
rosemary> agents
```

You should see output like this:

```
ID             OS       Hostname        Subnets                    Username    LastSeen    Internet
agent-2        linux    target-host     192.168.10.0/24 (+1)       root        10:01:23    No
```

The moment the agent registers, Rosemary installs iptables interception rules for its subnets. Any traffic your machine sends to 192.168.10.0/24 is now transparently tunneled through the agent.

To see the full subnet list for an agent:

```
rosemary> agents agent-2
```

```
Agent: agent-2
  OS:            linux
  Hostname:      target-host
  Username:      root
  Connected:     2026-04-24 10:01:10
  Last Seen:     10:01:23
  Internet:      No
  Subnets:
    - 192.168.10.0/24
    - 10.10.0.0/24
```

To check the routing table:

```
rosemary> routes
```

***

### Step 4 - Use the Tunnel

You can now reach the remote network from your machine using any tool without any additional configuration.

Ping a host:

```bash
ping 192.168.10.5
```

SSH into a remote machine:

```bash
ssh user@192.168.10.5
```

Scan with Nmap:

```bash
nmap -sV -p- 192.168.10.1
```

Curl a web service:

```bash
curl http://192.168.10.10:8080
```

DNS resolution also works transparently. If the agent can resolve hostnames on the remote network, your machine can too:

```bash
ping dc01.corp.local
ssh admin@fileserver.corp.local
```

All traffic is routed automatically based on which agent owns the destination subnet. If you have multiple agents connected across different network segments, each one handles its own subnets and you reach all of them at the same time.

***

### Step 5 - Open the Dashboard

Open your browser and navigate to:

```
http://<your-server-ip>:1024
```

Log in with your key. The dashboard gives you a visual overview of connected agents, their subnets, and connection status. From here you can also:

* Add port forwards
* Start SOCKS5 proxies
* Run ping sweeps and port scans through agents
* Manage routing rules

***

### Step 6 - Disconnect

To disconnect a specific agent:

```
rosemary> disconnect agent-2
```

To disconnect all agents at once:

```
rosemary> disconnect all
```

When an agent disconnects, the server automatically removes all iptables rules for its subnets. Your routing table returns to its previous state.

***

### Troubleshooting

**Agent connects but traffic is not routed**

Make sure the server is running as root. The iptables rules that intercept traffic require elevated privileges. Verify the agent subnets are active with:

```
rosemary> routes
```

**Agent keeps disconnecting**

Verify that `2048/udp` is reachable from the agent machine and no firewall is blocking outbound UDP. You can sanity-check the dashboard with TCP:

```bash
curl http://<server-ip>:1024
```

And probe the QUIC port with `nc` (a response is not expected, but a hard "port unreachable" indicates the agent transport is being blocked):

```bash
nc -uvz <server-ip> 2048
```

**DNS is not resolving remote hostnames**

The agent uses its own system resolver to answer DNS queries. If the remote hostname is only known to an internal DNS server, make sure the agent's `/etc/resolv.conf` points to that server. You can also check which DNS servers the agent is using by running `cat /etc/resolv.conf` on the remote host.
