CentOS 7.0默认使用的是firewall作为防火墙。
firewall:
systemctl start firewalld.service#启动firewall
systemctl stop firewalld.service#停止firewall
systemctl disable firewalld.service#禁止firewall开机启动
Systemctl diablefirewalld 永久关闭防火墙
vim/etc/sysconfig/selinux 并修改SELINUX=enforce行为SELINUX=disabled 关闭selinux
Centos7 修改SSH 端口
修改/etc/ssh/sshd_config
vi /etc/ssh/sshd_config
port 22 ——> port 2212
修改firewall配置
添加到防火墙:
firewall-cmd --zone=public --add-port=2212/tcp --permanent (permanent是保存配置,不然下次重启以后这次修改无效)
重启:
firewall-cmd --reload
查看添加端口是否成功,如果添加成功则会显示yes,否则no
firewall-cmd --zone=public --query-port=2212/tcp
修改SELinux
使用以下命令查看当前SElinux 允许的ssh端口:
semanage port -l | grep ssh
添加2212端口到 SELinux
semanage port -a -t ssh_port_t -p tcp 2212
然后确认一下是否添加进去
semanage port -l | grep ssh
如果成功会输出
ssh_port_t tcp 33378, 22
重启ssh
systemctl restart sshd.service
在阿里云服务器上可以简化步骤为:
systemctl stop firewalld.service#停止firewall
vi /etc/ssh/sshd_config
port 22 ——> port 2212
systemctl restart sshd.service
SSH端口即修改为2212
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。