I've written a WCF Service hosted by a Windows Service and it needs to listen on a known TCP/IP port. From what range can I safely allocate a port for use within my organization? That port will be embedded in the config files for the service and the clients that are consuming the service.
我编写了一个由Windows服务托管的WCF服务,它需要侦听已知的TCP / IP端口。我可以在什么范围内安全地分配端口以在我的组织内使用?该端口将嵌入到服务的配置文件和使用该服务的客户端中。
6 个解决方案
#1
23
Pick a port number from 49152 through 65535.
从49152到65535选择一个端口号。
IANA publishes a list of currently assigned ports.
IANA发布当前分配的端口列表。
http://www.iana.org/assignments/port-numbers
The Dynamic and/or Private Ports are those from 49152 through 65535. This is the range from where you SHOULD pick a port for your in-house applications. Of course any port belonging to one of the unassigned ranges on the published list can be used. But be aware that by picking a port number from those unassigned ranges there is no guarantee whatsoever that the port you choose will not be a reserved port in the future.
动态和/或专用端口是49152到65535的端口。这是您应该为内部应用程序选择端口的范围。当然,可以使用属于已发布列表上的未分配范围之一的任何端口。但请注意,通过从未分配范围中选择端口号,无法保证您选择的端口将来不会成为保留端口。
UNASSIGNED PORT NUMBERS SHOULD NOT BE USED. THE IANA WILL ASSIGN THE NUMBER FOR THE PORT AFTER YOUR APPLICATION HAS BEEN APPROVED.
不应使用未经授权的港口号码。在您的申请获得批准后,IANA将为该港口分配号码。
And make sure that the port number you pick is configurable as you stated:
并确保您选择的端口号可以按照您的说明进行配置:
That port will be embedded in the config files for the service and the clients that are consuming the service.
该端口将嵌入到服务的配置文件和使用该服务的客户端中。
This will avoid headaches in case some other 3rd party you-cannot-touch software is using your port number. If that happens you just go ahead and change it on the configuration file and it just works.
如果其他第三方您无法触摸软件正在使用您的端口号,这将避免令人头疼。如果发生这种情况,您只需继续在配置文件中进行更改即可。
#2
34
Ports 0-1023 are the Well Known Ports and are assigned by IANA. These should only be used for the assigned protocols on public networks.
端口0-1023是众所周知的端口,由IANA分配。这些仅应用于公共网络上的指定协议。
Ports 1024-65535 used to be called Registered Port Numbers (see rfc1700) but are now split into two areas (see rfc6335).
端口1024-65535以前称为注册端口号(参见rfc1700),但现在分为两个区域(参见rfc6335)。
Ports 1024-49151 are the User Ports and are the ones to use for your own protocols.
端口1024-49151是用户端口,是用于您自己的协议的端口。
Ports 49152-65535 are the Dynamic ports and should not be prescribed to a protocol.
端口49152-65535是动态端口,不应规定协议。
The User Ports can be used for any protocol, but there are a finite number, so your use will * with someone elses use on some network somewhere. IANA keep a record of registered port numbers (0-49151). If your protocol will be used on public networks then you need to look into registering it with IANA. If you are only using it within your own network then pick a port within this area (1024-49151) and check that port against the IANA register to make sure it isn't used by a protocol that could be used on your network. For private use it is probably better to pick a number that is assigned to a protocol you know won't be used than to choose one that is unassigned and so may be assigned in the future.
用户端口可用于任何协议,但有一个有限的数字,因此您的使用将与某些网络上的某些人使用冲突。 IANA保留了注册端口号(0-49151)的记录。如果您的协议将在公共网络上使用,那么您需要考虑向IANA注册它。如果您只在自己的网络中使用它,请在此区域内选择一个端口(1024-49151),并根据IANA注册检查该端口,以确保它不会被可在您的网络上使用的协议使用。对于私人使用,最好选择一个分配给您知道不会被使用的协议的号码,而不是选择一个未分配的协议,因此可能在将来分配。
Don't use a port number within the Dynamic range. These ports are assigned by the operating system, dynamically and somewhat randomly. If you open a client connection (using bind() with port=0) you will be assigned an unused port from the dynamic range. There is no way to guarantee that a port in this range will always be free for your protocol.
请勿在动态范围内使用端口号。这些端口由操作系统分配,动态且有些随机。如果打开客户端连接(使用带端口= 0的bind()),将为动态范围分配一个未使用的端口。无法保证此范围内的端口始终可用于您的协议。
#3
5
Short answer: Avoid anything up to and including 1023, or over 49152, and test the chosen port against services on your network.
简短回答:避免包括1023或超过49152在内的任何内容,并针对您网络上的服务测试所选端口。
If you've taken the reasonable precautions that it appears you have (putting the port number in a config file), it shouldn't be an enormous disruption if you later discover a conflict.
如果您采取了合理的预防措施(将端口号放在配置文件中),如果您以后发现冲突,则不应该造成巨大的破坏。
But (so that I can add something to the other suggestions that have popped up while I've been typing) make sure that you make it easy to change! If it's in config files, make it obvious. Document it, and point it out in troubleshooting. It's the sort of thing that could go wrong, so make it easy to debug if it needs changing.
但是(这样我可以在我输入时弹出的其他建议中添加一些内容)确保您可以轻松更改!如果它在配置文件中,那就明白吧。记录它,并在故障排除中指出它。这是可能出错的事情,因此如果需要更改,可以轻松调试。
#4
4
In addition to the other suggestions about picking a common application port, I'd suggest that you make the port configurable within your application. Hard-coded port numbers are a bad idea, particularly if you later find a port conflict with another application and need to change yours.
除了有关选择通用应用程序端口的其他建议之外,我建议您在应用程序中配置端口。硬编码端口号是一个坏主意,特别是如果您稍后发现与另一个应用程序的端口冲突并需要更改您的端口号。
#5
0
Here is a good list of common application ports. Make your own choice in an empty slot. Maybe you should also scan your network for any in-house special application.
这是一个很好的常见应用程序端口列表。在空槽中自行选择。也许您还应该扫描您的网络以获取任何内部特殊应用程序。
Typically high numbers port are available and I would suggest them but they could be blocked by firewalls.
通常高数字端口可用,我建议他们,但他们可能被防火墙阻止。
#6
0
As a note remember to check those port by netstat /a /n to see if its using by other application or not. I find out vista used the 49152 .... for some application level reason. Basically, because most of the system level listener does not implement port sharing its much safe to use the those ports which are not used at all.
记住要记住通过netstat / a / n检查这些端口,看看它是否被其他应用程序使用。我发现vista使用49152 ....出于某些应用程序级别的原因。基本上,因为大多数系统级别的侦听器没有实现端口共享,所以使用那些根本不使用的端口是非常安全的。
have nice programming day AMir
有一个很好的编程日AMir
#1
23
Pick a port number from 49152 through 65535.
从49152到65535选择一个端口号。
IANA publishes a list of currently assigned ports.
IANA发布当前分配的端口列表。
http://www.iana.org/assignments/port-numbers
The Dynamic and/or Private Ports are those from 49152 through 65535. This is the range from where you SHOULD pick a port for your in-house applications. Of course any port belonging to one of the unassigned ranges on the published list can be used. But be aware that by picking a port number from those unassigned ranges there is no guarantee whatsoever that the port you choose will not be a reserved port in the future.
动态和/或专用端口是49152到65535的端口。这是您应该为内部应用程序选择端口的范围。当然,可以使用属于已发布列表上的未分配范围之一的任何端口。但请注意,通过从未分配范围中选择端口号,无法保证您选择的端口将来不会成为保留端口。
UNASSIGNED PORT NUMBERS SHOULD NOT BE USED. THE IANA WILL ASSIGN THE NUMBER FOR THE PORT AFTER YOUR APPLICATION HAS BEEN APPROVED.
不应使用未经授权的港口号码。在您的申请获得批准后,IANA将为该港口分配号码。
And make sure that the port number you pick is configurable as you stated:
并确保您选择的端口号可以按照您的说明进行配置:
That port will be embedded in the config files for the service and the clients that are consuming the service.
该端口将嵌入到服务的配置文件和使用该服务的客户端中。
This will avoid headaches in case some other 3rd party you-cannot-touch software is using your port number. If that happens you just go ahead and change it on the configuration file and it just works.
如果其他第三方您无法触摸软件正在使用您的端口号,这将避免令人头疼。如果发生这种情况,您只需继续在配置文件中进行更改即可。
#2
34
Ports 0-1023 are the Well Known Ports and are assigned by IANA. These should only be used for the assigned protocols on public networks.
端口0-1023是众所周知的端口,由IANA分配。这些仅应用于公共网络上的指定协议。
Ports 1024-65535 used to be called Registered Port Numbers (see rfc1700) but are now split into two areas (see rfc6335).
端口1024-65535以前称为注册端口号(参见rfc1700),但现在分为两个区域(参见rfc6335)。
Ports 1024-49151 are the User Ports and are the ones to use for your own protocols.
端口1024-49151是用户端口,是用于您自己的协议的端口。
Ports 49152-65535 are the Dynamic ports and should not be prescribed to a protocol.
端口49152-65535是动态端口,不应规定协议。
The User Ports can be used for any protocol, but there are a finite number, so your use will * with someone elses use on some network somewhere. IANA keep a record of registered port numbers (0-49151). If your protocol will be used on public networks then you need to look into registering it with IANA. If you are only using it within your own network then pick a port within this area (1024-49151) and check that port against the IANA register to make sure it isn't used by a protocol that could be used on your network. For private use it is probably better to pick a number that is assigned to a protocol you know won't be used than to choose one that is unassigned and so may be assigned in the future.
用户端口可用于任何协议,但有一个有限的数字,因此您的使用将与某些网络上的某些人使用冲突。 IANA保留了注册端口号(0-49151)的记录。如果您的协议将在公共网络上使用,那么您需要考虑向IANA注册它。如果您只在自己的网络中使用它,请在此区域内选择一个端口(1024-49151),并根据IANA注册检查该端口,以确保它不会被可在您的网络上使用的协议使用。对于私人使用,最好选择一个分配给您知道不会被使用的协议的号码,而不是选择一个未分配的协议,因此可能在将来分配。
Don't use a port number within the Dynamic range. These ports are assigned by the operating system, dynamically and somewhat randomly. If you open a client connection (using bind() with port=0) you will be assigned an unused port from the dynamic range. There is no way to guarantee that a port in this range will always be free for your protocol.
请勿在动态范围内使用端口号。这些端口由操作系统分配,动态且有些随机。如果打开客户端连接(使用带端口= 0的bind()),将为动态范围分配一个未使用的端口。无法保证此范围内的端口始终可用于您的协议。
#3
5
Short answer: Avoid anything up to and including 1023, or over 49152, and test the chosen port against services on your network.
简短回答:避免包括1023或超过49152在内的任何内容,并针对您网络上的服务测试所选端口。
If you've taken the reasonable precautions that it appears you have (putting the port number in a config file), it shouldn't be an enormous disruption if you later discover a conflict.
如果您采取了合理的预防措施(将端口号放在配置文件中),如果您以后发现冲突,则不应该造成巨大的破坏。
But (so that I can add something to the other suggestions that have popped up while I've been typing) make sure that you make it easy to change! If it's in config files, make it obvious. Document it, and point it out in troubleshooting. It's the sort of thing that could go wrong, so make it easy to debug if it needs changing.
但是(这样我可以在我输入时弹出的其他建议中添加一些内容)确保您可以轻松更改!如果它在配置文件中,那就明白吧。记录它,并在故障排除中指出它。这是可能出错的事情,因此如果需要更改,可以轻松调试。
#4
4
In addition to the other suggestions about picking a common application port, I'd suggest that you make the port configurable within your application. Hard-coded port numbers are a bad idea, particularly if you later find a port conflict with another application and need to change yours.
除了有关选择通用应用程序端口的其他建议之外,我建议您在应用程序中配置端口。硬编码端口号是一个坏主意,特别是如果您稍后发现与另一个应用程序的端口冲突并需要更改您的端口号。
#5
0
Here is a good list of common application ports. Make your own choice in an empty slot. Maybe you should also scan your network for any in-house special application.
这是一个很好的常见应用程序端口列表。在空槽中自行选择。也许您还应该扫描您的网络以获取任何内部特殊应用程序。
Typically high numbers port are available and I would suggest them but they could be blocked by firewalls.
通常高数字端口可用,我建议他们,但他们可能被防火墙阻止。
#6
0
As a note remember to check those port by netstat /a /n to see if its using by other application or not. I find out vista used the 49152 .... for some application level reason. Basically, because most of the system level listener does not implement port sharing its much safe to use the those ports which are not used at all.
记住要记住通过netstat / a / n检查这些端口,看看它是否被其他应用程序使用。我发现vista使用49152 ....出于某些应用程序级别的原因。基本上,因为大多数系统级别的侦听器没有实现端口共享,所以使用那些根本不使用的端口是非常安全的。
have nice programming day AMir
有一个很好的编程日AMir