How to Share Pi OS via Torrent [with VPN]

How to Share Pi OS via Torrent [with VPN]

December 2, 2024

First of all: Why sharing Raspberry Pi OS?

I got some incompatibility issues with some IoT Projects and the latest Pi Images (bookworm, DEBIAN12).

So want to make sure that the projects that I place effort on will continue to work.

We can get Legacy images from here

But what if at some point they wont be available?

The raspberry team provides for each image a .torrent file so that any of us will become P2P keepers of the OS history.

⚠️
Make sure that you understand what you are sharing via P2P. This is just a guide to allow you to share Open Source Software with others.

How to Setup Torrents for a Raspberry Pi

I have been collecting some similar interesting Services to spin with Docker.

ℹ️
We will need Docker/Portainer - So get ready with this SelfHosting Script as described here

You have many alternatives, among them: QBittorrent, Transmission,…

Qbittorrent with the Raspberry Pi

You need this docker-compose config file:

---
version: "2.1"
services:
  qbittorrent:
    image: ghcr.io/linuxserver/qbittorrent
    container_name: qbittorrent
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Madrid
      - WEBUI_PORT=6011
    volumes:
      - /home/Docker/qbittorrent/config:/config
      - /home/Downloads:/downloads
    #network_mode: "container:your_gluetun_container_name" #change gluetun to your VPN container name   
    #network_mode: "service:your_gluetun_service_name" #change gluetun to your VPN service name  
    # ports: #you wont need the ports in this configuration file, you will need to include them in the Gluetun container
    #   - 6081:6881
    #   - 6081:6881/udp
    #   - 6011:6011  
    restart: unless-stopped

Thanks to this guide and this one for Transmission

Transmission with the Pi

---
version: "2.1"
services:
  transmission:
    image: ghcr.io/linuxserver/transmission 
    container_name: transmission
    environment:
      - PUID=1000 
      - PGID=1000 
      - TZ=Europe/Madrid 
    ports:
      - 9091:9091 #UI Port for Transmission
      - 51413:51413 
      - 51413:51413/udp 
    volumes:
      - /home/Docker/Torrents/Transmission/config:/config
      - /home/Downloads:/downloads
      - /home/Downloads/Transmission_watch:/watch
    restart: unless-stopped
ℹ️
When sharing content via P2P, you are exposing your public IP. You might want to use a VPN

How to Torrent with a VPN

Here I want to show you have to do it using the VPN you just setup.

But you can do similarly with 3rd party VPNs.

Choose one and use your wg0 network interface from the wireguard client:

version: "2.1"
services:
  qbittorrent:
    image: ghcr.io/linuxserver/qbittorrent
    container_name: qbittorrent
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Madrid
      - WEBUI_PORT=6011 #UI PORT FOR QBITTORRENT
    #network_mode: "container:your_gluetun_container_name" #change gluetun to your VPN container name   
    #network_mode: "service:your_gluetun_service_name" #change gluetun to your VPN service name  
    # ports: #you wont need the ports in this configuration file, you will need to include them in the Gluetun container
    #   - 6081:6881
    #   - 6081:6881/udp
    #   - 6011:6011        
    volumes:
      - /home/Docker/qbittorrent/config:/config
      - /home/Downloads:/downloads
    network_mode: "host"  # Use the host network stack (which includes wg0)
    restart: unless-stopped

Key Points to understand:

  1. network_mode: "host"

    • This allows the container to share the host network stack directly, including the wg0 interface.
  2. No Port Mapping

    • When using network_mode: "host", port mapping (ports:) is unnecessary since the container uses the host’s network stack.
  3. Ensure wg0 is Active

    • Before starting the container, ensure that your WireGuard interface (wg0) is active and routes traffic properly. Use the following command to check:
wg show
  1. Routing Through WireGuard
    • Verify that your host system routes the necessary traffic through the WireGuard tunnel. For example, you may need to ensure that the qBittorrent container traffic follows the correct wg0 routing rules.

Verify the Setup After starting the container with docker-compose up -d:

  1. Access the qBittorrent Web UI at http://<host-ip>:6011.
  2. Verify the external IP of your qBittorrent traffic to confirm it uses the WireGuard tunnel:
    • Check your IP address via a tracker (e.g., ipleak.net) or using the tracker settings in qBittorrent.
#docker exec -it qbittorrent sh
curl -sS https://ipinfo.io/json #the command to use
#wget -qO- https://ipinfo.io/json

#for windows you would use
#powershell -Command "(Invoke-WebRequest -Uri https://ipinfo.io/json).Content"

Conclusiones

So thats it for now.

You you can improve software availability and resilience.

Kind of share your work, but…share what you’ve saved?

At least, Ill keep a copy of Raspberry Pi OS (Debian 11) for the Pi.

And probably some good Armbian for the Orange Pi 5

⚠️
Sharing OSS OS images might seem trivial. But it can help smaller projects to get going!

FAQ

VPN Providers

Setup a VPN with Wireguard on a VPS

How to use Gluetun

How to check IPs

curl -sS https://ipinfo.io/json #the command to use
curl -sS http://ip-api.com/json/ #provides info about country, ISP, ...
curl -6 ifconfig.me #ipv6 info