0

I want to bind a server to port 1023. If I specify any free port > 1007, I have a "address already in use" error, but it works for ports <= 1007. Working as root on Debian 7.8...

Any idea??

Thanks in advance

greg
  • 169
  • 11
  • What does netstat -l show? Are you really sure it's free? – hookenz Jun 16 '15 at 02:07
  • @Matt I'm positive it's free (unless I have a rootkit on all ports above 1007), I've tested a bunch of random ports which don't appear binded with netstat. – greg Jun 16 '15 at 02:23
  • Are you sure the process is starting as root? or hasn't demoted itself before binding? – hookenz Jun 16 '15 at 02:24
  • Can you try binding a high port like 65530 ? you said "all above", if this were true you couldn't also ssh out etc. – hookenz Jun 16 '15 at 02:26
  • @Matt if it was demoted it wouldn't be able to bind to port 1006, for example, would it? – greg Jun 16 '15 at 02:26
  • @Matt good point I can bind to anything >= 1024, so it's really the range 1008-1023 which is "unbindable"... – greg Jun 16 '15 at 02:30
  • Note: I'm working with IPv4 only – greg Jun 16 '15 at 02:32
  • 2
    Try running 'netstat -tulpn' as root to see what process might be using that range of ports. My guess is, another process is using those ports for real. – hookenz Jun 16 '15 at 02:42
  • 1
    @Matt you're correct but these connection are ESTABLISHED and don't show on "netstat -tulpn", I had to use "netstat -tupan" to find them... silly me! – greg Jun 16 '15 at 02:47

2 Answers2

0

Ports below 1024 are considered system ports and require supervisor privileges to use. To avoid a port conflict you should use a non reserved port above 1024.

To see if there is a service already using the port address, perform the following command:

netstat -lntu

https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports

Arlion
  • 608
  • 1
  • 5
  • 17
  • I'm root so I have supervisors privileges. Furthermore the boundary is not 1024 it's 1007 and it's the other way round: I CAN bind BELOW 1007 and I CANNOT bind ABOVE 1007. – greg Jun 16 '15 at 02:25
  • See statement in question: "Working as root" – hookenz Jun 16 '15 at 02:25
0

OK I found it, a process was actually using all these ports but not in a daemon way (not LISTENing). Not really clean from the developer :(

Thanks for your help

greg
  • 169
  • 11