I would like to set my source port when I connect to the tor network. I know that the destination port is set irrespectively if you use a bridge or node to connect for out bound traffic. I would like tor to use a specific port all ways for the destination port for inbound traffic or source port for out bound traffic bound to a specific ip address. How can I do this? I am using tails.

I used this command echo Reachableaddresses IP:port | sudo tee -a /etc/tor/torrc it does not work still the source port is random

  • Source port it decided by your OS kernel. Can you clarify the use case? I can't think of any good reason to do this, and doing so would be difficult.
    – cacahuatl
    Dec 1, 2016 at 9:03
  • @canonizingironize doing so is actually not a big deal, and the reason of doing so is a sado-masochistic firewall/gate in front of user to reach Internet. I saw quite a samples myself: for example, if DNS query is not originating from port 53 - it will be dropped...
    – Alexey Vesnin
    Dec 1, 2016 at 12:31
  • Really? How did you make two TCP DNS queries at the same time?
    – cacahuatl
    Dec 1, 2016 at 19:14
  • So anyway, as Alexey has also demonstrated he doesn't understand, doing this would fundamentally break networking.
    – cacahuatl
    Dec 3, 2016 at 19:50

2 Answers 2


Write a server and learn the ways: You listen to a port, say 53 and then block all use of port 53. Nobody else can use it, and you are notified by the kernel of new messages on this. You do not open it like a file, but bind and connect to it, and after "fd = Connect();" you listen() to it and can even use regular "read(fd, buf,len)" and "write(fd,buf,len)" like to any other file, terminate with "close(fd)" and then others can use port 53.

People have mystified these and hide them in fancy routines with numerous parameters. The above is what it all boils down to.


ReachableAddress is not related to your issue at all! The trick can be done in full depth only by a firewall - Tor does not have this option for a various reasons. Use a container/vm with Tor inside and - when you're routing it's outbound traffic - switch the port and address.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .