ssh遇到port 22:No route to host问题的解决方法

一 iptables 问题

1.没有安装,可以先安装 
yum install iptables

2.防火墙的开启与关闭 
即时生效,重启失效 
service iptables start(开启) 
service iptables stop(关闭) 
service iptables restart(重启) 
永久生效 
chkconfig iptables on(开启) 
chkconfig iptables off(关闭)

查看防火墙运行状态 
service iptables status

3.清除防火墙规则 
iptables -F 
iptables -X 
iptables -Z

4.开放端口22 
iptables -A INPUT -p tcp –dport 22 -j ACCEPT 
iptables -A OUTPUT -p tcp –sport 22 -j ACCEPT

5保存设置 
/etc/rc.d/init.d/iptables save

service iptables restart(重启一下)

iptables操作最后都记得要执行一下此步骤(如3, 4)

6 查看防火墙规则 
iptables -nL

7 直接向防火墙?件中添加规则 
vi /etc/iptables.test.rules

iptables-restore < /etc/iptables.test.rules(改完后先加载规则) 
iptables-save > /etc/iptables.rules(保存规则)

二SSH问题

1 ssh运行状态 
service sshd status

如果出现 
Loaded: error (Reason: No such file or directory) 
说明ssh没有安装 
检查是否装了ssh包 
rpm -qa|grep ssh 
没?的话 
yum install openssh-server 
或者 
yum install sshd 
(卸载ssh服务)yum remove sshd

如果出现 
openssh-daemon is stopped 
说明安装了ssh但是没有开启 
即时生效,重启失效 
service sshd start 
service sshd stop 
永久生效 
chkconfig sshd on 
chkconfig sshd off

2修改ssh默认端口22(本例改为3547) 
vi /etc/sysconfig/iptables 
加入 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3547 -j ACCEPT 
重启防火墙 
/etc/init.d/iptables restart 
(可选) 
可根据你的ssh状况屏蔽22端口 
vi /etc/sysconfig/iptables 
在 
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT 
前面加上#注释掉此语句 
记得重启防?墙

安装semanage 
yum -y install policycoreutils-Python 
开放指定端口 
semanage port -a -t ssh_port_t -p tcp 3547 
重启ssh服务 
/etc/init.d/sshd restart 
查看端口情况 
semanage port -l|grep ssh 
应该能看到 
ssh_port_t tcp 3547, 22

3查看端口状态 
netstat -antulp|grep ssh

原文地址:https://www.cnblogs.com/saryli/p/11831736.html

时间: 2024-08-28 20:19:11

ssh遇到port 22:No route to host问题的解决方法的相关文章

&lt;Linux&gt; Ubuntu error: ssh: connect to host master port 22: No route to host lost connection

iptables当找到匹配的规则时,就会执行相应的动作,而不会向下继续匹配.因为ssh端口开放的规则在all规则之后,所以永远都不会匹配到,也就是ssh永远被禁止. root下执行:iptables -I INPUT -p tcp --dport 22 -j ACCEPT 即可.

使用wifi ssh: connect to host hadoop000 port 22: No route to host

使用的wifi,在wifi下IP会自动分配. 先尝试能否ping通,如果都无法ping通那先把IP配置那些先搞定ping通之后遇到此问题再来尝试解决. 查看  /etc/hosts 中配置的 IP  hostname 是否改变. 通过  ip a  查看相应的ip  与 /etc/hosts下的ip地址是否相同.保持hosts文件与ip a 中的无线IP 保持一致. 原文地址:https://www.cnblogs.com/Liuyt-61/p/10359472.html

CentOS yum 命令出现 [Errno 14] curl#6 - &amp;quot;Couldn&amp;#39;t resolve host ...&amp;quot; 的解决方法

安装svn的时候,发现报错说一个地址无法訪问. # yum list | grep subversion http://opensource.wandisco.com/centos/7/svn-1.8/RPMS/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Couldn't resolve host 'opensource.wandisco.com'" 正在尝试其他镜像. One of the configured repositor

Windows10 下 github ssh 访问出现 Permission denied(publickey)错误的解决方法

Windows10 下 github ssh 访问出现 Permission denied(publickey)错误的解决方法. 错误信息: git clone [email protected]:ediwang/envsetup.git Cloning into 'envsetup'... [email protected]: Permission denied (publickey). fatal: Could not read from remote repository. Please

[故障解决]Ssh连接port 22: Connection refused

金山云有一个服务器需要连接到数据库但是总是失败,检查之后发现它的VPC配错了,更改VPC之后,这台服务器也会更换一个新的内网IP地址,但是问题来了,更换了内网IP之后,从跳板机连接,提示port 22: Connection refused. #ssh -v 新的ip地址,发现根本没有到Connection established.直接就提示port 22: Connection refused.这基本可以断定不是跳板机的问题了,那么就需要在远程机器里看配置. 但是远程机器是无法连接的啊,怎么办

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: /***************************************************

SSH无法登陆服务器,但是可以ping通,解决方法

在打通虚拟机之间的ssh无密码登录时出现的问题,每次尝试登陆都会提示错误:Permission denied .历时一天多,我终于把问题搞定,期间百度了很多人的方法,也受到启发,其实是很简单的一个原理,今天就跟大家一起分享下吧,也算是做个记录. 开始走了很多误区,重复设置sshd_config,vsftpd.conf 等等文件,找不出问题出在哪. 因为 ssh localhost 时 可以连通,ssh 192.168.1.10时就不行 ssh  localhost 如下 ssh 192.168.

wget: unable to resolve host address的解决方法

wget:无法解析主机地址.这就能看出是DNS解析的问题. 解决办法: 登入root(VPS).进入/etc/resolv.conf.修改内容为下nameserver 8.8.8.8 #google域名服务器nameserver 8.8.4.4 #google域名服务器

ssh: connect to host gitlab.alpha.com port 22: Network is unreachable

在这里只说明我遇到的问题和解决方法,可能并不能解决你遇到的问题: git clone git@gitlab.alpha.com:ipcam/ambarella.gitCloning into 'ambarella'...ssh: connect to host gitlab.alpha.com port 22: Network is unreachablefatal: Could not read from remote repository. Please make sure you have