iconBjarne Verschorre

../port-forwarding-proton-vpn.md

Introduction

Proton VPN is a go to option if you’re in the Proton ecosystem. It’s a great VPN with port forwarding capabilities. Their website isn’t that STRAIGHT to the point as I like it so I’m writing this guide to help you (me) out. I’m doing this on the lastest version of Linux Mint.

Things to keep in mind

The script

#!/bin/bash

# Function to delete the UFW rule
delete_ufw_rule() {
    sudo ufw delete allow in on tun0 to 10.96.0.0/16 port $port comment "VPN Port Forward"
    exit 0
}

# Set up a trap to call delete_ufw_rule on SIGINT (Ctrl+C)
trap delete_ufw_rule SIGINT

# Get the port number
port=$(natpmpc -a 1 0 tcp 60 -g 10.2.0.1 | grep 'Mapped public port' | sed -E 's/.*Mapped public port ([0-9]+) protocol TCP to local port [0-9]+ lifetime [0-9]+/\1/')

# Add the UFW rule
sudo ufw allow in on tun0 to 10.96.0.0/16 port $port comment "VPN Port Forward"

# Main loop
while true; do
    date
    natpmpc -a 1 0 udp 60 -g 10.2.0.1 && natpmpc -a 1 0 tcp 60 -g 10.2.0.1 || { echo -e "ERROR with natpmpc command \a"; break; }
    sleep 45
done

# This line will not be reached if the script is interrupted
delete_ufw_rule

How it works

It will get the port number from the VPN server and open that port in your firewall. It will then keep refreshing the port every 45 seconds. If the script is interrupted, it will delete the UFW rule.

So just run this script in the background to (keep) open the port.

References

← Guide to Crowdsec Taking the SC-900 →