1. Edit firewall configuration:
Vi/etc/sysconfig/iptables
Firewall Add new port 2222
-A input-m State--state new-m tcp-p TCP--dport 2 222-j ACCEPT
======================================================================
# Firewall Configuration written by System-config-firewall
# Manual Customization of the This file was not recommended.
*filter
: INPUT accept [0:0]
: FORWARD accept [0:0]
: OUTPUT accept [0:0]
-A input-m state–state established,r Elated-j Accept
-a input-p icmp-j accept
-a input-i lo-j accept
-a input-m state–state new-m tcp-p tcp– Dport 22-j Accept
-a input-m state–state new-m tcp-p tcp–dport 2222-j Accept
-a input-j reject–reject-with icmp-host-prohibited
-A forward-j reject–reject-with icmp-host-prohibited
COMMIT
Restart the firewall for the configuration to take effect:
/ Etc/init.d/iptables Restart
or
service iptables restart
2. Backup SSH port configuration file
Cp/etc/ssh/ssh_config/etc/ssh/ssh_configbak
Cp/etc/ssh/sshd_config/etc/ssh/sshd_configbak
Modify the SSH port to: 2222
Vi/etc/ssh/sshd_config
Add port 2222 below ports #port 22
Vi/etc/ssh/ssh_config
Add port 2222 below ports #port 22
Restart:
/etc/init.d/sshd restart
Or
service sshd restart
After the 2222 port can be connected normally, return to repeat the above steps. The 22 port is disabled, and then SSH can only be connected with 2222 port!
CentOS Modify SSH Port