Reserved TCP/IP ports

时光总嘲笑我的痴心妄想 提交于 2021-02-08 02:59:44

问题


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?


回答1:


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.




回答2:


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>



回答3:


[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).



来源:https://stackoverflow.com/questions/28906613/reserved-tcp-ip-ports

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!