“Connection refused” vs “No route to host”

曾经在http://blog.csdn.net/bisal/article/details/42496583这篇博文中提到一个端口连接的验证:

“ora10g@localhost.localdomain$telnet 172.101.19.57 1521
Trying 172.101.19.57...
telnet: connect to address 172.101.19.57: No route to host
如果端口未开,实际报错:
ora10g@localhost.localdomain$telnet 172.27.19.56 1521
Trying 172.27.19.56...
telnet: connect to address 172.27.19.56: Connection refused
是不是防火墙的问题???
从数据库服务器关闭防火墙:
[root@dcsopen2Node ~]# service iptables stop
iptables: Flushing firewall rules: [  OK  ]
iptables: Setting chains to policy ACCEPT: nat mangle filter [  OK  ]
iptables: Unloading modules: [  OK  ]
再从远程机器执行:
ora10g@localhost.localdomain$telnet 172.101.19.571521
Trying 172.101.19.57...
Connected to 172.101.19.57.
Escape character is '^]'.
说明端口已开,更重要的是,明确了,就是防火墙问题。”

通过实验再次说明下“Connection refused”和“No route to host”的区别和问题诊断思路。

首先,网上有篇帖子说明“Connection refused” vs “No route to host”(http://superuser.com/questions/720851/connection-refused-vs-no-route-to-host):

"Connection refused" means that the target machine actively rejected the connection. With port 80 as the context, one of the following things is likely the reason:
    Nothing is listening on 127.0.0.1:80 and 132.70.6.157:80
    Nothing is listening on *:80
    The firewall is blocking the connection with REJECT
So check your Apache and iptables config.
"No route to host" refers to a network problem. It is not a reply from the target machine.
说的是“Connection refused”是目标主机明确拒绝了这次连接,有可能是该端口没有启动监听,或者因为防火墙。“No route to host”则可能是一个网络问题,不是目标主机的回复。

一个实验模拟:

客户端机器ip:172.1.1.1

目标机ip:172.1.2.1

1. 从客户端telnet目标机的一个已启动端口1521,但防火墙中未添加例外。

从172.1.1.1 telnet 172.1.2.1 1521,提示no route to host。

Trying 172.1.2.1...

telnet: connect to address 172.1.2.1: No route to host

在防火墙配置中iptables添加1521端口,telnet正常。

2. 从客户端telnet目标机的一个未启动监听的端口

172.1.2.1的10001端口没有启用,netstat -an | grep 10001不存在。

从172.1.1.1 telnet 172.1.2.1 10001,提示connection refused。

Trying 172.1.2.1...

telnet: connect to address 172.1.2.1: Connection refused

结论:说明No route to host是防火墙的返回,先经过防火墙,不管端口有没有。然后如果通过了防火墙,但监听未启动,则提示Connection refused的错误。

时间: 2024-10-14 11:23:56

“Connection refused” vs “No route to host”的相关文章

RMI异常,java.rmi.ConnectException: Connection refused to host

问题描述 String name = "Compute"; HelloWorldCompute engine = new HelloWorldEngine(); HelloWorldCompute stub = (HelloWorldCompute) UnicastRemoteObject.exportObject(engine, 8888); Registry registry = LocateRegistry.getRegistry(); registry.rebind(name,

hadoop中datanode无法启动,报Caused by: java.net.NoRouteToHostException: No route to host

今天把hadoop环境给搭起来了,在master上面启动hadoop后,jps查看进程,SecondaryNameNode NameNode Jps DataNode JobTracker TaskTracker都没问题.但是去http://master:50070/dfshealth.jsp查 看,live nodes为0.所以我到slave1和slave2上面去执行jps查看进程,结果都没有datanode进程,也就是说datanode没有启动成 功,所以我就到logs里面去执行less h

java网络编程错误java.net.ConnectException: Connection refused: connect求教

问题描述 java网络编程错误java.net.ConnectException: Connection refused: connect求教 刚开始学习java网络编程,在书上看到一段代码,就动手试一下,结果出现下面错误: java.net.ConnectException: Connection refused: connect 源代码如下: import java.io.*; import java.net.*; class lx01 { public static void main(S

nginx-ngnix+fastcgi+python服务器每隔20几分钟就报connection refused

问题描述 ngnix+fastcgi+python服务器每隔20几分钟就报connection refused 正在搭建一个fake server,要求每秒钟支持7000个并发.server采用nginx/fastcgi/flup搭建,用spawn-fastcgi来管理fastcgi进程,后台的应用程序很简单,就是返回固定的一串字符串,用python写的.用jmeter打流量测试,发现开始20几分钟server运行很好,后面就会有断断续续的error产生,刚开始以为是应用程序反映不过来,后来就将

JDBC连接SQL Server出现的connection refused问题的解决办法

使用JDBC在默认端口1433上连接SQL Server获得connection refused异常,大致异常信息为:The TCP/IP connection to the host  has failed. java.net.ConnectException: Connection refused. 1.使用telnet 127.0.0.1 1433测试,得到如下信息:正在连接到127.0.0.1...不能打开到主机的连接, 在端口 1433: 连接失败表示1433端口没有打开 2.检查SQ

Call to master/192.168.137.101:9001 failed on connection exception: java.net.ConnectException: Connection refused

java.net.ConnectException: Call to master/192.168.137.101:9001 failed on connection exception: java.net.ConnectException: Connection refused  at org.apache.hadoop.ipc.Client.wrapException(Client.java:1099)  at org.apache.hadoop.ipc.Client.call(Client

Socket的Connection refused异常解决办法

今天练习Socket编程,在new Socket时无意间遇到下述异常,倒腾了好一通,原来是没有开启对应的 服务器,记下来,以备参考,顺便为广大网友提个醒,别走了弯路-- Log代码 java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown S

ssh 修改端口后 connection refused

问题描述 ssh 修改端口后 connection refused 我在本机下新增了ssh的端口2306,保留了22,重启服务后,用另一台机器ssh过来,22的可以登录,2306的报 connection refused的错误,我两边的防火墙都用了iptables -F关闭了的,问下各位可能是什么原因导致的啊 解决方案 http://www.2cto.com/os/201107/97209.html

mina-Android TCP通讯使用Mina时Connection refused

问题描述 Android TCP通讯使用Mina时Connection refused 01-16 15:02:13.796: W/System.err(14805): org.apache.mina.core.RuntimeIoException: Failed to get the session. 01-16 15:02:13.800: W/System.err(14805): at org.apache.mina.core.future.DefaultConnectFuture.getS