如何为新服务选择默认的TCP / IP端口?

时间:2023-01-27 12:22:07

When developing an app that will listen on a TCP/IP port, how should one go about selecting a default port? Assume that this app will be installed on many computers, and that avoiding port conflicts is desired.

在开发将侦听TCP / IP端口的应用程序时,应如何选择默认端口?假设此应用程序将安装在许多计算机上,并且需要避免端口冲突。

12 个解决方案

#1


45  

Go here and pick a port with the description Unassigned

转到此处,选择一个描述为Unassigned的端口

#2


29  

First step: look at IANA listing :

第一步:查看IANA列表:

There you will see at the tail of the list

在那里你会看到列表的尾部

"The Dynamic and/or Private Ports are those from 49152 through 65535"

“动态和/或专用端口是49152到65535的端口”

so those would be your better bets, but once you pick one you could always google on it to see if there is a popular enough app that has already "claimed" it

所以那些将是你更好的赌注,但是一旦你选择了一个你可以随时google上看看是否有一个足够受欢迎的应用程序已经“声称”它

#3


6  

If by widely-used, you mean you want to protect against other people using it in the future, you can apply to have it marked as reserved for your app by IANA here

如果通过广泛使用,您的意思是希望保护其他人在将来使用它,您可以申请将IANA标记为为您的应用程序保留

#4


5  

The most comprehensive list of official IANA port numbers and non-official port numbers I know is nmap-services.

我所知道的最全面的官方IANA端口号和非官方端口号列表是nmap-services。

#5


2  

You probably want to avoid using any ports from this list (Wikipedia).

您可能希望避免使用此列表中的任何端口(Wikipedia)。

I would just pick one, and once the app is used by the masses, the port number will become recognized and included in such lists.

我只选择一个,一旦群众使用该应用程序,端口号将被识别并包含在此类列表中。

#6


2  

As others mention, check IANA.

正如其他人所说,请检查IANA。

Then check your local systems /etc/services to see if there are some custom ports already in use.

然后检查本地系统/ etc / services以查看是否有一些自定义端口已在使用中。

And please, don't hardcode it. Make sure it's configurable, someway, somehow -- if for no other reason that you want to be able to have multiple developers using their own localized builds at the same time.

请不要硬编码。确保它是可配置的,不管怎么说,如果没有其他原因你希望能够让多个开发人员同时使用他们自己的本地化版本。

#7


1  

Choosing an unassigned one from the IANA list is usually sufficient, but if you are talking about a commercially-released product, you really should apply to the IANA to get one assigned to you. Note that the process of doing this is simple but slow; the last time I applied for one, it took a year.

从IANA列表中选择未分配的通常就足够了,但如果您正在谈论商业发布的产品,那么您真的应该向IANA申请分配给您。请注意,这样做的过程很简单但很慢;我最后一次申请一个,花了一年时间。

#8


1  

If this is for an application that you expect to be used widely, then register a numberhere so no-one else uses it.

如果这是针对您希望广泛使用的应用程序,那么请注册一个数字,以便其他人不使用它。

Otherwise, just pick an unused one randomly.

否则,只需随机选择一个未使用的。

The problem with using one in the dynamic range is that it may not be available because it may be being used for a dynamic port number.

在动态范围中使用one的问题在于它可能不可用,因为它可能用于动态端口号。

#9


1  

Use iana list. Download the csv file from :

使用iana列表。从以下位置下载csv文件:

https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv

and use this shell script for searching for unregistred ports:

并使用此shell脚本搜索未注册的端口:

for port in {N..M}; do if ! grep -q $port service-names-port-numbers.csv; then echo $port;fi; done;

and put 2 numbers instead of N and M.

并放2个数字而不是N和M.

#10


0  

Well, you can reference some commonly used port numbers here and try not to use anyone else's.

那么,你可以在这里引用一些常用的端口号,尽量不要使用其他人的端口号。

If by "open to the public at large" you mean you're opening ports on your own systems, I'd have a chat with your system administrators about which ports they feel comfortable with doing that with.

如果通过“向公众开放”意味着您在自己的系统上打开端口,我会与您的系统管理员聊聊他们认为哪些端口可以使用。

#11


0  

Choose a number that is not very common

选择一个不常见的数字

#12


0  

Choose a default port that doesn't interfere with the most common daemons and servers. Also make sure that the port number isn't listed as an attack vector for some virus -- some companies have strict policies where they block such ports no matter what. Last but not least, make sure the port number is configurable.

选择一个不会干扰最常见的守护程序和服务器的默认端口。还要确保端口号未列为某些病毒的攻击媒介 - 有些公司有严格的策略,无论如何阻止此类端口。最后但并非最不重要的是,确保端口号是可配置的。

#1


45  

Go here and pick a port with the description Unassigned

转到此处,选择一个描述为Unassigned的端口

#2


29  

First step: look at IANA listing :

第一步:查看IANA列表:

There you will see at the tail of the list

在那里你会看到列表的尾部

"The Dynamic and/or Private Ports are those from 49152 through 65535"

“动态和/或专用端口是49152到65535的端口”

so those would be your better bets, but once you pick one you could always google on it to see if there is a popular enough app that has already "claimed" it

所以那些将是你更好的赌注,但是一旦你选择了一个你可以随时google上看看是否有一个足够受欢迎的应用程序已经“声称”它

#3


6  

If by widely-used, you mean you want to protect against other people using it in the future, you can apply to have it marked as reserved for your app by IANA here

如果通过广泛使用,您的意思是希望保护其他人在将来使用它,您可以申请将IANA标记为为您的应用程序保留

#4


5  

The most comprehensive list of official IANA port numbers and non-official port numbers I know is nmap-services.

我所知道的最全面的官方IANA端口号和非官方端口号列表是nmap-services。

#5


2  

You probably want to avoid using any ports from this list (Wikipedia).

您可能希望避免使用此列表中的任何端口(Wikipedia)。

I would just pick one, and once the app is used by the masses, the port number will become recognized and included in such lists.

我只选择一个,一旦群众使用该应用程序,端口号将被识别并包含在此类列表中。

#6


2  

As others mention, check IANA.

正如其他人所说,请检查IANA。

Then check your local systems /etc/services to see if there are some custom ports already in use.

然后检查本地系统/ etc / services以查看是否有一些自定义端口已在使用中。

And please, don't hardcode it. Make sure it's configurable, someway, somehow -- if for no other reason that you want to be able to have multiple developers using their own localized builds at the same time.

请不要硬编码。确保它是可配置的,不管怎么说,如果没有其他原因你希望能够让多个开发人员同时使用他们自己的本地化版本。

#7


1  

Choosing an unassigned one from the IANA list is usually sufficient, but if you are talking about a commercially-released product, you really should apply to the IANA to get one assigned to you. Note that the process of doing this is simple but slow; the last time I applied for one, it took a year.

从IANA列表中选择未分配的通常就足够了,但如果您正在谈论商业发布的产品,那么您真的应该向IANA申请分配给您。请注意,这样做的过程很简单但很慢;我最后一次申请一个,花了一年时间。

#8


1  

If this is for an application that you expect to be used widely, then register a numberhere so no-one else uses it.

如果这是针对您希望广泛使用的应用程序,那么请注册一个数字,以便其他人不使用它。

Otherwise, just pick an unused one randomly.

否则,只需随机选择一个未使用的。

The problem with using one in the dynamic range is that it may not be available because it may be being used for a dynamic port number.

在动态范围中使用one的问题在于它可能不可用,因为它可能用于动态端口号。

#9


1  

Use iana list. Download the csv file from :

使用iana列表。从以下位置下载csv文件:

https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv

and use this shell script for searching for unregistred ports:

并使用此shell脚本搜索未注册的端口:

for port in {N..M}; do if ! grep -q $port service-names-port-numbers.csv; then echo $port;fi; done;

and put 2 numbers instead of N and M.

并放2个数字而不是N和M.

#10


0  

Well, you can reference some commonly used port numbers here and try not to use anyone else's.

那么,你可以在这里引用一些常用的端口号,尽量不要使用其他人的端口号。

If by "open to the public at large" you mean you're opening ports on your own systems, I'd have a chat with your system administrators about which ports they feel comfortable with doing that with.

如果通过“向公众开放”意味着您在自己的系统上打开端口,我会与您的系统管理员聊聊他们认为哪些端口可以使用。

#11


0  

Choose a number that is not very common

选择一个不常见的数字

#12


0  

Choose a default port that doesn't interfere with the most common daemons and servers. Also make sure that the port number isn't listed as an attack vector for some virus -- some companies have strict policies where they block such ports no matter what. Last but not least, make sure the port number is configurable.

选择一个不会干扰最常见的守护程序和服务器的默认端口。还要确保端口号未列为某些病毒的攻击媒介 - 有些公司有严格的策略,无论如何阻止此类端口。最后但并非最不重要的是,确保端口号是可配置的。