iptables概念
#查看對應表中的所有規則
iptables -t 表名 -L
#查看表的指定鏈中的規則
iptables -t 表名 -L 鏈名
#查看對應表中的所有規則, -v顯示跟詳細的信息
iptables -t 表名 -v -L
# -n 表示不解析IP地址
iptables -t 表名 -n -L
#--line-numbers 顯示規則的序號
iptables --line-numbers -t 表名 -L
#-x 顯示計數器的精確值
iptables -t 表名 -v -x -L
#在指定表指定鏈的尾部增加一條規則,省略-t時,表示默認操作filter表中的規則
命令語法:iptables -t 表名 -A 鏈名 匹配條件 -j 動作
示例:iptables -t filter -A INPUT -s 192.168.1.146 -j DROP
#在指定表指定鏈的首部增加一條規則
命令語法:iptables -t 表名 -I 鏈名 匹配條件 -j 動作
示例:iptables -t filter -I INPUT -s 192.168.1.146 -j ACCEPT
#在指定表指定鏈指定位置增加一條規則
命令語法:iptables -t 表名 -I 鏈名 規則序號 匹配條件 -j 動作
示例:iptables -t filter -I INPUT 5 -s 192.168.1.146 -j REJECT
#設置指定表指定鏈的默認策略,並非添加規則
命令語法:iptables -t 表名 -P 鏈名 動作
示例:iptables -t filter -P FORWARD ACCEPT
#按照規則順序刪除,刪除指定表指定鏈的指定規則
命令語法:iptables -t 表名 -D 鏈名 規則序號
示例:iptables -t filter -D INPUT 3
#按照具體的匹配條件與動作刪除,刪除指定表的指定鏈的指定規則
命令語法:iptables -t 表名 -D 鏈名 匹配條件 -j 動作
示例:iptables -t filter -D INPUT -s 192.168.1.146 -j DROP
#刪除指定表指定鏈的所有規則
命令語法:iptables -t 表名 -F 鏈名
示例:iptables -t filter -F INPUT
#刪除指定表中的所有規則
命令語法:iptables -t 表名 -F
示例:iptables -t filter -F
#修改表中指定鏈的指定規則
命令語法:iptables -t 表名 -R 鏈名 規則序號 規則原本的匹配條件 -j 動作
示例:iptables -t filter -R INPUT 3 -s 192.168.1.146 -j ACCEPT
其他方法:先刪除,再在原編號位置添加一條規則
#修改指定表的指定鏈的默認策略
命令語法:iptables -t 表名 -P 鏈名 動作
示例:iptables -t filter -P FORWARD ACCEPT
#保存命令
service iptables save
& iptables-save > /etc/sysconfig/iptables
#從指定的文件重載規則
iptables-restore < /etc/sysconfig/iptables