Centos7 防火牆常用配置及說明

2021-10-07 00:14:24 字數 3561 閱讀 5428

一、 centos7和centos6 防火牆的區別:

使用的工具不一樣了。centos6 使用的是iptables ,centos7 使用的是filewall

iptables 用於過濾資料報,屬於網路層防火牆。

firewall 能夠允許哪些服務可用,那些埠可用...屬於更高一層的防火牆。

二、常用命令:

vi /usr/lib/firewalld/services/ssh.xml

vi /usr/lib/firewalld/services/html.xml

systemctl enable firewalld.service

systemctl restart firewalld.service

firewall-cmd --state

firewall-cmd --list-all

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

vi /etc/firewalld/zones/public.xml

systemctl restart firewalld.service

三、firewall 配置

the configuration for firewalld is stored in various xml files

in /usr/lib/firewalld and /etc/firewalld

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

1、系統配置目錄

/usr/lib/firewalld/services

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

2、使用者配置目錄

3、如何自定義新增埠

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

3.1 、命令的方式新增埠:

firwall-cmd --permanent --add-port=9527/tcp

引數介紹:

1、firwall-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;

如果–zone=dmz 這樣設定的話,會在dmz.xml檔案中新增一條。

l 3.2、修改配置檔案的方式新增埠

<?xml version="1.0" encoding="utf-8"?> public for use in public areas.

放通指定ip,指定埠、協議       放通任意ip訪問伺服器的9527埠      

上述的乙個配置檔案可以很好的看出:

1、新增需要的規則,開放通源ip為122.10.70.234,埠514,協議tcp; 2、開放通源ip為123.60.255.14,埠10050-10051,協議tcp;/3、開放通源ip為任意,埠9527,協議tcp;

四、firewall常用命令

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

service firewalld restart 重啟

service firewalld start 開啟

service firewalld stop 關閉

systemctl status firewalld

systemctl stop firewalld 關閉

systemctl start firewalld 開啟

systemctl restart firewalld 重啟

systemctl disable firewalld 關閉開機啟動

2、檢視狀態

firewall-cmd --state

3、檢視防火牆規則

firewall-cmd --list-all

五、centos 切換為iptables防火牆

切換到iptables首先應該關掉預設的firewalld,然後安裝iptables服務。

1、關閉firewall:

service firewalld stop systemctl disable firewalld.service #禁止firewall開機啟動

2、安裝iptables防火牆

yum install iptables-services #安裝

3、編輯iptables防火牆配置

vi /etc/sysconfig/iptables #編輯防火牆配置檔案

下邊是乙個完整的配置檔案:

firewall configuration written by system-config-firewall manual customization of this file is not recommended.

*filter :input accept [0:0] :forward accept [0:0] :output accept [0:0]

-a input -m state --state established,related -j accept

-a input -p icmp -j accept -a input -i lo -j accept

-a input -m state --state new -m tcp -p tcp --dport 22 -j accept

-a input -m state --state new -m tcp -p tcp --dport 80 -j accept

-a input -m state --state new -m tcp -p tcp --dport 3306 -j accept

-a input -j reject --reject-with icmp-host-prohibited

-a forward -j reject --reject-with icmp-host-prohibited

commit

:wq! #儲存退出

service iptables start #開啟systemctl enable iptables.service #設定防火牆開機啟動

centos7防火牆配置

centos7防火牆配置 centos7使用的是linux kernel 3.10.0的核心版本,新版的kernel核心已經有了防火牆netfilter,並且firewalld的使用效能更高,穩定性更好。centos7配置防火牆的兩種方法 一 使用xml配置檔案的方式配置 方法一cp usr lib...

centos7防火牆配置

使用命令的方式配置centos7 防火牆 add firewall cmd permanent zone public add port 8080 tcp remove firewall cmd permanent zone public remove port 8080 tcp reload fi...

Centos7 防火牆配置

1 firewalld的基本使用 啟動 systemctl start firewalld 關閉 systemctl stop firewalld 檢視狀態 systemctl status firewalld 開機禁用 systemctl disable firewalld 開機啟用 system...