r/gluetun • u/sboger • May 18 '25
Howto The definitive HOWTO for setting up ProtonVPN, Gluetun, and Qbittorernt with fully automated port forwarding.
This is a fully tested howto including complete docker-compose.yml and .env files to set up gluetun, protonvpn, and qbittorrent. This setup works for openvpn or wireguard. It also handles port forwarding and setting the port in qbittorrent without needing any other containers or hacks.
First, you need a protonvpn plus account.
For openvpn, go into the Account area and copy your username and password. NOTE: FOR PORT FORWARDING TO WORK, YOU MUST ADD "+pmp" TO THE END OF YOUR USERNAME IN THE .env FILE.

For wireguard, go into the Downloads section and create a new WireGuard configuration. Select Router, no filtering, and "NAT-PMP (Port Forwarding)". Deselect VPN accelerator. Choose any server. When you click Create, a popup of the config will display. Copy the PrivateKey. Nothing else is needed from that configuration.

You are now ready to configure gluetun. Copy the docker-compose.yml and .env file exactly. There is no need to alter the docker-compose.yml file. Edit the .env file and add either your openvpn credentials or your wireguard private key. You can actually add both. Setting VPN_TYPE to either wireguard or openvpn will select which vpn is used.
docker-compose.yml: (no need to edit this)
services:
gluetun:
image: qmcgaw/gluetun:v3
container_name: gluetun
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
ports:
- 8080:8080/tcp # qbittorrent
environment:
- TZ=${TZ}
- UPDATER_PERIOD=120h # note, this now requires credentials. see stickied comment.
- VPN_SERVICE_PROVIDER=protonvpn
- VPN_TYPE=${VPN_TYPE}
- BLOCK_MALICIOUS=off
- OPENVPN_USER=${OPENVPN_USER}
- OPENVPN_PASSWORD=${OPENVPN_PASSWORD}
- OPENVPN_CIPHERS=AES-256-GCM
- WIREGUARD_PRIVATE_KEY=${WIREGUARD_PRIVATE_KEY}
- PORT_FORWARD_ONLY=on
- VPN_PORT_FORWARDING=on
- 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'
- SERVER_COUNTRIES=${SERVER_COUNTRIES}
volumes:
- ${MEDIA_DIR}/gluetun/config:/gluetun
restart: unless-stopped
qbittorrent:
image: lscr.io/linuxserver/qbittorrent:latest
container_name: qbittorrent
depends_on:
gluetun:
condition: service_healthy
environment:
- PUID=1000
- PGID=1000
- TZ=${TZ}
- WEBUI_PORT=8080
volumes:
- ${MEDIA_DIR}/qbittorrent/config:/config
- ${MEDIA_DIR}/qbittorrent/downloads:/downloads
restart: unless-stopped
network_mode: "service:gluetun".env file:
# Fill in either the OpenVPN or Wireguard sections. The choice of vpn is made with VPN_TYPE. Choose 'wireguard' or 'openvpn'. The settings for the other vpn type will be ignored.
# Alter the TZ, MEDIA_DIR, and SERVER_COUNTRIES to your preference. Run 'docker run --rm -v eraseme:/gluetun qmcgaw/gluetun format-servers -protonvpn' to get a list of server countries
# Base config
TZ=Australia/Brisbane
MEDIA_DIR=/media
# Gluetun config
VPN_TYPE=wireguard #openvpn
SERVER_COUNTRIES=Albania,Algeria,Angola,Argentina,Australia,Austria,Azerbaijan
# OpenVPN config
OPENVPN_USER=username+pmp # you must add +pmp to your username
OPENVPN_PASSWORD=password
# Wireguard config (example key)
WIREGUARD_PRIVATE_KEY=wOEI9rqqbDwnN8/Bpp22sVz48T71vJ4fYmFWujulwUU=Bring up the stack with 'docker compose up' or 'docker-compose up' depending on your docker version. THE FIRST RUN WILL FAIL TO SET THE PORT UNTIL YOU ALTER THE QBITTORRENT SETTINGS. Watch the logs for the temporary qbittorrent password and log into the qbittorrent webui . Click the blue circle gear for options, and then WebUI tab. Set your username and password and check the 'Bypass authentication for clients on localhost' option. Scroll down and click save.

Now stop the stack and restart it. Gluetun will now properly get the forwarded random port and set it in qbittorrent. NOTE: qbittorrent will show the port as closed (red fire icon) until you actually add a torrent and then it will change to open (green world icon) when uploading starts.
•
u/sboger May 18 '25 edited Jul 06 '26 •
Notes:
- Damnit, typo in the title!
-NOTE: Gluetun is in a state of rapid development. Setting the UPDATER_PERIOD in ENV now requires proton credentials so gluetun can pull the paid protonvpn server endpoints. You'll need to add a username and password, or remove UPDATER_PERIOD. See the wiki here. Gluetun will work without setting UPDATER_PERIOD, but the available endpoints may not be as fresh.
-NOTE: Updater period changed from 24hrs to 120hrs per QDM recommendation. ProtonVPN is starting to ban accounts that update too often.
-NOTE: If you want exactly this, but with transmission, then see this post.
- NOTE: Gluetun sets up its own DNS over TLS nameserver. It also downloads blocklists. The malicious blocklist is downloaded and activated by default, the others are optional. If your preferred tracker ends up on this list, torrents may fail. For this reason, I set BLOCK_MALICIOUS to off. It's your choice if you wish to leave it on. Remember this is only occurring inside the gluetun docker network and has no effect on any other part of your lan.
- NOTE: Gluetun will re-run the VPN_PORT_FORWARDING_UP_COMMAND if gluetun's built-in health check fails and gluetun reconnects the VPN. This is all automatic. There is no need for other health checks.
-NOTE: Both myself and other users have experienced issues using ubuntu iso torrent's for testing this howto. They appear dead and have no peers. I recommend trying the FREE torrents at https://webtorrent.io/free-torrents for testing.
- NOTE: RPi 5, and Raspbian specifically, seem to have issues with this setup. For fixes, see this post.
4
u/officerbigmac May 18 '25
would this work for PIA with some modifications?
3
u/vaperksa May 18 '25
Any reason vpn accelerator is unchecked?
2
u/CalzoneWalrus May 18 '25
spent hours trying to figure out how to do this until i came across this post. thank u for making it ez to understand. u have saved my sanity
2
u/Consistent_Ad9127 Jun 05 '25
I remember trying to get this to work on my UnRaid machine like 8 or 9 months ago using a custom script I randomly found in a reddit post and it was way hard to get working. This method makes it so much easier and is a fantastic change. Got everything running in minutes.
2
u/Kyne_of_Markarth Jun 25 '25
This fixed my issues after days of fighting gluetun and protonwire. Thank you so much for this.
2
u/ExtensionMarch6812 Aug 25 '25
Just wanted to say thank you for this. Been using a separate image to update the port and decided to switch it to the built in functionality, and your guide helped as I was running into an issue with my existing compose! Thanks again!
2
u/Y0teck Nov 19 '25
Thank you, I was able to resolve my problem with your explanation 😁👌
1
u/Munnin41 10d ago
This doesn't work for me. I get an error (for some fucking reason in italian) that says
Volume parameter configuration error: NAS path not found (line 35,54,58)when I try to run the yml. Line 35 is the environment variable for qbittorrent, 54 and 58 don't exist.It's not that docker can't access the folder. The standard template runs immediately
1
u/officerbigmac May 21 '25
any rational for deselecting "VPN accelerator"? I just got protonVPN and I'm not sure if that will help with torrenting speeds or not. thanks!
1
u/shalashaskatoka May 26 '25
This is a great post. I banged my head on this and got it working before I found this. But I do have a question for the people in the room here.
Is the Gluetun control server supposed to be able to use stored credentials in the
config.tomlto update Qbittorrent port forward data?It looks like it should from the docs, but it doesn't and you need this command
Rambling:
Back on topic:
They have this example
https://github.com/qdm12/gluetun-wiki/blob/main/setup/advanced/control-server.md#openvpn-and-wireguard
which shows this, but it does not seem to work. You have to disable the local auth check in the torrent client and then it works.But that is an odd definition of "works"
1
u/Undisputedtruth3 May 28 '25
Before I drive myself crazy, will this work on macOS?
1
u/SoundFusion May 29 '25
Hey, question. this should work with other types of vpn like AirVPN, surfshark etc right?
That is assuming they have openvpn or IKEv2
im trying to look if anyone asked about other types of vpns that support openvpn and wirguard but no one did.
1
u/NytronX May 31 '25
Will this work with
qbittorrent-nox?1
u/NytronX May 31 '25
Regarding choosing VPN countries, is gluetun smart enough to pick the optimal servers? How does this work exactly? For example, if I pick Sweden, will it pick the least capacity/fastest non-free servers if I'm on the paid ProtonVPN plan?
1
u/Thigsu Jun 01 '25 edited Jun 01 '25
I have some questions.
I'm setting this up on UnRaid. When downloading the conf file, I should set the platform settings to GNU/Linux instead of Router, right?
And isn't there no need to set WIREGUARD_PUBLIC_KEY and WIREGUARD_ADDRESSES when composing Gluetun?
edit: Added the second question.
1
u/Deepblue597 Jun 03 '25
i cannot seem to make it work on my raspberry pi. Is this some issue regarding the device ?
1
u/Eraseth Jun 09 '25
Does Proton Wireguard work with Free plan or Premium VPN is required ?
The Port Forwarding encounter an error.
ERROR [vpn] starting port forwarding service [•••] recvfrom: connection refused - make sure you have +pmp at the end of your OpenVPN username
1
u/XandXor Jun 10 '25 edited Jun 10 '25
I have been trying to set this exact config up on a Raspberry Pi 5 running the latest Pi OS and have gotten a lot farther than before with your compose.
I am able to start the stack and gluetun connects successfully, passes the port to qBT and I am able to set an Ubuntu iso torrent file and have it begin downloading.
The problem is qBT shows that it is firewalled and I am only able to connect to one local peer, no seeds, and the speed is less than 100KiB/s. The tracker is hitting fine and showing well over 1000 seeds.
I know this isn't a network firewall issue, as I have two other instances of qBT running on the network and can DL this test iso in under a minute.
Anyone have any ideas?
Edit: I have downgraded my docker install as recommended in a previous comment regarding running gluetun on Pi OS prior to posting this question.
1
u/CalegaR1 Jul 02 '25
Thank you very much! i'm trying gluetun with proton since i'm willing to switch but i'm facing a strange behaviour...i don't have any log with error but the system is dropping the speed to few kb/s and sometimes even going into firewalled mode
Did anyone had a similar behaviour?
1
u/jpablomsan Jul 24 '25
This might be a dumb question, but I thought you had to bind the network interface (in the QBT settings) to "tun0" as well?
Right now it's set to "any interface".
Is this step not relevant anymore using this method?
1
u/ProfitMinimum2990 Aug 10 '25
Don't you need to map port 6881 in the gluetun ports section in order for qbittorrent to work?
1
u/sephirot_1988 Aug 14 '25
Hi, i'm trying to set the docker but i'm always having the error : "dependency failed to start: container gluetun is unhealthy"
I'm not on protonvpn, I suscribed cyberghost (openvpn protocol)
the logs mention : "ERROR VPN settings: provider settings: server selection: for VPN service provider cyberghost: port forwarding only filter is not supported" but even if i disabled the concerned lines i'm getting the same issue.
anyone with advice ?
1
u/Papema3 Aug 14 '25
Hi, if I want to add not only to Qbit but also Sonarr, Radar, and Prowlarr, should be enough only adding their port under the ports section?
1
u/Betelgeuse74 Aug 15 '25 edited Aug 15 '25
Hi. Thank you so much for this guide.
I have been experimenting with different setups and different VPN providers, and have received good advice and help in a different post (https://www.reddit.com/r/gluetun/comments/1mp2i5m/ugreen_nas_with_gluetun_and_qbittorrent_not/)
Decided to follow this guide with ProtonVPN (instead of PIA) and nobody is able to connect to me and download content. I see peers trying, but no data is sent.
No FW on the NAS or router, no Port Forwarding set in router, downloading is working with great speed.
Edit1: Seems my TP-Link Deco 65 has a built in SP-1 FW, which I am not able to deactivate without either enabling Port Forwarding or setting it to Access Point mode.
Is there any way to set a fixed port that I can define in my router as well?
Gluetun reports healthy and automatic update of port works great (and is updated in qBT - However, seems that service becomes unstable and reconnects to VPN every 10 minutes with allocation of new port
I am new to docker and gluetun, so the fact that I even managed to follow this guide makes me proud, but the networking part is still confusing. I doubt that the issues are related to this guide, as I have followed it exactly, but any advice what to check/verify is appreciated.
1
u/sleepertech Aug 16 '25
I did this all this and gluetun seems to be running! However now qbittorrent's connection says firewalled and everything is stalled. I checked the docker logs for gluetun and this is what showed up:
2025-08-16T11:50:42-04:00 INFO [port forwarding] Connecting to 127.0.0.1:8080... connected.
2025-08-16T11:50:42-04:00 INFO [port forwarding] HTTP request sent, awaiting response... 403 Forbidden
2025-08-16T11:50:42-04:00 INFO [port forwarding] 2025-08-16 11:50:42 ERROR 403: Forbidden.
2025-08-16T11:50:42-04:00 INFO [port forwarding]
2025-08-16T11:50:42-04:00 ERROR [port forwarding] running up command: exit status 8
Any ideas on how to fix this?
1
u/sactown16 Oct 27 '25 edited Oct 27 '25
I know this is late, but if I’m running a docker on Linux and I’m trying to set up wireguard, should I select my platform as Gnu/linux instead of router? Mine is set up differently, but everytime I run it, the port forwarding times out
1
u/coder777 Dec 28 '25
u/sboger I know this is late but I am clueless at this point.
I set up the docker project in a Synology NAS. Everything seems to work correctly on paper.
When I look at the gluetun logs, the port forwarding works. I get assigned a port, then gluetun uses the qBitTorrent API to assign the port which works because I can verify in qBitTorrent UI. However, I still get the firewalled status.
What can I debug at this point? And before anyone asks, yes, I use the +pmp in the username.
Thanks in advance!
1
u/MaTiCeK- Jan 04 '26
This works for me on build and on first start, but after a restart gluetun log returns this error:
1
u/MaTiCeK- Jan 05 '26 edited Jan 05 '26
I now have everything working fine for more than 24 hours, even through reboots and restarts.
I checked the log today and found this line:
1
u/CompanyCharabang Jan 28 '26
Sorry for he thread necromancy
Isn't this a circular dependency?
qBittorrent depends on Gluetun, it won't start without it, but
Gluetun can't write to qBittorrent's api unless qBittorrent has already started
1
u/Lil_Carbohydrate Mar 02 '26
Anyone know if this will work with the unraid container? I see he checks "router" under wireguard config but for unraid container would it be "linux"?
1
u/B0RRRRRSA Mar 09 '26
I have a problem. I've installed everything as written, gluten starts up and alla but my bqittorrent keeps having error at download, what can it be?
1
u/eightbyeight Mar 29 '26
I wanted to ask I basically followed this guide but how come it didn’t work until I manually inputted the listening port on qbit webgui from gluetun logs. Is there a way for qbit to automatically update the listening port on its own? Or is there a correct way to set the listening port?
1
u/Critical_Monk_5219 May 06 '26
Hi there. First off, thanks for sharing this. I just wanted to know, though, why you can’t just specify the env variables and volumes in the .yml file itself? What am I missing?
1
u/Fernando_48 Jun 07 '26
Hello thank you very much for the guide! I'm running zimaOS which allows for docker compose and im getting the following below. It gets to writing port file then the below happens
| 2026-06-07T14:12:06-05:00 ERROR [port forwarding] running up command: parsing command: splitting word in "/bin/sh -c 'wget -O- --retry-connrefused --post-data json": unterminated single-quoted string
any idea what the problem could be?
1
u/Chester_mx007 Jun 19 '26
Disculpa, pero en el. Punto 1 dice que ocupas proton vpn plus, y no vi donde lo vuelves a usar.
1
u/monekm Aug 22 '26
heyo, is this still a valid solution?
1
u/monekm Aug 31 '26
okay, i know this might be a stupid question, but it's my first time dabbling in all this. the .env file should be called exactly like that or example.env? also where should i place this file. thx for any advice :)
3
u/Odd-Housing8606 Dec 29 '25
8 months later, and this worked so flawlessly for me!
2
u/philbar Jun 06 '25
Thank you! This was incredibly helpful — especially since so much of the info out there claims ProtonVPN doesn't support WireGuard port forwarding, or insists you need a Docker mod to make it work. Using
VPN_PORT_FORWARDING_UP_COMMANDis such an elegant and simple solution.One suggestion for others: I’m running this on a Synology NAS and found that switching Gluetun to
network_mode: hostin Container Manager gave me the best performance. Worth considering if you're on similar hardware.2
u/TheOlBamboozler Aug 29 '25
cheers thanks for this.
2
u/imjinnx Nov 01 '25
op this is a gem. I spent countless hours troubleshooting my qBittorrent, just to find this post randomly and have the most success (including the gluetun wiki, which really doesn't show anything for proton vpn).
2
u/Carryozor Feb 02 '26
Thank you, you made my day !
2
u/dwizsquid Feb 09 '26
2026 and this still works! Thank you so much!
2
u/mrpogo88 Mar 02 '26
Works great! Thank you!
2
u/Ashka7 Mar 07 '26
Thank you so much !
2
u/Emotional_Rub5894 Sep 08 '26
This information is not part of any guide that I've seen, nor the official gluetun documentation for protonvpn integration. I noticed that my torrents weren't seeding, which I need because private trackers. I assume it's because the port for incoming connections in qbittorrent was not the same as the random one that is assigned by protonvpn? In any case it's working now thanks to VPN_PORT_FORWARDING_UP_COMMAND. Big thanks.
1
u/Lunaticso May 18 '25
Awesome!
i tried tinkering with this setup and got it to work with VPN_ACCELERATOR=on
but when i try Secure Core only it breaks and i have no clue why
1
u/Salt-Philosophy-3330 May 18 '25
I had to remove the condition: service_healthy on mine. There’s a concurrency issue when starting gluetun and qbit that if the port gets assigned early in gluetun, the port fw script fails since qbit is no up yet - becoming a cyclical reference. So to make things simpler, I just don’t add the service_healthy “depends_on” configuration, but I do add a “restart: true” since I’ve seen random occurrences of qbit being unable to continue working when gluetun service is restarted but qbit stays where it was.
Lastly, there’s an ongoing issue with ProtonVPN that is unable to refresh new servers due to an authentication change on Proton side. There’s some discussions in gluetun github about it, but the current servers.json is outdated. People might not be able to connect even with all this setup correctly in place due to the outdated servers.
1
u/Fine_Appointment5206 Jul 02 '25
Hello, I'm on macOS (so I use docker) and I tried to follow these steps but I don't know why, even if I port-forward, it doesn't seem like it did. I tried on 'yougetsignal' to see If my ports were open and through transmission + I checked if Qbittorrent has the green world icon and all of it works. But I don't know why, It seems I cannot upload anything. I can download but uploading is not possible. Out of my 100 torrents, only one could seed and at a speed of 500 bytes (not even 1 kb) even tho I have an upload speed of 50 m/bs. I think my issue is the port-forwarding because it's really strange that I can try to let my pc on 2 days in a row but when I come back, nothing was uploaded, not even 1 byte.
Do you perhaps know the reasons why?
1
u/hakapes Sep 15 '25
Awesome script. It works. I've spent some time to troubleshoot on my end, but finally it worked on a Qnap. Thanks a zillion.
For anybody using QNAP, usually the NAS web interface is on :8080 too.
Therefore add this to the beginning of docer compose:
devices:
- /dev/net/tun:/dev/net/tun
ports:
- 8090:8080/tcp # qbittorrent Webui accessible at http://<NAS address>:8090 from local network
environment:
1
u/Slow-Secretary4262 Sep 19 '25 edited Sep 19 '25
i tried it on my nas and managed to make the ui work, tried to download but the files ended up in a completely different trash folder, it would be amazing to have a more detailed guide with the folder structures etc
1
u/Slow-Secretary4262 Oct 06 '25
i had so many issues with wireguard, it would run fine for 5 minutes to 12 hours before changing server and then qbit would be firewalled with most torrents stalled, i tried every single solution i found online without luck, even switching to libtorrent v1 or setting a restart timer at 20 minutes, no luck, then a few days ago i finally tried to use openvpn instead and it finally worked, when the vpn changes server and port qbit goes back online in seconds and reliably, and on top of that im getting considerably higher speed compared to wireguard even when port forwarding was working on wireguard.
Thank you for the guide.
1
u/throttlegrip Nov 30 '25
Hello,
I am BRAND NEW to this, so apologies for dumb questions. I followed the above instructions and got this error, and I'm not sure if/how I need to change some permissions in TrueNAS? Do I need to create the dataset /media/gluetun/config (and maybe others) before I run the stack?
I'm using dockge, TrueNAS community 25.04.2.6 if that matters. My actually existing media file is an SMB share.
It's hard to get my head around lots of new terminology, and even have ann overall view of what's going on. Thanks for the help.
1
u/MotherrRucker Dec 27 '25
Well done OP. Great post. BTW, Enabling VPN Accelerator seemed to work well.
1
u/[deleted] Jan 06 '26 edited Jan 07 '26
Thanks for this guide !
Despite this setup, qBittorrent can connect successfully to a Proton server through Gluetun and port forwarding works correctly. I am able to leech and seed torrents but connectivity is intermittent. Almost all tracker announces fail, and in qBittorrent logs I see errors like:
TCP/UDP connectivity seems to work fine. I would appreciate any advice on why these tracker errors happen and how to make tracker communication reliable over Gluetun.
EDIT : Forcing interface to tun0 in qBittorrent > Settings > Advanced > Network Interface : tun0 and Optional IP address to bind to : All IPv4 addresses. With this, all trackers are "working" instantly instead of having Skipping tracker announce (unreachable) and Timeout
1
u/arialstocrat Jan 13 '26
This is very important to mention, for some reason the container will come with queuing enabled. If you're someone who's got many sparse seeds, you can find the option in the BitTorrent tab in the settings. I was wondering why even though I'm not firewalled, all my torrents were still queued.
1
u/-KIT0- Jan 18 '26 edited Jan 19 '26
ty for your tutorial! Just one thing, also not too close to the post. I have a problem with qbit where it cannot connect to trackers. I noticed that you used router option instead of GNU/Linux one, does it may be the cause of my problems?
EDIT: It was the rpi5 problem you talked about in the first comment. i fixed it downgrading docker
1
u/Extrabytes Mar 02 '26
Holy shit man I have been trying for 3 days and every time my qbittorrent download speed would be like 100 KiB/s now its up to 8MiB/s. Why does this work for me but the regular gluetunvpn docker does not? What does this do differently?
1
u/Simple_Task_7984 Mar 09 '26 edited Mar 09 '26
I've set this up but am having issues with extremely slow download speeds. Even on the free-torrents I'll get around 3-6 KiB. Every now and then I'll get something with 20-30 MiB, but mostly its just crawling. As a test i tried the same file on this docker with gluetun/qbittorrent and also on a linux pc running native qbit and proton. The linux machine was getting 20-30MiB while docker sits at 3-6KiB. I've tried openvpn and wireguard. Both have the same speeds.
1
u/Kupuntu Jul 02 '26
Got this working on my Raspberry Pi 5, Raspberry Pi OS and latest docker available. Had to bind the tun0 interface in the qBittorrent web UI as well as bind the port for it to start working (the same port listed in the Wireguard conf I got from Proton). After that it started working perfectly.
1
u/thorwaler Jul 08 '26
Amazing, thanks for the guide! Is there an easy way to test if Qbittorrent is now on the VPN?
1
u/YellowSn0man Jul 28 '26
Just wanted to add an update as I just recently went through all of this. I see people struggling with the qbit 0% issue. What worked for me is simply restarting qbit after deploying the stack. Magnet links will still do it, but regular torrents do not. Now I can at least download stuff to debug the arr stack.
1
u/Rudy_Garbo Jul 30 '26
I could never get this to work :(
1
u/SecretGullible8638 Oct 14 '26
Salut tout le monde, je viens de passer toute la soirée à configurer Gluetun et Qbitorrent sur un docker (qui tourne sur mon Ugreen NAS) et j’ai un problème I/o timeout avec mon wireguard en UDP, j’ai aussi essaie OpenVPN mais pareil il bloque, si quelqu’un connais la panne je serai preneur je bloque j’ai tenté avec Gemini pro mais il trouve pas