2

Do reserved TCP/IP ports require that a program is running and bound to the port? If no such program is running or exists, can another program use this port? For example, on Linux, port 7 is reserved for an echo server. I assume there is some program running and is bound to port 7 of the machine. The program basically echos back input. If this program is stopped, will port 7 be released?

If I wrote my own echo server and bound it to some other port, wouldn't this port be released once my custom echo server program is killed?

Does the same thing happen for reserved ports?

Also, if all these programs are running on reserved ports, wouldn't they consume system resources even if they are blocked listening for a connection? Are these programs running at all times?

Mars
  • 4,677
  • 8
  • 43
  • 65

3 Answers3

3

Do reserved TCP/IP ports require that a program is running and bound to the port?

No.

If no such program is running or exists, can another program use this port?

Nothing to stop you, but it's still reserved, and users are entitled to complain to you if you misuse ports reserved for something else.

For example, on Linux, port 7 is reserved for an echo server. I assume there is some program running and is bound to port 7 of the machine. The program basically echos back input. If this program is stopped, will port 7 be released?

Yes.

If I wrote my own echo server and bound it to some other port, wouldn't this port be released once my custom echo server program is killed?

Yes.

Does the same thing happen for reserved ports?

Yes, of course.

Also, if all these programs are running on reserved ports, wouldn't they consume system resources even if they are blocked listening for a connection?

Yes.

Are these programs running at all times?

Either they are running or they aren't running. You're asking about both situations at the same time. If you mean 'executing', i.e. consuming CPU, the answer is no, they are blocked waiting for connections while there are no connections.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

[EDIT] The idea of a reserved port is that any custom software you write should take care to avoid binding to them, to avoid interfering with an established service. Further, non-root users can't bind any ports below 1024 anyway, many of which are registered with IANA (aka reserved).

There's no requirement that a particular process be bound to any port. A port is just a system resource. Typically a master inetd starts early in the system boot sequence, binds to some low-numbered ports, and handles the trivial services such as echo itself. These algorithms are so simple, and so infrequently used in practice, that very few resources are consumed. That's why you'll not find a separate "echo server" process. If you read the inetd.conf manual page:

http://www.freebsd.org/cgi/man.cgi?query=inetd.conf&sektion=5&manpath=FreeBSD%209.2-RELEASE

The inetd utility also provides several other 'trivial' services inter- nally by use of routines within itself. These services are 'echo', 'discard', 'chargen' (character generator), 'daytime' (human read- able time), and 'time' (machine readable time, in the form of the number of seconds since midnight, January 1, 1900).

user207421
  • 305,947
  • 44
  • 307
  • 483
BaseZen
  • 8,650
  • 3
  • 35
  • 47
  • The idea of a reserved port is that it is on a list at IANA so that only one service can use it. The idea of ports 1-1023 is that only the root user can bind to them. These aren't the same thing. There are many reserved ports above 1023. – user207421 Mar 06 '15 at 22:49
  • "List of Well-Known Ports Port numbers range from 0 to 65536, but only ports numbers 0 to 1024 are *reserved* for privileged services and designated as well-known ports. This list of well-known port numbers specifies the port used by the server process as its contact port." http://www.webopedia.com/quick_ref/portnumbers.asp – BaseZen Mar 06 '15 at 23:01
  • Exacfly. Reserved *for privileged users.* Arbitrary websites aren't normative references and can't 'specify' anything. Only the IANA can do that. If you take your link's advice and refer to RFC 1700 you will see that the real list as of that date extended well beyond 1023, and RFC 1700 itself was obsoleted many years ago. – user207421 Mar 06 '15 at 23:45
  • Don't use code formatting for text that isn't code. – user207421 May 27 '15 at 00:33
0

ports 1-65535 are available, and ports in range 1-1023 are the privileged ones and using for standard applications.

And there will be Ephemeral port range also exists in your system and it can be found as follows:

sysctl -A | grep ip_local_port_range 

Epeheral port range is available for all your client sockets.

When there is a server, client communication most of the time communication is happening using a socket. Socket is nothing but a pair of IP address and a port number. All the port referred usually with configuration will be a server port configuration and client port is dynamically choosing from the Epeheral port range. In case of epeheral ports, system may not release the port until this range is exhausted.

You can check port availability by using command:

netstat -a | grep <port number>
Steephen
  • 14,645
  • 7
  • 40
  • 47