diff --git a/setup/advanced/vpn-port-forwarding.md b/setup/advanced/vpn-port-forwarding.md index ddf12c1..83c1a39 100644 --- a/setup/advanced/vpn-port-forwarding.md +++ b/setup/advanced/vpn-port-forwarding.md @@ -10,6 +10,8 @@ VPN server side port forwarding is implemented natively into Gluetun for the fol - **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: @@ -36,7 +38,7 @@ Notes: ### 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'` `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. @@ -48,6 +50,12 @@ Thanks to [@Marsu31](https://github.com/Marsu31) 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: diff --git a/setup/options/port-forwarding.md b/setup/options/port-forwarding.md index 41c922d..0494382 100644 --- a/setup/options/port-forwarding.md +++ b/setup/options/port-forwarding.md @@ -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. @@ -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=`. | | `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. | diff --git a/setup/providers/perfect-privacy.md b/setup/providers/perfect-privacy.md index 2ea710c..e7db74d 100644 --- a/setup/providers/perfect-privacy.md +++ b/setup/providers/perfect-privacy.md @@ -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 diff --git a/setup/providers/private-internet-access.md b/setup/providers/private-internet-access.md index cd68bdb..acc6e3c 100644 --- a/setup/providers/private-internet-access.md +++ b/setup/providers/private-internet-access.md @@ -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 diff --git a/setup/providers/privatevpn.md b/setup/providers/privatevpn.md index 5a04d1f..03918c2 100644 --- a/setup/providers/privatevpn.md +++ b/setup/providers/privatevpn.md @@ -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