rejetto forum

[SOLVED] (Debian/Wine) Port 80 already in use... except it's not

neuro · 2 · 7795

0 Members and 1 Guest are viewing this topic.

Offline neuro

  • Occasional poster
  • *
    • Posts: 2
    • View Profile
I suspect that it's not even a real HFS problem,but anyways, here it is: When I try to set HFS to use listen on port 80, it returns  "Cannot open port. It is already used by another software".

The OS is a newly installed Debian Squeeze running HFS with Wine.

The tricks listed here didn't help much; the 'best' result being the output of netstat -lnptu that listed all the listening ports that I was aware of. No trace of port 80.

Wonder if anyone knows where the problem is
« Last Edit: July 20, 2011, 01:41:30 PM by neuro »


Offline neuro

  • Occasional poster
  • *
    • Posts: 2
    • View Profile
OK I figured it out. I'm posting the solution in case someone else has the same problem.

As I said in my previous post, I'm running HFS on Debian using Wine. HSF finds that port 80 is unreachable and assumes that it's being used by something else, hence the 'another software is using it' message.
I used all the tricks that I could google up to find out what was using port 80, and it seemed that nothing was.
When I googled something along the lines of 'what is using port 80', the real solution popped up right away.

Turns out that in Linux regular users can't open any ports under 1024. Programs must run as root to access those ports. On the other hand though, running Wine as root is highly discouraged (and often doesnt even work) so the solution is to use IPtables (default Linux command-line firewall) to switch ports.

Basically the concept is: packets come in through port 80 => IPtables redirects them to port 8080 => HFS listens on port 8080 => packets get through.

This is done running this command (as root)

iptables -t nat --A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

Then users will be able to access HFS on port 80 (i.e. without need to specify any port in the url), even though HFS is still listening on port 8080.

NOTE: The iptables command must be re-issued at each reboot, or included in a startup script

By the way, it may be a good idea to  change the message displayed on 'port unreachable' to something like "Unable to bind to selected port. It may be already in use, or unreachable for other reasons". I mean the message "it IS being used by other software" made me look the wrong way for two days (but on the other hand, port already in use is actually the problem in most cases...)
« Last Edit: August 29, 2011, 07:16:13 PM by neuro »