C UDP服务器访问问题
假设您有一个在 Linux 上的端口 9030 上运行的 UDP 服务器,并且您无法以某种方式访问该 UDP 服务器。没有防火墙或类似设置阻止访问该 UDP 端口。另请注意,数据包到达操作系统的网络堆栈,当操作系统收到数据包时,它立即发送“目标端口不可达”的 ICMP 数据包。令您惊讶的是,netstat 输出显示 UDP 服务器正在您指定的确切端口上运行,如下所示:
udp 0 0 212.253.35.111:9030 0.0.0.0:* 722/udpServerApp
另请注意,UDP 服务器侦听公共 IP,而不是本地主机等。这意味着数据包到达该公共 IP 地址。
那么可能会出现什么问题呢?你最好的猜测是什么?我真的很困惑。
Suppose you have an UDP server running on port 9030 on Linux and you can't access somehow to that UDP Server. There is no firewall or similar set up preventing access to that UDP port. And also please know that packet reaches to network stack of O.S. and when O.S. receives packet it immediately sends ICMP packet of Destination Port Unreachable. And to your surprise, netstat output shows that UDP server is running on the exact port you assigned as below:
udp 0 0 212.253.35.111:9030 0.0.0.0:* 722/udpServerApp
Also note that UDP Server listens on Public IP, not localhost or etc. Meaning packet reaches to that public IP Address.
So what might going wrong? What would you your best guesses? I am really confused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能没有监听正确的地址 - 例如监听
127.0.0.1
(localhost) 而不是“任何”地址。 netstat 的确切输出会告诉您这一点(但您没有发布它并要求猜测,所以就在这里)。You're probably not listening on the right address - e.g. listening on
127.0.0.1
(localhost) in stead of "any" address. The exact output of netstat will tell you that (but you didn't post it and asked for a guess, so here it is).您的套接字正在侦听本地 IP 地址 212.253.35.111 的端口 9030。
通过 tcpdump 或wireshark 验证您是否确实将 UDP 数据包发送到 IP 212.253.35.111 的端口 9030。
您要么尝试连接到错误的端口,错误的IP地址,或者有一个你还没有发现的防火墙(例如一些本地iptables规则),或者有一个路由错误,并且你不知何故在某个地方有两台机器具有相同的IP地址(通过一些负载平衡很有可能) /热备用设置,例如,如果您使用 VRRP)
Your socket is listening on the local IP address 212.253.35.111 , on port 9030.
Verify, via tcpdump or wireshark that you really are sending the UDP packets to the IP 212.253.35.111 , port 9030.
You're either trying to connect to the wrong port, the wrong IP address, or there's a firewall (e.g. some local iptables rules) you've yet to discover, or there's a routing error and you somehow have 2 machines somewhere with the same IP address (quite possible with some load balancing/hot standby setup, e.g. if you're using VRRP)
UDP服务器绑定在什么IP地址上?
如果它仅绑定在
127.0.0.1
上,则无法从外部网络接口访问它。要监听每个接口,应将其绑定到 INADDR_ANY 。
What IP address is the UDP server bound on?
If it's only bound on
127.0.0.1
then it won't be accessible from external network interfaces.To listen on every interface it should be bound to
INADDR_ANY
.