CentOS7 以下的版本默認使用 iptables 做爲防火牆,CentOS 7開始默認使用的是firewall作爲防火牆
本文使用的系統是 CentOS7,所以下面講解的是firewall的操作。
1. 查看防火牆是否開啓
firewall-cmd --state
默認是沒開啓的狀態,如下圖
2. 查看firewalld狀態/開啓/關閉/重啓/開機自啓動
systemctl start firewalld.service //開啓 systemctl status firewalld // 查看狀態 systemctl enable firewalld // 開機自啓動 systemctl stop firewalld // 關閉
3. 查看防火牆規則
如果要查看iptables目前運行的規則,使用iptables -L可以列出
- 查看對外網電腦防火牆列外的端口號 firewall-cmd --zone=public --list-ports
4. 設置規則
– 開放指定端口 firewall-cmd --zone=public --add-port=1936/tcp --permanent – 關閉指定端口 firewall-cmd --zone=public --remove-port=1936/tcp --permanent
– 重啓防火牆 firewall-cmd --reloadl
相關鏈接: