# 開啟和關閉防火牆
systemctl start firewalld # 啟動防火牆
systemctl status firewalld # 檢視防火牆狀態
systemctl stop firewalld # 關閉防火牆
systemctl disable firewalld # 開啟不啟動防火牆
systemctl enable firewalld # 開機啟動防火牆
centos7 防火牆新增埠:【單個】
firewall-cmd --zone=public --add-port=443/tcp --permanent
centos7 防火牆新增埠:【範圍】
firewall-cmd --zone=public --add-port=20000-30000/tcp --permanent
【重新載入】
firewall-cmd --reload
【檢視】
firewall-cmd --zone=public --list-ports
【刪除】
firewall-cmd --zone=public --remove-port=80/tcp --permanent
切換到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 #設定防火牆開機啟動
-a input -p tcp -m state --state new -m tcp --dport 80 -j accept
-a input -p tcp -m state --state new -m tcp --dport 443 -j accept
-a input -p tcp -m state --state new -m tcp --dport 3306 -j accept
-a input -p tcp -m state --state new -m tcp --dport 6379 -j accept
-a input -p tcp -m state --state new -m tcp --dport 8022 -j accept
-a input -p tcp -m state --state new -m tcp --dport 8024 -j accept
-a input -p tcp -m state --state new -m tcp --dport 8080 -j accept
-a input -p tcp -m state --state new -m tcp --dport 8082 -j accept
-a input -p tcp -m state --state new -m tcp --dport 8192 -j accept
-a input -p tcp -m state --state new -m tcp --dport 18080 -j accept
-a input -p tcp -m state --state new -m tcp --dport 10000:20000 -j accept
# 禁止ip訪問
-i input -s 120.227.17.174 -j drop
Centos7防火牆及埠設定
1 查詢防火牆開放的埠 firewall cmd zone public list ports 2 防火牆開放埠 firewall cmd zone public add port 5672 tcp permanent 開放5672埠 firewall cmd zone public remove ...
Centos7埠和防火牆設定
1 開啟埠 firewall cmd zone public add port 9092 tcp permanent返回success即使開啟埠成功 zone 作用域 add port 80 tcp 新增埠,格式為 埠 通訊協議 permanent 永久生效 2 重啟centos7的防火牆 syst...
Centos 7 設定防火牆
centos 7 firewall 命令 檢視已經開放的埠 firewall cmd list ports開啟埠 firewall cmd zone public add port 80 tcp permanent命令含義 zone 作用域 add port 80 tcp 新增埠,格式為 埠 通訊協...