1、先查看下服務器端口號範圍:
sysctl -a|grep ip_local_port_range
2、備份防火牆配置
cp /etc/sysconfig/iptables /etc/sysconfig/iptables.old
3、編輯並增加
-A INPUT -p tcp -m state --state NEW -m tcp --dport 12345 -j ACCEPT
4、防火牆重啓,使配置生效
service iptables restart
5、備份ssh端口文件
cp /etc/ssh/ssh_config /etc/ssh/ssh_config.old
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.old
6、vi /etc/ssh/sshd_config
在端口#Port 22下面增加Port 12345(去掉#)
7、vi /etc/ssh/ssh_config
在端口#Port 22下面增加Port 12345(去掉#)
8、重啓SSH服務
service sshd restart
9、用12345端口連接成功之後,再回過來刪除iptables的22端口