端口与IP地址的关系

发布于 2024-09-03 03:50:37 字数 125 浏览 2 评论 0 原文

我的问题是,如果机器A有两个IP地址X,Y。

它可以打开 80 端口两次吗,例如 X:80Y:80 吗?

比如说,端口是机器唯一的还是IP唯一的?

My question is, if machine A have two IP address X,Y.

Can it open port 80 twice,like X:80 and Y:80 ?

Say,is port unique by machine or by IP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海风掠过北极光 2024-09-10 03:50:37

IP 地址指定网络接口(想象一下计算机上的以太网端口或 WiFi 连接)。端口号指定将到达给定网络接口的消息路由到的进程。因此,您可以对不同的 IP 地址使用相同的端口号,因为它们指定在给定接口上侦听的端口。但请注意,如果在调用 绑定函数。

An IP address specifies a network interface (think an ethernet port on your computer or your WiFi connection). A port number specifies the process to which to route messages arriving on a given network interface. Hence you can use the same port number with different IP addresses, as they specify the port on which to listen on that given interface. Note, though, that you can even reuse a port number with the same IP address if you use the SO_REUSEADDR option when invoking the bind function.

歌枕肩 2024-09-10 03:50:37

它的 IP 是独一无二的。当您绑定时(这是重要部分),您绑定到IP和端口号,而不是机器和端口号。要绑定到所有地址,您可以使用类似 INADDR_ANY 的内容。

如果您只想绑定到几个地址,则必须“手动”进行。当操作系统收到数据包时,它首先检查他是否是目的地。然后,它将其转发到已请求(通过绑定、通过连接等)的程序,该程序是具有该特定 IP 和端口号的数据包的目的地。

It's unique by IP. When you bind, (that's the important part), you bind to an IP and a port number, not a machine and a port number. To bind to all addreses you can use something like INADDR_ANY.

If you want to bind only to a few addresses, you have to do so "by hand". When the OS receives a packet it first checks he is the destination. Then it forwards it to the program that has requested (through bind, through connect etc) that he be the destination of packets with that specific IP and port number.

情未る 2024-09-10 03:50:37

端口和IP具有1对1的映射。

所以,是的,您可以在同一台计算机上的两个不同 IP 上打开端口 80。

port and IP's have 1 to 1 mapping.

So, yes you could have port 80 open on two different IP's on the same machine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文