“Connection refused” vs “No route to host”

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

“[email protected]$telnet 172.101.19.57 1521
Trying 172.101.19.57...
telnet: connect to address 172.101.19.57: No route to host
如果端口未开,实际报错:
[email protected]$telnet 172.27.19.56 1521
Trying 172.27.19.56...
telnet: connect to address 172.27.19.56: Connection refused
是不是防火墙的问题???
从数据库服务器关闭防火墙:
[[email protected] ~]# service iptables stop
iptables: Flushing firewall rules: [  OK  ]
iptables: Setting chains to policy ACCEPT: nat mangle filter [  OK  ]
iptables: Unloading modules: [  OK  ]
再从远程机器执行:
[email protected]$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-12 08:47:14

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

nagios Connection refused by host

服务端(192.168.2.110)无法访问客户端的NRPE:  [[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 NRPE v2.12 [[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.2.120 Connection refused by host 客户端(192.168.2.120): [[email p

ssh: connect to host localhost port 22: Connection refused (2)

命令:ssh localhost 错误信息:ssh: connect to host localhost port 22: Connection refused 错误原因: 1.sshd 未安装 2.sshd 未启动 3.防火墙 解决方法: 1.确定安装sshd:  sudo apt-get install openssh-server 2.启动sshd: net start sshd 3.检查防火墙设置 检验方法: 输入命令:ssh localhost 若成功,则表示安装成功,且连接通过: 转

Ubuntu下 ssh : connect to host localhost port 22:Connection refused

Ubuntu下测试ssh时使用ssh localhost 命令,出现错误提示connect to host localhost port 22:Connection refused 造成这个错误的原因可能是ssh-server未安装或者未启动.ubuntu 11.10 默认安装openssh-client,但是木有安装server 运行 ps -e | grep ssh,查看是否有sshd进程 如果没有,说明server没启动,通过 /etc/init.d/ssh -start 启动server

ssh: connect to host github.com port 22: Connection refused

假设git例如,下面的问题时,远程推送: [[email protected] learngit]$ git push -u origin master ssh: connect to host github.com port 22: Connection refused fatal: Could not read from remote repository. Please make sure you have the correct access rights and the reposit

ubuntu安装配置ssh-connect to host localhost port 22: Connection refused

在安装ssh,经常出现 ssh: connect to host localhost port 22: Connection refused 从以下几点去检查: 1.是否安装ssh-server: 打开"终端窗口",输入"sudo ps -e |grep ssh"-->回车-->有sshd,说明ssh服务已经启动,如果没有启动,输入"sudo service ssh start"-->回车-->ssh服务就会启动.若无ss

Linux--ssh: connect to host localhost port 22: Connection refused

今日在进行SSH免密码登陆的时候,使用SSH进行测试,抛出下面异常 ssh: connect to host localhost port 22: Connection refused 在网上收了下,答复很多,基本都是 1.没启动SSH 2.没安装SSH 3.没关防火墙 4.-. ,千篇一律. 上面的解决方案我都看了,但是还是不好使. 调研了些关于SSH的资料,内容如下, SSH:是一种安全通道协议,主要用来实现字符界面的远程登录,远程复制等功能(使用TCP的22号端口).SSH协议对通信双方的

mac connect to host localhost port 22: Connection refused

在Mac OS X 10.10.5学习hadoop的过程中,输入命令ssh localhost得到 ssh: connect to host localhost port 22: Connection refused 解决方法是选择系统偏好设置->选择共享->点击远程登录 然后再输入命令ssh localhost发现已经解决问题 找到解决方案来自于 http://stackoverflow.com/questions/6313929/how-do-i-open-port-22-in-os-x-

Linux 出现telnet: 127.0.0.1: Connection refused错误解决办法

Linux 出现telnet: connect to address 127.0.0.1: Connection refused错误解决办法 没有xinetd服务: 1./etc/init.d目录中放置了系统中各个daemon服务的脚本,xinetd是其中之一. 2.xinetd是一种特殊的daemon服务(super daemon),它本身管理了一系列的daemon服务,这些服务只有在用户调用时才由xinetd启动,它们启动速度稍慢于独立的daemon服务,这些服务在/etc/xinetd.c

CentOS下配置Hadoop集群:java.net.NoRouteToHostException: No route to host问题的解决

我用的是hadoop 1.2.1 遇到的问题是: hadoop中datanode无法启动,报Caused by: java.net.NoRouteToHostException: No route to host 2013-06-11 02:22:13,637 INFO org.apache.hadoop.hdfs.server.datanode.DataNode: STARTUP_MSG: /***************************************************