关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

云服务器:centOS 7 与 centOS 6 区别之防火墙

发布时间:2020-04-07 10:35:37

云服务器 centOS 7 与 centOS 6 区别之防火墙

  •  加入了 systemctl 这一神器

  •  防火墙设置不同

  •  加入了更高级别的安全设置(SELinux)


centOS 7 开始防火墙使用 firewalld 代替了 iptables

firewalld 简单使用:

开机启动 | 开机不启动 | 启动 | 停止 | 重启 | 查询状态 firewalld 防火墙服务

systemctl enable|disable|start|stop|restart|status firewalld

永久(--permanent) 开放(--zone=public) 某一个端口:

firewall-cmd --add-port=667/tcp --add-port=888-890/tcp --zone=public --permanent


同时永久(--permanent) 开放(--zone=public) 多个(包括连续的和不连续的)端口:

firewall-cmd --add-port=667/tcp --add-port=888-890/tcp --zone=public --permanent


永久(--permanent) 移除(remove) 一个或多个开放的(--zone=public)端口:

firewall-cmd --remove-port=6666/tcp --zone=public --permanent


查询开放的端口:

firewall-cmd --list-port


刷新/重新载入 防火墙:

firewall-cmd --reload


在每一次更新防火墙规则(包括更新端口、添加屏蔽 ip 等操作) 之后都必须重新载入才会生效


引入 SELinux

什么是 SELinux ? 其全名是: Security Enhanced Linux,简单来讲就是更高级别的安全设置(这玩意儿的戏特别多,一不小心就会被它坑了)


有些时候,当你以为使用 firewalld 开放了防火墙端口就万事大吉的时候,说不定你的服务就被这玩意给拦截了


SELinux 端口管理简单使用:


安装 SELinux 管理工具 semanage :

yum install policycoreutils-python


查看某一项服务(如 http) 相关的端口:

semanage port -l | grep http


向 SELinux 中添加一项服务(如 xxx 服务)的开放端口

semanage port -a -t xxx_port_t -p tcp 2333


将 SELinux 中的端口移除:

semanage port --delete -t http_port_t -p tcp 8899-8902


重启 SELinux 服务:

systemctl restart sshd.service



/template/Home/Zkeys2/PC/Static