1. 程式人生 > >centos7中防火牆設定

centos7中防火牆設定

官方文件:

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sec-using_firewalls#sec-Introduction_to_firewalld1

一、firewall介紹
CentOS 7中防火牆是一個非常的強大的功能,在CentOS 6.5中在iptables防火牆中進行了升級了。我的阿里雲centos7中預設使用firewall,並且預設沒有開啟。 
注意:使用阿里雲伺服器,先要在阿里雲後控制檯的安全組開放埠,然後關閉centos防火牆或者開放centos的對應埠,才能訪問阿里雲!

二、firewall配置
The configuration for firewalld is stored in various XML files in /usr/lib/firewalld/ and /etc/firewalld/.

This allows a great deal of flexibility as the files can be edited, written to, backed up, used as templates for other installations and so on.

注意:以下firewalld 的操作只有重啟之後才有效:service firewalld restart 重啟
 

1、系統配置目錄

/usr/lib/firewalld/services

目錄中存放定義好的網路服務和埠引數,系統引數,不能修改。

2、使用者配置目錄

/etc/firewalld/

3、如何自定義新增埠

使用者可以通過修改配置檔案的方式新增埠,也可以通過命令的方式新增埠,注意,修改的內容會在/etc/firewalld/ 目錄下的配置檔案中體現。

3.1、命令的方式新增埠

firewall-cmd --permanent --add-port=9527/tcp 
引數介紹:

1、firewall-cmd:是Linux提供的操作firewall的一個工具;
2、--permanent:表示設定為持久;
3、--add-port:標識新增的埠;

另外,firewall中有Zone的概念,可以將具體的埠制定到具體的zone配置檔案中。

例如:新增8010埠

firewall-cmd --zone=public --permanent --add-port=8010/tcp

--zone=public:指定的zone為public;

三、firewall常用命令

1、重啟、關閉、開啟firewalld服務

systemctl start firewalld         # 啟動,
systemctl enable firewalld     # 開機啟動
systemctl stop firewalld         # 關閉
systemctl disable firewalld     # 取消開機啟動
service firewalld restart         #重啟

2、檢視firewall的狀態

firewall-cmd --state

3、檢視防火牆規則

firewall-cmd --list-all