随笔 - 1062  文章 - 0  评论 - 82  阅读 - 226万

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

posted on   清明-心若淡定  阅读(23303)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2018-11-10 数字的可视化:python画图之散点图sactter函数详解
2018-11-10 Python使用matplotlib模块绘制多条折线图、散点图
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示