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

Can you find out why connection refused happens if you are not the sender of request?

· 52CE 我爱测

I have read a few posts and articles about why a connection would be refused. This usually talks about it in general, like this one What causes the 'Connection Refused' message? . But my question is how or when can you be certain…

问题原文

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

I have read a few posts and articles about why a connection would be refused. This usually talks about it in general, like this one What causes the 'Connection Refused' message?.

But my question is how or when can you be certain that there is something wrong with the other side (lets say someone sending a request to you).

In this scenario if you call a request to a public ip and port that you set up and the connection goes through and everything goes right (from different devices, ips and networks) but then, if someone else sends it it gets refused. How do we know what the issue is ?

已采纳解答

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

When a client attempts to connect to a service/server there are roughly the following scenario's:

  1. The connection succeeds.
  2. The connection attempt fails, because the client receives no response. It receives neither positive nor negative response and the connection attempt eventually simply fails from a time out.
  3. The connection attempt fails, but the client receives an error message.

When you try to debug from the client

  • scenario #1 is easy ;)

  • scenario #3 usually shows as a "connection refused" error.
    When you run a packet capture on the client you'd be looking for :

    • either TCP reset/RST packet
    • or an ICMP packet such as "unreachable - admin prohibited".

    Both of which contain a source IP-address which either matches the IP-address of the server you're connecting to, or not.

    • When the error comes from the server either nothing is listening or there might be a host-based firewall active on the server.
    • When the IP-address is not from the server, it comes from the (first) device on the path between client and server that is blocking the connection attempt.
  • scenario #2 sometimes shows as a "connection time-out" and sometimes a bit incorrectly as "connection refused".
    This is usually the result from a firewall configuration that silently drops all connection attempts that are not allowed. From the client it is inconclusive where that happens. A packet capture shows nothing and you can't debug that from the client. You don't know where that happens, on the server or somewhere on the path between client and server.

When you try to debug from the server

  • scenario #1 is easy ;)

  • To debug both scenario #2 and #3 you can run a packet capture on the server:

    A packet capture on the server will see all incoming packets. Incoming packets are still received when no service is listening on the port. Regardless of the fact that an host based firewall may be active, a packet capture shows packets before they're processed and possibly rejected/silently-dropped by a host-based firewall.
    Linux reference here or Windows here

    1. When packets from the client are received:
      Debug further on the server (check: the configuration of the host-based firewall, if the service is enabled, healthy, has active ACL's etc. etc.)

    2. When packets from the client are NOT received:
      The connection attempt is blocked somewhere along the path between client and server. From the server you can't learn where.

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

资料来源与适用范围

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

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

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