ssh遇到port22:Noroutetohost问题的解决⽅法⼀ 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 /st.rules
iptables-restore < /st.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
ssh命令指定端口如果出现
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-
开放指定端⼝
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