iptables

經由先前的簡易測試,我們針對ipv4設置iptables的過濾規則

清理規則

-F : Deleting (flushing) all the rules.

-X : Delete chain.

-t table_name : Select table (called nat or mangle) and delete/flush rules.

-P : Set the default policy (such as DROP, REJECT, or ACCEPT).

# Flush filter
IPTABLES=/sbin/iptables
$IPTABLES -F
$IPTABLES -X

echo "Flush mangle table ......"
echo
# Flush mangle
$IPTABLES -F -t mangle
$IPTABLES -t mangle -X


echo "Flush nat table ......"
echo
# Flush nat
$IPTABLES -F -t nat
$IPTABLES -t nat -X
###-----------------------------------------------------###
# 設定 filter table 的預設政策
###-----------------------------------------------------###
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT

IPTables中,主要有三張table,每張table內有專屬的chain,每個chain裡面有一系列的rule。

圖片來源:http://www.thegeekstuff.com/2011/01/iptables-fundamentals/

所以,在進行規則規劃前,都應先清除所有的規則,保持乾淨

以前寫的shell

Last updated

Was this helpful?