Skip to content

Bug: Port forwarding sets and maintains firewalled port #3343

Description

@BingoRox

Is this urgent?

Yes

Host OS

Synology DSM 7.3.2

CPU arch

x86_64

VPN service provider

ProtonVPN

What are you using to run the container

docker-compose

What is the version of Gluetun

Running version latest built on 2026-05-21T18:39:34.738Z (commit 1a25f73) on Linux 4.4.302+ (x86_64)

What's the problem 🤔

Port forwarding is setting and maintaining a port that is firewalled. The port is changed, as you can see in the logs, but the new port is not open:

Image

This behaviour was also occurring on the v3.41.1 tag, so I think this is Proton related, (edit: but I will say today I was only able to get a working port on v3.41.1 and it could have been an unrelated issue when I experienced this on the tagged version last week). I initially did not have the updater enable, so I added my credentials for the paid server info, but the issue persists. The only thing that has worked is recreating the container multiple times until a working port is set.

I found that putting {"ports": []} to the control server also resulted in weird behaviour where the port was maintained even though the port file was cleared:

2026-05-22T21:56:17-04:00 DEBUG [port forwarding] refreshing forwarded ports since 45 seconds have elapsed
2026-05-22T21:56:17-04:00 DEBUG [port forwarding] port forwarded 53633 maintained
2026-05-22T21:56:26-04:00 DEBUG [http server] access to route PUT /v1/portforward authorized for role qbittorrent
2026-05-22T21:56:26-04:00 INFO [port forwarding] --2026-05-22 21:56:26--  http://127.0.0.1:8090/api/v2/app/setPreferences
2026-05-22T21:56:26-04:00 INFO [port forwarding] Connecting to 127.0.0.1:8090... connected.
2026-05-22T21:56:27-04:00 INFO [port forwarding] HTTP request sent, awaiting response... 200 OK
2026-05-22T21:56:27-04:00 INFO [port forwarding] Length: 0 [text/plain]
2026-05-22T21:56:27-04:00 INFO [port forwarding] Saving to: 'STDOUT'
2026-05-22T21:56:27-04:00 INFO [port forwarding]      0K                                                        0.00 =0s
2026-05-22T21:56:27-04:00 INFO [port forwarding] 
2026-05-22T21:56:27-04:00 INFO [port forwarding] 2026-05-22 21:56:27 (0.00 B/s) - written to stdout [0/0]
2026-05-22T21:56:27-04:00 INFO [firewall] removing allowed port 53633...
2026-05-22T21:56:27-04:00 INFO [port forwarding] clearing port file /tmp/gluetun/forwarded_port
2026-05-22T21:56:27-04:00 INFO [port forwarding] no port forwarded
2026/05/22 21:56:27 http: panic serving 172.20.0.1:49534: runtime error: index out of range [0] with length 0
goroutine 543 [running]:
net/http.(*conn).serve.func1()
2026-05-22T21:57:02-04:00 DEBUG [port forwarding] refreshing forwarded ports since 45 seconds have elapsed
2026-05-22T21:57:02-04:00 DEBUG [port forwarding] port forwarded 53633 maintained

I have tried other servers with the same result. I don't think the iptables warning is related, since eventually it works with the same warning and the iptables in the container are working correctly based on my limited testing. Let me know what else I can try!

Share your logs (at least 10 lines)

2026-05-22T21:18:18-04:00 INFO [vpn] You are running 1 commit behind the most recent latest
2026-05-22T21:18:18-04:00 INFO [port forwarding] starting
2026-05-22T21:18:18-04:00 DEBUG [port forwarding] gateway external IPv4 address is 185.98.171.161
2026-05-22T21:18:18-04:00 INFO [port forwarding] port forwarded is 38889 (internal port 56789)
2026-05-22T21:18:18-04:00 INFO [firewall] setting allowed input port 56789 through interface tun0...
2026-05-22T21:18:18-04:00 WARN [iptables] IPv6 port redirection disabled because your kernel does not support IPv6 NAT: command failed: "ip6tables-legacy -t nat --append PREROUTING -i tun0 -p tcp --dport 56789 -j REDIRECT --to-ports 38889": ip6tables v1.8.11 (legacy): can't initialize ip6tables table `nat': Table does not exist (do you need to insmod?)
Perhaps ip6tables or your kernel needs to be upgraded.: exit status 3
2026-05-22T21:18:18-04:00 INFO [port forwarding] writing port file /tmp/gluetun/forwarded_port
2026-05-22T21:18:18-04:00 INFO [port forwarding] --2026-05-22 21:18:18--  http://127.0.0.1:8090/api/v2/app/setPreferences
2026-05-22T21:18:18-04:00 INFO [port forwarding] Connecting to 127.0.0.1:8090... connected.
2026-05-22T21:18:20-04:00 INFO [port forwarding] HTTP request sent, awaiting response... 200 OK
2026-05-22T21:18:20-04:00 INFO [port forwarding] Length: 0 [text/plain]
2026-05-22T21:18:20-04:00 INFO [port forwarding] Saving to: 'STDOUT'
2026-05-22T21:18:20-04:00 INFO [port forwarding] 
2026-05-22T21:18:20-04:00 INFO [port forwarding] 2026-05-22 21:18:20 (0.00 B/s) - written to stdout [0/0]
2026-05-22T21:18:46-04:00 WARN [dns] getting tls connection for request IN A github.com.: creating connection: running TLS handshake with 1.1.1.1:853 (cloudflare-dns.com): read tcp 10.2.0.2:60792->1.1.1.1:853: read: connection reset by peer
2026-05-22T21:18:46-04:00 WARN [dns] getting tls connection for request IN A tracker.tleechreload.org.: creating connection: running TLS handshake with 1.1.1.1:853 (cloudflare-dns.com): read tcp 10.2.0.2:60786->1.1.1.1:853: read: connection reset by peer
2026-05-22T21:18:46-04:00 WARN [dns] getting tls connection for request IN AAAA tracker.tleechreload.org.: creating connection: running TLS handshake with 1.1.1.1:853 (cloudflare-dns.com): read tcp 10.2.0.2:60784->1.1.1.1:853: read: connection reset by peer
...
more dns warnings
...
2026-05-22T21:18:47-04:00 WARN [dns] getting tls connection for request IN A api.ipify.org.: creating connection: running TLS handshake with 1.1.1.1:853 (cloudflare-dns.com): read tcp 10.2.0.2:60806->1.1.1.1:853: read: connection reset by peer
2026-05-22T21:19:05-04:00 DEBUG [port forwarding] refreshing forwarded ports since 45 seconds have elapsed
2026-05-22T21:19:05-04:00 INFO [port forwarding] --2026-05-22 21:19:05--  http://127.0.0.1:8090/api/v2/app/setPreferences
2026-05-22T21:19:05-04:00 INFO [port forwarding] Connecting to 127.0.0.1:8090... connected.
2026-05-22T21:19:05-04:00 INFO [port forwarding] HTTP request sent, awaiting response... 200 OK
2026-05-22T21:19:05-04:00 INFO [port forwarding] Length: 0 [text/plain]
2026-05-22T21:19:05-04:00 INFO [port forwarding] Saving to: 'STDOUT'
2026-05-22T21:19:05-04:00 INFO [port forwarding] 
2026-05-22T21:19:05-04:00 INFO [port forwarding]      0K                                                        0.00 =0s
2026-05-22T21:19:05-04:00 INFO [port forwarding] 
2026-05-22T21:19:05-04:00 INFO [port forwarding] 2026-05-22 21:19:05 (0.00 B/s) - written to stdout [0/0]
2026-05-22T21:19:05-04:00 INFO [port forwarding] 
2026-05-22T21:19:05-04:00 INFO [firewall] removing allowed port 38889...
2026-05-22T21:19:05-04:00 INFO [port forwarding] clearing port file /tmp/gluetun/forwarded_port
2026-05-22T21:19:05-04:00 ERROR [port forwarding] external port changed from 38889 to 53633
2026-05-22T21:19:05-04:00 INFO [port forwarding] starting
2026-05-22T21:19:05-04:00 DEBUG [port forwarding] gateway external IPv4 address is 185.98.171.161
2026-05-22T21:19:05-04:00 INFO [port forwarding] port forwarded is 53633 (internal port 56789)
2026-05-22T21:19:05-04:00 WARN [iptables] IPv6 port redirection disabled because your kernel does not support IPv6 NAT: command failed: "ip6tables-legacy -t nat --append PREROUTING -i tun0 -p tcp --dport 56789 -j REDIRECT --to-ports 53633": ip6tables v1.8.11 (legacy): can't initialize ip6tables table `nat': Table does not exist (do you need to insmod?)
Perhaps ip6tables or your kernel needs to be upgraded.: exit status 3
2026-05-22T21:19:05-04:00 INFO [port forwarding] writing port file /tmp/gluetun/forwarded_port
2026-05-22T21:19:05-04:00 INFO [port forwarding] --2026-05-22 21:19:05--  http://127.0.0.1:8090/api/v2/app/setPreferences
2026-05-22T21:19:05-04:00 INFO [port forwarding] Connecting to 127.0.0.1:8090... connected.
2026-05-22T21:19:05-04:00 INFO [port forwarding] HTTP request sent, awaiting response... 200 OK
2026-05-22T21:19:05-04:00 INFO [port forwarding] Length: 0 [text/plain]
2026-05-22T21:19:05-04:00 INFO [port forwarding] Saving to: 'STDOUT'
2026-05-22T21:19:50-04:00 DEBUG [port forwarding] refreshing forwarded ports since 45 seconds have elapsed
2026-05-22T21:19:50-04:00 DEBUG [port forwarding] port forwarded 53633 maintained
2026-05-22T21:20:35-04:00 DEBUG [port forwarding] refreshing forwarded ports since 45 seconds have elapsed
2026-05-22T21:20:35-04:00 DEBUG [port forwarding] port forwarded 53633 maintained
2026-05-22T21:21:20-04:00 DEBUG [port forwarding] refreshing forwarded ports since 45 seconds have elapsed
2026-05-22T21:21:20-04:00 DEBUG [port forwarding] port forwarded 53633 maintained
2026-05-22T21:22:05-04:00 DEBUG [port forwarding] refreshing forwarded ports since 45 seconds have elapsed
2026-05-22T21:22:05-04:00 DEBUG [port forwarding] port forwarded 53633 maintained
... 
port maintained every 45 seconds for at least 20 minutes

Share your configuration

services:
  gluetun:
    image: qmcgaw/gluetun:latest
    container_name: gluetun
    cap_add:
      - NET_ADMIN
      - NET_RAW
    devices:
      - /dev/net/tun:/dev/net/tun
    env_file:
      - .env
    ports:
      - 172.20.0.1:8001:8001          # gluetun control server
      - 172.20.0.1:8888:8888          # HTTP proxy
      - 172.20.0.1:8090:8090          # qbittorrent
    volumes:
      - /volume2/docker/gluetun:/gluetun
      - /volume2/docker/gluetun/auth/config.toml:/gluetun/auth/config.toml
    environment:
      - PUID=$PUID
      - PGID=$PGID
      - TZ=$TZ
      - LOG_LEVEL=debug
      - PUBLICIP_API=ipinfo
      - PUBLICIP_API_TOKEN=$PUBLICIP_API_TOKEN
      - HTTPPROXY=on
      - HTTPPROXY_USER=gluetun
      - HTTPPROXY_PASSWORD=$HTTPPROXY_PASSWORD
      - SHADOWSOCKS=off
      - FIREWALL_OUTBOUND_SUBNETS=172.20.0.0/16,192.168.2.0/24
      - HTTP_CONTROL_SERVER_ADDRESS=:8001
      - BLOCK_MALICIOUS=off
      ### Updater ###
      - UPDATER_PERIOD=24h
      - UPDATER_PROTONVPN_EMAIL=$UPDATER_PROTONVPN_EMAIL
      - UPDATER_PROTONVPN_PASSWORD=$UPDATER_PROTONVPN_PASSWORD
      ### ProtonVPN Config ###
      - VPN_SERVICE_PROVIDER=protonvpn
      - VPN_TYPE=wireguard
      - WIREGUARD_PRIVATE_KEY=$WIREGUARD_PRIVATE_KEY
      - SERVER_COUNTRIES=$SERVER_COUNTRIES
      - SERVER_CITIES=$SERVER_CITIES
      - SERVER_HOSTNAMES=$SERVER_HOSTNAMES
      - PORT_FORWARD_ONLY=on
      - VPN_PORT_FORWARDING=on
      - WIREGUARD_MTU=1400
      - VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c 'wget -O- --retry-connrefused --post-data "json={\"listen_port\":{{PORTS}}}" http://127.0.0.1:8090/api/v2/app/setPreferences 2>&1'
      - VPN_PORT_FORWARDING_DOWN_COMMAND=/bin/sh -c 'wget -O- --retry-connrefused --post-data "json={\"listen_port\":0" http://127.0.0.1:8090/api/v2/app/setPreferences 2>&1'
    networks:
      - bridge
    restart: always

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions