一本讥、 Centos7和Centos6 防火墻的區(qū)別:
使用的工具不一樣了呕臂。Centos6 使用的是iptables炭分,Centos7 使用的是filewall
iptables 用于過濾數(shù)據(jù)包,屬于網(wǎng)絡(luò)層防火墻都伪。
firewall 能夠允許哪些服務(wù)可用最欠,那些端口可用...屬于更高一層的防火墻示罗。
二、常用命令:
vim /usr/lib/firewalld/services/ssh.xml
vim /usr/lib/firewalld/services/http.xml
systemctl enable firewalld.service
systemctl restart firewalld.service
firewall-cmd --state 查看狀態(tài)
firewall-cmd --list-all 查看過濾的列表信息
firewall-cmd --zone=public --permanent --add-port=8502/tcp 添加一個協(xié)議為tcp的8502端口過濾
vim /etc/firewalld/zones/public.xml <port protocol="tcp" port="8502"/>
systemctl restart firewalld.service
三芝硬、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的配置存儲在各種XML文件中
在/usr/lib/firewalld和/etc/firewalld中
這允許極大的靈活性蚜点,因為文件可以被編輯、寫入拌阴、備份绍绘、用作其他安裝的模板等等。
注意:以下firewalld 的操作只有重啟之后才有效:service firewalld restart
1迟赃、系統(tǒng)配置目錄(/usr/lib/firewalld/services)
目錄中存放定義好的網(wǎng)絡(luò)服務(wù)和端口參數(shù)陪拘,系統(tǒng)參數(shù),不能修改纤壁。
2左刽、用戶配置目錄(/etc/firewalld/)
3、如何自定義添加端口
用戶可以通過修改配置文件的方式添加端口酌媒,也可以通過命令的方式添加端口欠痴,注意:修改的內(nèi)容會在/etc/firewalld/目錄下的配置文件中體現(xiàn)迄靠。
3.1 、命令的方式添加端口:
firwall-cmd --permanent --add-port=9527/tcp
參數(shù)介紹:
1喇辽、firwall-cmd:是Linux提供的操作firewall的一個工具掌挚;
2、--permanent:表示設(shè)置為持久菩咨;
3吠式、--add-port:標(biāo)識添加的端口;
另外旦委,firewall中有Zone的概念,可以將具體的端口制定到具體的zone配置文件中雏亚。
例如:添加8010端口
firewall-cmd --zone=public --permanent --add-port=8010/tcp
--zone=public:指定的zone為public缨硝;
如果--zone=dmz 這樣設(shè)置的話,會在dmz.xml文件中新增一條罢低。
3.2查辩、修改配置文件的方式添加端口
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas.</description>
<rule family="ipv4">
<source address="122.10.70.234"/>
<port protocol="udp" port="514"/>
<accept/>
</rule>
<rule family="ipv4">
<source address="123.60.255.14"/>
<port protocol="tcp" port="10050-10051"/>
<accept/>
</rule>
<rule family="ipv4">
<source address="192.249.87.114"/> 放通指定ip,指定端口网持、協(xié)議
<port protocol="tcp" port="80"/>
<accept/>
</rule>
<rule family="ipv4"> 放通任意ip訪問服務(wù)器的9527端口
<port protocol="tcp" port="9527"/>
<accept/>
</rule>
</zone>
上述的一個配置文件可以很好的看出:
1宜岛、添加需要的規(guī)則,開放通源ip為122.10.70.234功舀,端口514萍倡,協(xié)議tcp;
2辟汰、開放通源ip為123.60.255.14列敲,端口10050-10051,協(xié)議tcp帖汞;
3戴而、開放通源ip為任意,端口9527翩蘸,協(xié)議tcp所意;
四、firewall常用命令
1催首、重啟扶踊、關(guān)閉、開啟郎任、firewalld.serverice 服務(wù)
Service firewalld restart 重啟
Service firewalld start 開啟
Service firewalld stop 關(guān)閉
systemctl status firewalld 查看狀態(tài)
systemctl stop firewalld 關(guān)閉
systemctl start firewalld 開啟
systemctl restart firewalld 重啟
systemctl disable firewalld 關(guān)閉開機啟動
2姻檀、查看狀態(tài)
firewall-cmd --state
3、查看防火墻規(guī)則
firewall-cmd --list-all
五涝滴、Centos 切換為iptables防火墻
提示:切換到iptables首先應(yīng)該關(guān)掉默認的firewalld绣版,然后安裝iptables服務(wù)胶台。
1、關(guān)閉firewall:
systemctl stop firewalld.service
systemctl disable firewalld.service #禁止firewall開機啟動
2杂抽、安裝iptables防火墻:
yum install iptables-services #安裝
3诈唬、編輯iptables防火墻配置:
vim /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 start iptables.service #開啟
systemctl enable iptables.service #設(shè)置防火墻開機啟動