Centos7下默認(rèn)的防火墻是Firewall潮瓶,替代了之前的iptables
firewall配置
- 系統(tǒng)配置目錄
/usr/lib/firewalld/services
目錄中存放定義好的網(wǎng)絡(luò)服務(wù)和端口參數(shù),系統(tǒng)參數(shù),不能修改捞附。 - 用戶配置目錄
/etc/firewalld/
如何自定義添加端口
用戶可以通過修改配置文件的方式添加端口抖甘,也可以通過命令的方式添加端口枉侧,注意帽氓,修改的內(nèi)容會在/etc/firewalld/ 目錄下的配置文件中還體現(xiàn)盟猖。
- 命令的方式添加端口
firewall-cmd --permanent --add-port=9527/tcp
參數(shù)介紹:
- firwall-cmd:是Linux提供的操作firewall的一個工具担巩;
- --permanent:表示設(shè)置為持久方援;
- --add-port:標(biāo)識添加的端口;
另外涛癌,firewall中有Zone的概念犯戏,可以將具體的端口制定到具體的zone配置文件中。
例如:添加8010端口
firewall-cmd --zone=public --permanent --add-port=8010/tcp
--zone=public:指定的zone為public拳话;
- 修改配置文件的方式添加端口
firewall常用命令
- 重啟先匪、關(guān)閉、開啟firewalld.service服務(wù)
service firewalld restart
重啟
service firewalld start
開啟
service firewalld stop
關(guān)閉 - 查看firewall服務(wù)狀態(tài)
systemctl status firewall
- 查看firewall的狀態(tài)
firewall-cmd --state
- 查看防火墻規(guī)則
firewall-cmd --list-all
CentOS切換為iptables防火墻:
切換到iptables首先應(yīng)該關(guān)掉默認(rèn)的firewalld弃衍,然后安裝iptables服務(wù)呀非。
關(guān)閉firewall:
service firewalld stop
systemctl disable firewalld.service
#禁止firewall開機啟動安裝iptables防火墻
yum install iptables-services
yum install iptables* -y
#安裝
注:rpm -qa|grep iptables,查看有沒有iptables的安裝包镜盯,如果你的系統(tǒng)是centos系統(tǒng)岸裙,那么你的yum源就是網(wǎng)絡(luò)yum源,只要保障你的虛擬機能夠上網(wǎng)就行速缆,那么就先yum list查看一下降允,然后直接yum install iptables* -y編輯iptables防火墻配置
vi /etc/sysconfig/iptables #編輯防火墻配置文件
service iptables start
#開啟
systemctl enable iptables.service
#設(shè)置防火墻開機啟動