1. 程式人生 > 實用技巧 >Linux系統防火牆模組SELinux及其安全策略管理工具iptables/firewalld命令教程

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 instally iptables#安裝iptables

yum update iptables#升級iptables

yum install iptablesservicesy#安裝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狀態

yumy install firewall*##安裝firewall命令

yumy 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系統中,除了系統自帶的防火牆安全模組以外,很多大公司的伺服器產品還有專用的安全管理模組,如阿里雲盾(安騎士)、騰訊雲鏡等。