Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions setup/advanced/vpn-port-forwarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

- **Private Internet Access**, [more information](../providers/private-internet-access.md)
- **ProtonVPN**, [more information](../providers/protonvpn.md)
- **Perfect Privacy**, [more information](../providers/perfect-privacy.md)
- **PrivateVPN**, [more information](../providers/privatevpn.md)

You can enable it with `VPN_PORT_FORWARDING=on`.
The forwarded port can be accessed:
Expand All @@ -36,18 +38,23 @@

### qBittorrent example

`VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c 'wget -O- --retry-connrefused --post-data "json={\"listen_port\":{{PORTS}}}" http://127.0.0.1:8080/api/v2/app/setPreferences 2>&1'`
`VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c 'wget -O- --retry-connrefused --post-data "json={\"listen_port\":$(echo {{PORTS}} | cut -d, -f1),\"random_port\":false,\"upnp\":false}" http://127.0.0.1:8080/api/v2/app/setPreferences 2>&1'`
Comment thread
qdm12 marked this conversation as resolved.
`VPN_PORT_FORWARDING_DOWN_COMMAND=/bin/sh -c 'wget -O- --retry-connrefused --post-data "json={\"listen_port\":123}" http://127.0.0.1:8080/api/v2/app/setPreferences 2>&1'`

For this to work, the qBittorrent web UI server must be enabled and listening on port `8080` and the Web UI "Bypass authentication for clients on localhost" must be ticked (json key `bypass_local_auth`) so Gluetun can reach qBittorrent without authentication.
Due to a bug in qBittorrent, for port forwarding to be reestablished after a disconnect, the port needs to be re-set. This can be achieved automatically using the DOWN_COMMAND above.

Comment thread
qdm12 marked this conversation as resolved.
Thanks to [@Marsu31](https://github.com/Marsu31)

Check failure on line 47 in setup/advanced/vpn-port-forwarding.md

View workflow job for this annotation

GitHub Actions / verify

Multiple consecutive blank lines

setup/advanced/vpn-port-forwarding.md:47 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.29.0/doc/md012.md
## Allow a forwarded port through the firewall

For non-native integrations where you have a designated forwarded port from your VPN provider, you can allow it by adding it to the environment variable `FIREWALL_VPN_INPUT_PORTS`.

## Port redirection using iptables

Gluetun supports setting up a redirection of incoming traffic from the VPN opened port to a custom localhost port of your choosing, by using the `VPN_PORT_FORWARDING_LISTENING_PORT` environment variable. Do not use this with torrent clients, or any other software that publicly announces its port, as that software would not be aware of the publicly visible port and would be announcing the private port instead.

For example, if you have a web server (nginx, caddy, apache) listening on port 80, you can set `VPN_PORT_FORWARDING_LISTENING_PORT=80` to expose it to the outside world on all available VPN server's public ports.

## Test it

Assuming:
Expand Down
6 changes: 5 additions & 1 deletion setup/options/port-forwarding.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# VPN server port forwarding options

Read [the guide](../advanced/vpn-port-forwarding.md) for details.

## Environment variables

💁 The following environment variables are all optional.
Expand All @@ -9,4 +11,6 @@
| `VPN_PORT_FORWARDING` | `off` | `off` or `on` | Enable custom port forwarding code for supported providers |
| `VPN_PORT_FORWARDING_PROVIDER` | Current provider in use | `private internet access`, `perfect privacy`, `privatevpn`, `protonvpn` | Choose the custom port forwarding code to use. This is useful when using the custom provider with Wireguard. For PIA, make sure you set `SERVER_NAMES=<server-name>`. |
| `VPN_PORT_FORWARDING_STATUS_FILE` | `/tmp/gluetun/forwarded_port` | Valid filepath | File path to use for writing the forwarded port obtained. |
| `VPN_PORT_FORWARDING_LISTENING_PORT` | | Valid port number | Port redirection for the VPN server side port forwarded. |
| `VPN_PORT_FORWARDING_LISTENING_PORT` | | Valid port number | Port redirection to redirect incoming traffic to. Do not use with torrent clients. |
| `VPN_PORT_FORWARDING_UP_COMMAND` | | Shell command | Command to run when port forwarding has finished setting up. |
| `VPN_PORT_FORWARDING_DOWN_COMMAND` | | Shell command | Command to run when port forwarding has finished tearing down. |
2 changes: 1 addition & 1 deletion setup/providers/perfect-privacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:

## VPN server port forwarding

Set `VPN_PORT_FORWARDING=on` and the 3 ports forwarded will be logged out as well as available via the http control server.
Set `VPN_PORT_FORWARDING=on` and the 3 ports forwarded will be logged out as well as available via the http control server. See [VPN server port forwarding setup page](../advanced/vpn-port-forwarding.md) for more details.

## Servers

Expand Down
3 changes: 1 addition & 2 deletions setup/providers/private-internet-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ services:
- `PORT_FORWARD_ONLY`: Set to `true` to select servers with port forwarding only
- `PRIVATE_INTERNET_ACCESS_OPENVPN_ENCRYPTION_PRESET`: Encryption preset, defaulting to `strong`, which can be set to `normal`, `strong` or `none`. ⚠️ `none` disables the `cipher` and `auth` OpenVPN options.
- `OPENVPN_ENDPOINT_PORT`: Custom OpenVPN server endpoint port
- `VPN_PORT_FORWARDING`: defaults to `off` and can be set to `on`to enable port forwarding on the VPN server
- `VPN_PORT_FORWARDING_STATUS_FILE`: File path to write the forwarded port number to. It defaults to `/tmp/gluetun/forwarded_port`.
- `VPN_PORT_FORWARDING`: defaults to `off` and can be set to `on` to enable port forwarding on the VPN server

## Wireguard

Expand Down
6 changes: 4 additions & 2 deletions setup/providers/privatevpn.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## TLDR

💁 To use with Wireguard, see [the custom provider Wireguard section](custom.md#wireguard).
💁 To use with Wireguard, see [the custom provider Wireguard section](custom.md#wireguard). You will need to use the IP address of the endpoint instead of the domain - see [discussion](https://github.com/qdm12/gluetun/issues/2680).
Comment thread
qdm12 marked this conversation as resolved.
Outdated

For OpenVPN:

Expand Down Expand Up @@ -44,7 +44,9 @@ services:

## VPN server port forwarding

Set `VPN_PORT_FORWARDING=on` and the port forwarded will be logged out as well as available via the http control server.
VPN server port forwarding is only supported on OpenVPN. If you try using it with Wireguard, PrivateVPN API will return `{"supported":false}` message, resulting in a "port forwarding not supported for this VPN server" error.

Set `VPN_PORT_FORWARDING=on` and the port forwarded will be logged out as well as available via the http control server. See [VPN server port forwarding setup page](../advanced/vpn-port-forwarding.md) for more details.

## Servers

Expand Down
Loading