大网数据广告活动
服务器运维问答

Can't connect to EC2 via TCP

· 52CE 我爱测

My Ubuntu 19.04 EC2 instance has security group with inbound and unbound rules set to all protocols, all ports and 0.0.0.0/0 IP range. I can connect to it with SSH on port 22 and with http on port 80, using Windows Test-NetConnec…

问题原文

原帖链接 · Elgirhath · CC BY-SA 4.0

My Ubuntu 19.04 EC2 instance has security group with inbound and unbound rules set to all protocols, all ports and 0.0.0.0/0 IP range.

I can connect to it with SSH on port 22 and with http on port 80, using Windows Test-NetConnection. I run an app on the VM which listens on port 5000, but I couldn't connect to it from my local computer.

Thanks to this answer I run a testable process that listens on port 5000 on my VM.

ubuntu@ip-172-31-35-82:~$ nc -4 -k -l -v localhost 5000
Listening on [localhost] (family 2, port 5000)

Calling curl localhost:5000 on another terminal produces an expected output

ubuntu@ip-172-31-35-82:~$ nc -4 -k -l -v localhost 5000
Listening on [localhost] (family 2, port 5000)
Connection from localhost 51424 received!
GET / HTTP/1.1
Host: localhost:5000
User-Agent: curl/7.58.0
Accept: */*

However doing calling Test-NetConnection or Invoke-WebRequest from my local computer to that machine and port 5000 fails immedietaly (no timeout). The listening process also doesn't print that it received any new connections.

(base) PS C:\Users\Konrad> Test-NetConnection **.**.***.** -port 5000 -v
WARNING: TCP connect to (**.**.***.** : 5000) failed
VERBOSE: **.**.***.**.in-addr.arpa
VERBOSE: **.**.***.**.in-addr.arpa
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = QueryIsolationType,'className'
 = MSFT_NetAddressFilter,'namespaceName' = root\standardcimv2'.
VERBOSE: Operation 'Invoke CimMethod' complete.


ComputerName           : **.**.***.**
RemoteAddress          : **.**.***.**
RemotePort             : 5000
InterfaceAlias         : Wi-Fi
SourceAddress          : **.**.***.**
PingSucceeded          : True
PingReplyDetails (RTT) : 42 ms
TcpTestSucceeded       : False

Real IPs have been replaced.

What am I missing?

已采纳解答

原帖链接 · Alex Moore · CC BY-SA 4.0

I believe the issue you are encountering with your testing is that on the netcat (nc) command you are setting to listen for connections you are specifying localhost, meaning it will only listen on that localhost interface and any connections coming in from outside it won't be listening on and so it will simply reset the connection, which is what you are seeing.

Instead you can remove the localhost entry on the nc command and it will bind to all interfaces and at that point it should work externally.

For example:

nc -4 -k -l -v 5000

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。