alpacon tunnel
Forward a local TCP port to a service on a remote server.
Usage
alpacon tunnel [flags] SERVER [-- COMMAND...]
Key facts
- Use browser login; token authentication cannot open tunnels.
- Remote services must listen on IPv4 loopback (
127.0.0.1). - Optionally run a local command while the tunnel is open.
Flags
| Flag | Type | Description | Default |
|---|---|---|---|
-g, --groupname | string | Groupname for the tunnel | — |
-h, --help | bool | help for tunnel | false |
-l, --local | string | Local port to listen on (required) | — |
-r, --remote | string | Remote port to connect to (required) | — |
-u, --username | string | Username for the tunnel | — |
-v, --verbose | bool | Show connection logs | false |
--work-session | string | Attach this tunnel to a work-session (overrides ‘work-session use’) | — |
--output | string | Output format: table or json | table |
Examples
Forward local port 9000 to remote port 8082
alpacon tunnel my-server -l 9000 -r 8082Same using long flags
alpacon tunnel my-server --local 9000 --remote 8082Forward local port 2222 to remote SSH port 22
alpacon tunnel my-server -l 2222 -r 22Specify username and groupname for the tunnel
alpacon tunnel my-server -l 9000 -r 8082 -u admin -g developersAttach the tunnel to a specific work session
alpacon tunnel my-server -l 9000 -r 8082 --work-session 11111111-2222-3333-4444-555555555555Run psql with the tunnel attached
alpacon tunnel prod-db -l 5432 -r 5432 -- psql -h 127.0.0.1 -p 5432 -U app appdbRun kubectl with the tunnel attached
alpacon tunnel prod-k8s -l 6443 -r 6443 -- kubectl --server=https://127.0.0.1:6443 get podsEnable verbose output for debugging
alpacon tunnel my-server -l 9000 -r 8082 -vDetails
Create a secure TCP tunnel between your local machine and a remote server. This allows you to forward a local port to a remote port, enabling access to services running on the server (such as databases, web applications, or internal APIs) through a secure connection. The tunnel reaches the remote port on the server’s IPv4 loopback address (127.0.0.1), so a service that listens only on ::1 can’t be reached. Optionally, run a local command with the tunnel lifecycle attached.
On Windows servers, port forwarding needs Alpamon 2.5.1 or later. See Windows servers.
Running a local command
If -- COMMAND [ARGS...] is provided, Alpacon runs the local command in the same session with the tunnel lifecycle attached: the tunnel opens before the command starts and closes when the command exits. Place -- before the local command so Alpacon parses the tunnel flags and forwards everything after -- to the local program exactly as provided.
Work session requirement
When you sign in with browser login, alpacon tunnel requires an active work session that includes the tunnel scope. A token (API token or service token) cannot open a tunnel; run alpacon login without -t instead.
The session to attach is resolved from the --work-session flag, the ALPACON_WORK_SESSION environment variable, or the active session set with alpacon work-session use—in that order.