How to solve port 22: No route to host problems in ssh
Iptables Problems
1. No installation. you can install it first.
Yum install iptables
2. Firewall enabling and disabling
Takes effect immediately, and the restart fails.
Service iptables start (Enabled)
Service iptables stop (disabled)
Service iptables restart (restart)
Valid permanently
Chkconfig iptables on (Enabled)
Chkconfig iptables off (disabled)
View firewall running status
Service iptables status
3. Clear firewall rules
Iptables-F
Iptables-X
Iptables-Z
4. open port 22
Iptables-a input-p tcp-dport 22-j ACCEPT
Iptables-a output-p tcp-sport 22-j ACCEPT
5. Save settings
/Etc/rc. d/init. d/iptables save
Service iptables restart (restart)
At the end of the iptables operation, remember to perform this step (such as 3, 4)
6. View firewall rules
Iptables-nL
7. Add Rules Directly to the firewall File
Vi/etc/iptables. test. rules
Iptables-restore </etc/iptables. test. rules (load rules first after modification)
Iptables-save>/etc/iptables. rules (save rules)
Ii. SSH Problems1. ssh running status
Service sshd status
If
Loaded: error (Reason: No such file or directory)
Ssh is not installed
Check whether the ssh package is installed
Rpm-qa | grep ssh
No
Yum install openssh-server
Or
Yum install sshd
(Uninstall ssh service) yum remove sshd
If
Openssh-daemon is stopped
It indicates that ssh is installed but not enabled.
Takes effect immediately, and the restart fails.
Service sshd start
Service sshd stop
Valid permanently
Chkconfig sshd on
Chkconfig sshd off
2. Modify the default ssh port 22 (in this example, change to 3547)
Vi/etc/sysconfig/iptables
Join
-A input-m state-state NEW-m tcp-p tcp-dport 3547-j ACCEPT
Restart Firewall
/Etc/init. d/iptables restart
(Optional)
Port 22 can be blocked based on your ssh status
Vi/etc/sysconfig/iptables
In
-A RH-Firewall-1-INPUT-m state-state NEW-m tcp-p tcp-dport 22-j ACCEPT
Add # comment out this statement
Remember to restart the Firewall
Install semanage
Yum-y install policycoreutils-Python
Open specified port
Semanage port-a-t ssh_port_t-p tcp 3547
Restart the ssh service
/Etc/init. d/sshd restart
View port status
Semanage port-l | grep ssh
You can see
Ssh_port_t tcp 3547, 22
3. view port status
Netstat-antulp | grep ssh
Now, we will add more problems later.