Page 1 of 1

Binding to specific IP

Posted: Mon Oct 07, 2013 12:00 pm
by ffsppl
I've got two interfaces both configured with their own IP. Say their IPs are 1.1.1.1 and 2.2.2.2, and I wanted to bind deluged to 2.2.2.2; I've done this with deluged -i 2.2.2.2 -u 2.2.2.2. Here's the output from lsof:

Code: Select all

deluged  23629     2000    8u  IPv4 10667839      0t0  TCP 2.2.2.2:58846 (LISTEN)
deluged  23629     2000    9u  IPv4 10667842      0t0  TCP 2.2.2.2:55914 (LISTEN)
deluged  23629     2000   10u  IPv4 10667845      0t0  UDP *:1900
deluged  23629     2000   11u  IPv4 10667846      0t0  UDP 127.0.0.1:1900
deluged  23629     2000   12u  IPv4 10667847      0t0  UDP 127.0.0.1:33285
deluged  23629     2000   13u  IPv4 10667848      0t0  UDP 1.1.1.1:1900
deluged  23629     2000   14u  IPv4 10667849      0t0  UDP 1.1.1.1:40736
deluged  23629     2000   15u  IPv4 10667850      0t0  UDP 2.2.2.2:1900
deluged  23629     2000   16u  IPv4 10667851      0t0  UDP 2.2.2.2:54027
deluged  23629     2000   18u  IPv4 10667858      0t0  UDP *:35130
deluged  23629     2000   19u  IPv4 10667860      0t0  UDP *:6771
deluged  23629     2000   20u  IPv4 10667861      0t0  UDP 127.0.0.1:6771
deluged  23629     2000   21u  IPv4 10667862      0t0  UDP 127.0.0.1:40304
deluged  23629     2000   22u  IPv4 10667863      0t0  UDP 1.1.1.1:6771
deluged  23629     2000   23u  IPv4 10667864      0t0  UDP 1.1.1.1:37867
deluged  23629     2000   24u  IPv4 10667865      0t0  UDP 2.2.2.2:6771
deluged  23629     2000   25u  IPv4 10667866      0t0  UDP 2.2.2.2:33008
It's clear deluged feels it is free to make use of 1.1.1.1, but I'm at least hoping that all actual torrent traffic is bound to 2.2.2.2 and I'm looking for someone to confirm that before I run it for real and would love to hear from someone who knows for sure whether this is the case. Just to be clear, what I mean by bound to 2.2.2.2 is that everything between me and a tracker and/or peers are seen as originating from 2.2.2.2.

Re: Binding to specific IP

Posted: Mon Oct 07, 2013 2:37 pm
by bro
Hi

As you can see, deluged is set up to listen on 2.2.2.2 only. But by default, the traffic initiated from deluged will follow the default route in the routing table, which presumable goes through 1.1.1.1. You'd have to handle this by adding rules to the routing table to divert the traffic you want through 2.2.2.2.

Re: Binding to specific IP

Posted: Mon Oct 07, 2013 3:46 pm
by ffsppl
Thanks for answering!

Does that mean that the -i flag doesn't necessarily mean that packets going to a tracker have 2.2.2.2 as the source address, even when given that I'm not altering the packets before they hit the wire?

Because my current thinking is that -i 2.2.2.2 has the effect of all outgoing packets having 2.2.2.2 as the source address regardless of what the routes are; if the routing is amiss then the packets simply hit a wall, and that's obviously on the user, but the packets still have 2.2.2.2 as the source, i.e. deluged sets the source based on -i and it's up to the rest of the system to then route and mangle the packets if needed . Have I got this wrong?

Re: Binding to specific IP

Posted: Tue Oct 08, 2013 2:39 pm
by bro
That is a good question.

When a peer connects to the libtorrent listen socket (2.2.2.2:55914), that socket is bound to 2.2.2.2, and packets sent from libtorrent on that socket would have source 2.2.2.2.
Also TCP connections initiated from deluged (libtorrent) to other peers should be bound to 2.2.2.2, and it looks to be the case when I check with tcpdump. I'm not sure if the traffic to the trackers are bound to 2.2.2.2, but I guess it should be.

As for all the UDP sockets,

These would be UPnP (40736 being random)
UDP 1.1.1.1:1900
UDP 1.1.1.1:40736
And these would be Local Service Discovery (37867 being random)
UDP 1.1.1.1:6771
UDP 1.1.1.1:37867

Re: Binding to specific IP

Posted: Tue Oct 08, 2013 11:21 pm
by ffsppl
bro wrote:When a peer connects to the libtorrent listen socket (2.2.2.2:55914), that socket is bound to 2.2.2.2, and packets sent from libtorrent on that socket would have source 2.2.2.2.
Also TCP connections initiated from deluged (libtorrent) to other peers should be bound to 2.2.2.2, and it looks to be the case when I check with tcpdump. I'm not sure if the traffic to the trackers are bound to 2.2.2.2, but I guess it should be.
It really would be an odd design choice if this wasn't the case but to be sure I went and tested it all in a controlled environment and came to the same conclusion, and I'm now absolutely certain that both swarm and tracker only see the IP deluged is bound to.

Not sure if the auxiliary functions opening all those UDP sockets would have leaked my other IP in anyway but just for peace of mind I disabled these and got a very satisfying output from lsof this time... nothing but 2.2.2.2 for deluged.

Thanks for the help.