[Solved] Complete Newbie with a Pi 5 & PIA - How to Bind?

General support for problems installing or using Deluge
Post Reply
PanoramicPanda
New User
New User
Posts: 3
Joined: Wed Mar 27, 2024 1:19 pm

[Solved] Complete Newbie with a Pi 5 & PIA - How to Bind?

Post by PanoramicPanda »

I'm a complete Linux noob but have managed to stumble my own way through the Docs to set up Deluged as a service on the Pi, and I'm able to connect to it from the interface on my Windows machine. It listens to folders for files, and even copies completed downloads to my NAS. Huzzah!

However, regarding the VPN usage, I'm having all sorts of problems. I got PIA installed on the Pi - it's the one I've been using for years on Windows and already paid for, but I'm open to switching if it can make this easier. I currently have the PIA port forward set on the Incoming Port.

The current state seems to be if I reboot the Pi, torrents download & seed but show my current IP. I think this is because Deluged service starts up before PIA auto-connects, and it's just leaking my IP. Also PIA port sometimes changes, which requires me to check it and change it in the UI. Both of these feel like the wrong state if I want this thing to just be on and not need to check it anymore.

That led me to some googling to find out about binding PIA to Deluge, which first led me to this thread viewtopic.php?t=56243&sid=943a147ab8464 ... 7&start=10 where I tried the "tun0" approach. No dice. Nothing was downloaded or seeded.

I then tried following this post: viewtopic.php?p=230104#p230104
But was quickly lost with some of the commands not working. As I said, complete Linux Newbie here. I have NO clue what I'm doing.

I'm running the latest of everything to my knowledge. I am fairly tech-savvy, but Linux is a major blindspot in my knowledge, and I need a bit of a stronger guide here I think. Can anyone help?
Last edited by PanoramicPanda on Wed Mar 27, 2024 11:40 pm, edited 1 time in total.
mhertz
Moderator
Moderator
Posts: 2216
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Complete Newbie with a Pi 5 & PIA - How to Bind?

Post by mhertz »

If tun0 is correct adapter, then should work, check 'ip addr' or alike if having a tun0, but that is probably just for openvpn - I don't know anything about wireguard I'm affraid. Otherwise can use local IP of vpn interface instead. Need in both in and out fields.

There's a bug, fixed by djlegolas in still unmerged PR(merged in doadin's builds though), so need enter tun0 or IP from either web-ui or core.conf, until said PR merged.

For auto updating port, then need Google for a script for such, as I haven't had PIA for years, so don't know there webapi.
PanoramicPanda
New User
New User
Posts: 3
Joined: Wed Mar 27, 2024 1:19 pm

Re: Complete Newbie with a Pi 5 & PIA - How to Bind?

Post by PanoramicPanda »

Setting listen_interface and outgoing_interface to "tun0" (which is PIA's OpenVPN interface according to `ifconfig`), makes my torrents not do anything. No downloading, no seeding. "Port Issue" in lower right corner, "N/A" for IP at bottom. Incoming port is set to PIA's current port, outgoing is random. I feel like that's the fix to focus on first before auto-updating.

Can I get it working at all, then focus on port update. 😂

New check: used yougetsignal.com to check the port forwarding of the VPN in general and it's closed according to the check. That may be my issue, working to dig into that.
Last edited by PanoramicPanda on Wed Mar 27, 2024 2:52 pm, edited 1 time in total.
mhertz
Moderator
Moderator
Posts: 2216
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Complete Newbie with a Pi 5 & PIA - How to Bind?

Post by mhertz »

Do you have a tun0 interface? Otherwise can use ip(of tun0) as said. And need use only webui or core.conf for this.

Edit: Sorry, you clearly stated as such. Restart deluged, and vpn, it should work, atleast downloading. Edit, unless firewall or whatnot. Sorry, not time now, but i'll think about it, and in meantime please others chime in if possible, thanks.
PanoramicPanda
New User
New User
Posts: 3
Joined: Wed Mar 27, 2024 1:19 pm

Re: Complete Newbie with a Pi 5 & PIA - How to Bind?

Post by PanoramicPanda »

I do indeed have tun0, and after restarting deluged it does not work. A

Code: Select all

ncat -l <port>
test did spit me out information, so it seems to be port forwarding correctly. Just can't see it from yougetsignal for some reason, so maybe that's the issue maybe it's not. 😔

Tried setting them to the IP directly instead of "tun0", but still no dice. Thank you for doing this back and forth - helps me to see that I seem to be doing what should work at least.

Edit: Worth noting that "Test Active Port" always gives a warning sign ⚠
Edit 2: Using ncat and then using yougetsignal will ping the port as open. So it seems Deluge just isn't actually using it? I have active torrents attempting to download/seed.
Edit 3: For the sake of details - ifconfig gets me eth0 (I assume my own network), lo (local), tun0 (I assume PIA VPN, is there a way to tell?), and wlan0 (I assume wireless network, which I don't have setup.

Also, is that a thing with this forum where all posts wait for moderator approval? Or a side-effect of being a new registered user? 😂
Last edited by PanoramicPanda on Wed Mar 27, 2024 4:29 pm, edited 3 times in total.
PanoramicPanda
New User
New User
Posts: 3
Joined: Wed Mar 27, 2024 1:19 pm

Re: Complete Newbie with a Pi 5 & PIA - How to Bind?

Post by PanoramicPanda »

Okay, update: In ifconfig under tun0, there's an row for inet: 10.23.xx.xxx. I used that instead of "tun0" or the IP PIA gives me (172.98.xx.xxx) and downloads started working! Test active port also gives me a checkmark! The IP at the bottom of deluge is also the IP that PIA shows me as.

The file I just got done with started seeding, but none of my old ones are. That could just be a "no one connecting to me" problem though.

Looks like I need to find a way to get that inet value and not the VPN IP via a script and then assign those. That at least gets me a track to work down!
mhertz
Moderator
Moderator
Posts: 2216
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Complete Newbie with a Pi 5 & PIA - How to Bind?

Post by mhertz »

Good job, just came home little ago and see you fixed the issue yourself kudos! :)

Yeah, new users need approval now, as spambots and alike became a big nuisance and a quick stop gap to circumvent, meanwhile looking for other means(Cas).

Anyway, there's different ways to accomplish that e.g. parse that value out, but most normally you use $4 and an UP script, e.g --up <script/command> and need also --script-security 2 btw. It's probably easiest though to add to your openvpn config, like:

Code: Select all

script-security 2
up /etc/openvpn/up.sh
up.sh need be executable and it is run as root I believe. Then can e.g. use sed etc to change listen_interface and outgoing_interface in core.conf, but easier to use deluge-console like e.g 'deluge-console config -s listen_interface $4' in up.sh and same for other command etc. Can also add code needed for getting the forwarded port presumably and add to deluge in same way. Note, might have to use other than 'up', there's route-up and others too, and some run before others and so maybe too early to have gotten the IP yet, so need experiment, or add slight delay in script, or better, a loop to keep querying only until value ready.

Just some food for though, and good job again :)

Edit: BTW, I was thinking to have you run a curl command through --interface tun0, and check logs etc, before reading you fixed it, but now looking up the command for curl(--interface) actually gave me as first link, a page to a post with someone on rpi not able to use tun0 only IP, as you, and a poster stated it was because needed be root or sudo on rpi, for whatever reason, just for completeness...
PanoramicPanda
New User
New User
Posts: 3
Joined: Wed Mar 27, 2024 1:19 pm

Re: Complete Newbie with a Pi 5 & PIA - How to Bind?

Post by PanoramicPanda »

Since I'm a firm believer of leaving behind the steps I needed to help others:

I wound up with the following script I adapted and put on a cronjob to check every 2 hours. Seems to be working!

Code: Select all

#!/usr/bin/env bash
# Author: PanoramicPanda
# Based on https://github.com/HTPCGuides/pia-port-forwarding-scripts/blob/master/deluge-pia-port-forwarding.sh

# Set path for root Cron Job
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

VPNINTERFACE=tun0
DESIRED_IP=$(ifconfig $VPNINTERFACE | awk '/inet / {print $2}' | awk 'BEGIN { FS = ":" } {print $(NF)}')
#echo "Desired IP: $DESIRED_IP"

DELUGEUSER=
DELUGEPASS=
DELUGEHOST=localhost
DELUGECMD="connect $DELUGEHOST:58846 $DELUGEUSER $DELUGEPASS"

#request new port
DESIRED_PORT=$(piactl get portforward)
#echo "Desired Port: $DESIRED_PORT"

get_current_settings() {
	echo "Getting current settings..."
	local current_ports_output=$(deluge-console "$DELUGECMD; config listen_ports")
#	echo "Current ports config: $current_ports_output"
	CURRENT_PORTS=$(echo $current_ports_output | grep -oP '(?<=listen_ports: \()\d+')
#	echo "Current Port: $CURRENT_PORTS"

	local current_interface_output=$(deluge-console "$DELUGECMD; config listen_interface")
#	echo "Current interface config: $current_interface_output"
	CURRENT_INTERFACE=$(echo $current_interface_output | grep -oP '(?<=listen_interface: )[\d\.]+')
#	echo "Current Interface: $CURRENT_INTERFACE"
}

update_settings_if_needed() {
	echo "Seeing if we need to update..."
	if [ "$CURRENT_PORTS" != "$DESIRED_PORT" ]; then
		echo "Updating ports to $DESIRED_PORT"
		deluge-console "$DELUGECMD; config --set listen_ports ($DESIRED_PORT,$DESIRED_PORT)"
	else
		echo "listen_ports is already set to $DESIRED_PORT"
	fi

	if [ "$CURRENT_INTERFACE" != "$DESIRED_IP" ]; then
		echo "Updating interface to $DESIRED_IP"
		deluge-console "$DELUGECMD; config --set listen_interface $DESIRED_IP; config --set outgoing_interface $DESIRED_IP"
	else
		echo "Interface already set to $DESIRED_IP"
	fi
}

get_current_settings
update_settings_if_needed
Cron is as such:

Code: Select all

@reboot sleep 60 && /home/scripts/portforward.sh | while IFS= read -r line; do echo "$(date) $line"; done >> /var/log/pia_portforward.log 2>&1 #PIA Port Forward
0 */2 * * * /home/scripts/portforward.sh | while IFS= read -r line; do echo "$(date) $line"; done >> /var/log/pia_portforward.log 2>&1 #PIA Port Forward
with a log rotation of:

Code: Select all

/var/log/pia_portforward.log {
        daily
        compress
        rotate 7
}
I also had to delete the two lines in util.py as mentioned in this post: viewtopic.php?p=236670#p236670
Post Reply