以下只是針對自定義規則的簡單說明和舉例,其實也就是幫助文檔裏面的東西;詳細的說明自行參考 firewall-cmd --help
傳遞的參數 <args> 與 iptables, ip6tables 以及 ebtables 一致!
Centos7 Firewall 用戶操作接口依然調用系統內核的iptables模塊來設定規則!
直接選項
–direct需要是直接選項的第一個參數。
將命令傳遞給防火牆。參數 <args> 可以是 iptables, ip6tables 以及 ebtables 命令行參數。
firewall-cmd --direct --passthrough { ipv4 | ipv6 | eb } <args>
爲表 <table> 增加一個新鏈 <chain> 。
firewall-cmd --direct --add-chain { ipv4 | ipv6 | eb } <table> <chain>
從表 <table> 中刪除鏈 <chain> 。
firewall-cmd --direct --remove-chain { ipv4 | ipv6 | eb } <table> <chain>
查詢 <chain> 鏈是否存在與表 <table >. 如果是,返回0,否則返回1.
firewall-cmd --direct --query-chain { ipv4 | ipv6 | eb } <table> <chain>
如果啓用,此命令將有返回值。此命令沒有輸出信息。
獲取用空格分隔的表 <table> 中鏈的列表。
firewall-cmd --direct --get-chains { ipv4 | ipv6 | eb } <table>
爲表 <table> 增加一條參數爲 <args> 的鏈 <chain> ,優先級設定爲 <priority>。
firewall-cmd --direct --add-rule { ipv4 | ipv6 | eb } <table> <chain> <priority> <args>
參考示例:
方式-:[reload 生效,修改後重啓纔可生效]
# firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 1 -s 192.168.1.0/24 -p tcp --dport=22 -j ACCEPT
# firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 2 -p tcp --dport=22 -j DROP
方式二:[重載或重啓後失效]
# iptables -t filter -I INPUT_direct -s 192.168.1.20 -p tcp --dport=22 -j ACCEPT
# iptables -A INPUT_direct -p tcp --dport=22 -j DROP
從表 <table> 中刪除帶參數 <args> 的鏈 <chain>。
firewall-cmd --direct --remove-rule { ipv4 | ipv6 | eb } <table> <chain> <args>
# firewall-cmd --direct --remove-rule ipv4 filter INPUT 2 -p tcp --dport=22 -j DROP
查詢帶參數 <args> 的鏈 <chain> 是否存在表 <table> 中
firewall-cmd --direct --query-rule { ipv4 | ipv6 | eb } <table> <chain> <args>
獲取表 <table> 中所有增加到鏈 <chain> 的規則,並用換行分隔。
firewall-cmd --direct --get-rules { ipv4 | ipv6 | eb } <table> <chain>