Linux系统防火墙模块SELinux及其安全策略管理工具iptables/firewalld命令教程

为什么要介绍Linux系统的防火墙安全模块呢?一个很直接的原因就是很多小伙伴搭建好科学上网服务之后,却无法正常上网,回头检查各项操作都没有问题,这时候却被搞得焦头烂额、一头雾水。其实,一般都是由于Linux系统防火墙没有放行相应端口造成的。一灯不是和尚就通过这篇文章向您介绍Linux系统的防火墙相关的操作知识。

1、Linux系统防火墙常见的模块

一般情况下,我们在Linux系统下常见的防火墙模块有SELinux,而 iptables 和 firewalld 是防火墙安全策略管理工具。其中,iptables 运行在 CentOS 6 及以下系统,firewalld运行在 CentOS 7 及以上系统。

2、SELinux安全增强模块

SELinux,英文名Security-Enhanced Linux,是一个Linux内核的安全增强模块,其提供了访问控制安全策略机制,包括了强制访问控制(Mandatory Access Control,MAC)。SELinux是一组内核修改和用户空间工具,已经被添加到各种Linux发行版中。其软件架构力图将安全决策的执行与安全策略分离,并简化涉及执行安全策略的软件的数量。SELinux虽然保护了我们的系统,但同时也会阻碍很多软件的运行。如果你想要关闭SELinux,则有以下执行命令:

(1)临时关闭SELinux

getenforce #获取当前selinux状态
setenforce 0 #临时关闭

其中,Enforcing为开启,Permissive为关闭。

(2)永久关闭SELinux

vi /etc/selinux/config

找到SELINUX=enforce,改成SELINUX=disabled;把“SELINUXTYPE=targeted”这行注释掉,变成 # “SELINUXTYPE=targeted”,然后保存重启服务器生效;同理如果要开启则删掉注释把disabled改成enforce。

3、iptables防火墙命令

iptables系统防火墙默认安装在 CentOS 6 及以下版本的Linux系统,其中“#”后面为注释内容。

service iptables status #检查是否安装了iptables

yum install y iptables #安装iptables

yum update iptables #升级iptables

yum install iptablesservices y #安装iptables-services

service iptables restart #重启iptables

service iptables start #启动iptables

service iptables stop #停止iptables

service iptables restart #重启iptables

chkconfig iptables on #开机自启

chkconfig iptables off #关闭开机自启

4、firewalld防火墙命令

firewalld系统防火墙默认安装在 CentOS 7 及以上版本的Linux系统,其中“#”后面为注释内容。

systemctl status firewalld.service ##查看firewall状态

yum y install firewall* ##安装firewall命令

yum y remove firewall* ##卸载firewall命令

systemctl start firewalld.service ##打开firewall命令

systemctl stop firewalld.service ##关闭firewall命令

systemctl restart firewalld.service ##重启firewall

systemctl disable firewalld.service ##禁止firewall开机自启

systemctl enable firewalld.service ##允许firewall开机自启

在Linux系统中,除了系统自带的防火墙安全模块以外,很多大公司的服务器产品还有专用的安全管理模块,如阿里云盾(安骑士)、腾讯云镜等。

本文由一灯不是和尚更新于2020年9月10日;如果您有什么意见或建议,请在文章下面评论区留言反馈。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注