Is listen_interface for VPNs?

General support for problems installing or using Deluge
Post Reply
Airton
New User
New User
Posts: 7
Joined: Tue Oct 30, 2018 8:58 am

Is listen_interface for VPNs?

Post by Airton »

Background
I have a Raspbian/Debian system running deluged (1.3.13+git20161), which I access via another Linux box running the deluge front-end. I am trying to force torrents through my VPN, while leaving the UI accessible through the local network.

My understanding is that I should be able to do this selective routing through deluged itself, via listen_interface (also available in the GUI through Preferences > Network > Interface). However, I can't seem to find any clear instructions on how to use this. How precisely should I use listen_interface?

What I've tried

I am using an OpenVPN config, which I have tested by itself and is working fine. I then add no-pull to the OpenVPN config file, and restart it. I attempt to get the IP address of tun0 with

Code: Select all

$ ip route show table main
default via 192.168.1.100 dev eth0 
10.15.0.0/16 dev tun0 proto kernel scope link src 10.15.0.2 
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.91 
or sometimes

Code: Select all

$ ip route show table main
default via 192.168.1.100 dev eth0 
10.15.0.0/16 dev tun0 proto kernel scope link src 10.15.0.9 
<VPN_public_IP> via 192.168.1.100 dev eth0 
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.91 
I try to set listen_interface to the IP address above, i.e. 10.15.0.2 or 10.15.0.9, then restart deluged, but I get no incoming connections, and can't connect to anything.

I am aware of other methods to use a VPN with deluged, but the "Interface" method seemed easier. Am I using this setting correctly?
Airton
New User
New User
Posts: 7
Joined: Tue Oct 30, 2018 8:58 am

Re: Is listen_interface for VPNs?

Post by Airton »

And… I'm probably justified in a bump! Still looking for an answer to this. Thank you in advance.
mhertz
Moderator
Moderator
Posts: 2215
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Is listen_interface for VPNs?

Post by mhertz »

The listen_interface option is for binding to whatever IP wanted bound to, so you're using the option correctly it seems.

I'm not very good at networking honestly, so not sure I can help you, but what is it you're after? I couldn't fully understand if you're after split tunneling or not regarding the VPN? Sounds like it from the nopull, but you only mention that you want this for leaving UI accesible from local network, where by UI I guess you mean deluge UI.

Btw, deluge1 only has the single binding option, and deluge2 features also the second one i.e. outgoing_interface, so personally i'm not that thrilled about using binding in deluge1, but whatever. It's seemingly the most important option though howvever, to be fair.

Last, of-course incoming connections will only be possible through using VPN supporting port-forwarding.

Back when I started with VPN split-tunneling, then I used somewhat likeminded approach, just rtorrent, but regardless, and followed this guide here, which in addition to the nopull addition also e.g. adds route-changes etc: https://gist.github.com/awidegreen/825794317f98a941107f
Airton
New User
New User
Posts: 7
Joined: Tue Oct 30, 2018 8:58 am

Re: Is listen_interface for VPNs?

Post by Airton »

Thank you mhertz! Sorry, I should have updated my post. I'm running Arch Linux now, so it is deluge2 that I'm running.

Yes, I am trying to do split tunnelling. All traffic should be via the VPN, except the deluge UI. I'm running deluged on my server, and I want to connect to its interface via my local network, using the deluge client.

I can see deluge's preferences now has "Incoming Address" and "Outgoing Interface". However, it looks like I misunderstood what these do. In my original post, I thought that I would use one of these to connect to the VPN, and the deluge UI would pass through the local network by default. However, from your post, it seems like I should manually (i.e. via the CLI) connect deluge to the VPN, and then the "Interface" option is for sending deluge's UI through the local network? I got it the wrong way around?

Thank you again for your help!

EDIT: Hmmm… but reading your link, it looks like the key is `exec rtorrent -b "$bind2ip"`. Looking at `man deluge`, I can see `--interface=ip_address` and `--ui-interface=ip_address`, but shouldn't these be the equivalent parameters to "Incoming Address" and "Outgoing Interface" in the GUI? I tried setting "Incoming Address" to the IP address `10.10.0.9` (derived from `ip`), but I couldn't get a torrent connection.

EDIT2: I also tried using `/etc/openvpn/vpn-up.sh` as per your link, but I get the error `Error: any valid address is expected rather than "".` It looks like `ifconfig_remote` is empty, so I tried putting in `ifconfig_remote=$5` at the beginning of the script, but now after `ip route add table mullvadtunnel default via 255.255.0.0` I get `Error: Nexthop has invalid gateway.`

EDIT3: Got it working! Kinda! So for now, I manually perform the "up" script. Taking some advice from here, I firstly get the IP addresses:

Code: Select all

$ ip route show table main
...
10.10.0.0/16 dev tun0 proto kernel scope link src 10.10.0.5 
...
$ ipcalc 10.10.0.0/16
...
HostMax:   10.10.255.254        00001010.00001010. 11111111.11111110
...
Then using these IP addresses:

Code: Select all

$ sudo ip rule add from 10.10.0.5 table mullvadtunnel
$ sudo ip route add table mullvadtunnel default via 10.10.255.254
$ sudo ip route add table mullvadtunnel 10.10.255.254 via 10.10.0.5 dev tun0
I can code this later to extract these programatically, but for testing purposes this works fine. I then used the `10.10.0.5` address for deluge's "Incoming Address" in the GUI, restart the systemd service, and it works perfectly! Torrents go through the VPN, and deluge UI through the local network! I have no idea why the ifconfig_remote was failing before.

However, one major issue is that this IP address appears to change each time I connect to the VPN. So far I've seen 10.10.0.3, 10.10.0.5, 10.10.0.6, and 10.10.0.8. If I hardcode one of these IP addresses into deluge, then it may well change. I guess I could hack something into the VPN-up script to launch deluge with a different IP address each time, but this is starting to feel very suboptimal, and potentially a security risk. Is there a better way?
mhertz
Moderator
Moderator
Posts: 2215
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Is listen_interface for VPNs?

Post by mhertz »

Sorry for confusion :) I thought you where after the general split routing term, where you wanted having torrenting over VPN and everything else, e.g. web-browsing etc, over normal connection, though you all along stated what you wanted, and I was just slow in uptake seemingly :)

Anyway, if just wanting a regular VPN setup and controlling deluge UIs from LAN, then couldn't you just run without any changes? Honest question, and again, I don't know much about networking stuff, besides the very basics pretty much(and some ssh etc, but noob honestly :) ). I did test this actually, and could connect with deluge GTK client to a deluge server on other PC in LAN and openvpn running also, on same PC in LAN.

In some setups, I believe mostly with split routing, in the sence of e.g. torrenting only VPN traffic, then there can be issues like you suggested, and instead e.g. reverse proxies like nginx or ssh port forwarding is needed, I have read at-least. If you haven't already, there's lots of info herein, though not strictly for your use-case but regardless.: viewtopic.php?t=49883

The post I linked to initially, was because I assumed you wanted the split-routing before mentioned of e.g. only torrenting over VPN, and the rtorrent command to bind to vpn, should instead be translated to the deluge UI or CLI options of binding to network interface. Yes, those options are, as you stated, not for what you initially thought, and are more for binding specific traffic, e.g. in the before-mentioned torrent-over-vpn-only scenario, and/or also can act as a kill-switch at same time. You shouldn't really need it per-say for your scenario, or so i'm guessing atleast, but is a nice thing nonetheless, especially if you not already use other precatuions e.g. iptables rules etc, for proper kill-switch functionality. for mitigating leaks happening through connection drops.

Yeah, as you state, it's annoying as IP changes, so either you have to script it as you also stated, e.g. the up script supports, I believe $4 or %4, cannot remember terminology off-rip, which holds said local IP, and which could be defined to start deluged with -i and -o switch, for in/out IP binding or setting these options through deluge-console. Alternatively, then you could use ltconfig plugin and hardcode tun0 as listen_interfaces and outgoing_interfaces options, but under listen_interfaces option, you should add a port, e.g. tun0:xxxxx, where xxxx is a number for port choosen. There should be no port for the outgoing_interfaces option. If using this method, then that overrides the general deluge networking options of selected port to use, and so should ignore those options + the deluge binding options as you hardcode them directly. You could use tun0 under outgoing-interface in deluge, and just let ltconfig plugin handle the listen_interfaces option if wanted. The reason for that, is that the deluge listen_interface option doesn't support interface names like tun0 unfortunetly, and only IPs, where libtorrent options defined through ltconfig does however(even though deluge sets same libtorrent options behind the scene, but just haden't added support for using interface names as incoming bindings yet, unfortunetly).

Sorry for long babblings and initial confusion/misunderstandings. Also for not really knowing much about this subject in general, and still replying, so if others are in the know, then please jump in and take over, as would be more helpfull to OP.
Airton
New User
New User
Posts: 7
Joined: Tue Oct 30, 2018 8:58 am

Re: Is listen_interface for VPNs?

Post by Airton »

Anyway, if just wanting a regular VPN setup and controlling deluge UIs from LAN, then couldn't you just run without any changes?
I think I still may have been unclear. I have numerous programs on my server that I don't want running through the VPN. I only want deluge's torrents through the VPN (but not deluge's UI).

I had a read of the links, and I think that this solution is probably best, i.e. opening a connection to the VPN, then starting deluge with -i. I had a look at ltconfig, but it looks like it is not yet compatible with deluge2.

No big deal though. Having thought more, I think it should be relatively easy enough to trigger a deluge restart after reconnecting to the VPN. I think this is probably also the safest option too, because it prevents IP leaks. I'll have more of a play, and write a tutorial up and post it here. I feel like this is a pretty common use case that should have a tutorial somewhere!
User avatar
gderf
Seeder
Seeder
Posts: 155
Joined: Sat Jun 18, 2016 1:32 am

Re: Is listen_interface for VPNs?

Post by gderf »

Have you considered using a docker that combines deluge with OpenVPN such as binhex/arch-delugevpn

https://hub.docker.com/r/binhex/arch-delugevpn
Airton
New User
New User
Posts: 7
Joined: Tue Oct 30, 2018 8:58 am

Re: Is listen_interface for VPNs?

Post by Airton »

gderf wrote:Have you considered using a docker that combines deluge with OpenVPN such as binhex/arch-delugevpn
Thank you for the suggestion gderf. I actually did come across that option previously, but it wouldn't work on my system, as it only works on 64-bit systems, and I'm running a 32-bit architecture. It would have been much simpler though!

EDIT: guide completed and posted here!
Post Reply