From 6124a058a44d881d7b71f93d32304b06dbc0d3b1 Mon Sep 17 00:00:00 2001 From: Alex Lavallee Date: Fri, 9 Aug 2024 18:29:18 -0700 Subject: [PATCH 1/2] docs(portforwarding): Explain how to use custom port forwarding command --- setup/advanced/vpn-port-forwarding.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setup/advanced/vpn-port-forwarding.md b/setup/advanced/vpn-port-forwarding.md index b3f8eb1..5445d7b 100644 --- a/setup/advanced/vpn-port-forwarding.md +++ b/setup/advanced/vpn-port-forwarding.md @@ -16,6 +16,12 @@ The forwarded port can be accessed: - through the [control server](control-server.md#openvpn-and-wireguard) - through the file written at `/tmp/gluetun/forwarded_port` (will be deprecated in v4.0.0 release) +- by running a user specified command upon port forwarding starting (see below) + +## Custom port forwarding up command +- Can be set via `VPN_PORT_FORWARDING_UP_COMMAND=command` +- Doesn't understand shell specific syntax such as `&&`, and one should use `/bin/sh -c "my shell syntax"` to do so if they want (bash isn't installed by default, only sh) +- Will have the string `{{PORTS}}` replaced by a comma separated list of the ports that have been forwarded (Example: `VPN_PORT_FORWARDING_UP_COMMAND=/script.sh {{PORTS}}`) ## Allow a forwarded port through the firewall From a9726c636aca02d3dc9c33733f8bcf728460dbcc Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sat, 9 Nov 2024 18:10:12 +0100 Subject: [PATCH 2/2] Update setup/advanced/vpn-port-forwarding.md --- setup/advanced/vpn-port-forwarding.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/setup/advanced/vpn-port-forwarding.md b/setup/advanced/vpn-port-forwarding.md index 5445d7b..210b705 100644 --- a/setup/advanced/vpn-port-forwarding.md +++ b/setup/advanced/vpn-port-forwarding.md @@ -19,9 +19,15 @@ The forwarded port can be accessed: - by running a user specified command upon port forwarding starting (see below) ## Custom port forwarding up command -- Can be set via `VPN_PORT_FORWARDING_UP_COMMAND=command` -- Doesn't understand shell specific syntax such as `&&`, and one should use `/bin/sh -c "my shell syntax"` to do so if they want (bash isn't installed by default, only sh) -- Will have the string `{{PORTS}}` replaced by a comma separated list of the ports that have been forwarded (Example: `VPN_PORT_FORWARDING_UP_COMMAND=/script.sh {{PORTS}}`) + +A command can be set with `VPN_PORT_FORWARDING_UP_COMMAND`. For example `VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c "echo {{PORTS}}"`. + +Notes: + +- The special string `{{PORTS}}` is replaced by a comma separated list of the ports that have been forwarded. For example `/bin/sh -c "echo {{PORTS}}"` would become `/bin/sh -c "echo 5678,9876"` +- shell specific syntax such as `&&` is not understood in the command, and one should use `/bin/sh -c "my shell syntax"` to do so if they want. +- one can bind mount a shell script in Gluetun and execute it with for example `VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c /gluetun/myscript.sh` - 💁 feel free to propose a pull request to add commonly used shell scripts for port forwarding! +- the output of the command is written to the port forwarding logger within Gluetun ## Allow a forwarded port through the firewall