简体   繁体   English

主机上的nc-> VM工作(端口9050),但是VM(用Python编写的运行服务器)从主机-> VM的同一端口上重置连接[TCP RST](9050)

[英]nc from host -> VM works (port 9050), but VM (running server written in Python) resets connection [TCP RST] from host -> VM on same port (9050)

Background Info 背景资料

I'm developing a network-enabled embedded device that is intended to communicate with a server. 我正在开发旨在与服务器通信的支持网络的嵌入式设备。 Because this server will be running linux (but I require Windows tools for development), I'm running a VM with Ubuntu Server 14.04 for dev purposes. 因为该服务器将运行linux(但是我需要Windows工具进行开发),所以出于开发目的,我正在运行带有Ubuntu Server 14.04的VM。

The embedded aspect isn't important for this question, as I'm stripping back to the simplest test setup (just have host connect to server on VM to see a TCP connection get established) for troubleshooting. 对于该问题,嵌入式方面并不重要,因为我将返回最简单的测试设置(只需将主机连接到VM上的服务器以查看建立的TCP连接)即可进行故障排除。

Network Setup 网络设置

  • D-Link DIR-615 running DD-WRT [v24-sp2 (03/25/13) std (SVN revision 21061)], static IPs assigned to host and VM by MAC filter, DNS feature enabled 运行DD-WRT [v24-sp2(03/25/13)std(SVN版本21061)]的D-Link DIR-615,通过MAC过滤器分配给主机和VM的静态IP,启用了DNS功能

  • Development Machine (192.168.5.117, dev.test.lan) 开发机(192.168.5.117,dev.test.lan)

  • Ubuntu VM (192.168.5.118, vm.test.lan) - using a bridged connection (NAT doesn't work as the client will initiate connection to VM) Ubuntu VM(192.168.5.118,vm.test.lan)-使用桥接连接(NAT不起作用,因为客户端将启动与VM的连接)

  • Router isn't connected to any sort of WAN, only wired connections, Wi-fi is disabled 路由器未连接到任何种类的WAN,仅有线连接,Wi-fi被禁用

Sanity Checks Performed 进行完整性检查

  • ping host from VM succeeds (using IP or dns name) 从VM ping主机成功(使用IP或dns名称)

  • ping VM from host succeeds (using IP or dns name) 从主机ping VM成功(使用IP或dns名称)

  • nc between host <-> VM (can listen/connect from either side) [listening on port 9050] 主机<-> VM之间的nc(可以从任一侧侦听/连接)[在端口9050上侦听]

  • within VM, can connect via nc to server application running on VM, a connection is successfully established [to port 9050] 在VM中,可以通过nc连接到在VM上运行的服务器应用程序,成功建立了连接[到端口9050]

  • Windows firewall opened for incoming/outgoing TCP connections on port 9050 Windows防火墙为端口9050上的传入/传出TCP连接打开

Problem Analysis 问题分析

Using wireshark, I'm able to see TCP connections working succesfully when performing the nc sanity test (host <-> VM). 使用Wireshark,在执行nc正常性测试(主机<-> VM)时,我可以看到TCP连接成功运行。

When I run the server (written in python, using asyncio) on the VM, and try to connect via nc from the host, the server doesn't see any connection come in (but we know that connecting from nc to the server works, as that was tested inside the VM successfully). 当我在VM上运行服务器(使用python,使用asyncio编写),并尝试从主机通过nc连接时,服务器看不到任何连接(但是我们知道从nc连接到服务器可以正常工作,因为在VM内成功测试了该代码)。

From wireshark I see the host sending a SYN to the VM, after which the VM responds with [RST, ACK]. 从Wireshark中,我看到主机向VM发送SYN,然后VM响应[RST,ACK]。 The host retries transmission twice before giving up. 主机在放弃之前重试传输两次。

Questions 问题

  • Is a bridged connection the appropriate setting to use for the VM? 桥接连接是否适合用于VM?

  • What is the best way to find out where the RST is coming from? 找出RST来自何处的最佳方法是什么? (is it the router, the VMs TCP/IP stack, or is some part of Python causing it?) (是路由器,VM的TCP / IP堆栈,还是Python的某些部分导致了它?)


Update: Tried nc 192.168.5.118 9050 within the VM and observed the same refused connection behaviour as if I had tried from host. 更新:在VM中尝试了nc 192.168.5.118 9050 ,并观察到与我从主机尝试过的连接行为相同的拒绝连接行为。 Based on what Adam has said, it looks like we're getting closer. 根据亚当所说的话,我们似乎越来越近了。 Will try Adam's suggestion as well and post an update. 还将尝试亚当的建议并发布更新。

The RST packet is being sent by the OS to indicate that the port is closed—no process is bound to it and listening. 操作系统正在发送RST数据包,以指示该端口已关闭-没有进程绑定到该端口并正在侦听。 As a result, the client trying to connect will very quickly fail with ECONNREFUSED (connection refused). 结果,尝试连接的客户端将很快失败,并显示ECONNREFUSED (连接被拒绝)。 This is perfectly normal behavior. 这是完全正常的行为。

How exactly are you binding to the port in your Python server process? 在Python服务器进程中,您如何精确地绑定到端口? Are you binding to the correct network interface? 您是否绑定到正确的网络接口? If you accidentally bound to only the loopback device ( localhost or 127.0.0.1 ), then you'll see exactly what you're describing: local connections from the machine to itself will succeed just fine, but connections from external hosts will fail. 如果您不小心绑定了仅环回设备( localhost127.0.0.1 ),那么您将确切地看到您所描述的内容:从计算机到自身的本地连接将成功,但是从外部主机的连接将失败。

In Python, you typically use either '' or '0.0.0.0' as the address portion to indicate that you want to bind to all network interfaces; 在Python中,通常使用'''0.0.0.0'作为地址部分,以指示您要绑定到所有网络接口; this is equivalent to the C constant INADDR_ANY : 这等效于C常量INADDR_ANY

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', port))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM