iptables命令基本用法
# man iptables
NAME
iptables — administration tool for IPv4 packet filtering and NAT
SYNOPSIS
iptables [-t table] {-A|-C|-D} chain rule-specification
iptables [-t table] -I chain [rulenum] rule-specification
iptables [-t table] -R chain rulenum rule-specification
iptables [-t table] -D chain rulenum
iptables [-t table] -S [chain [rulenum]]
iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]
iptables [-t table] -N chain
iptables [-t table] -X [chain]
iptables [-t table] -P chain target
iptables [-t table] -E old-chain-name new-chain-name
rule-specification = [matches...] [target]
match = -m matchname [per-match-options]
target = -j targetname [per-target-options]# iptables -t 表名 -L 列出所有规则 -n 以数值方式显示
# iptables [-t table] -N chain 创建一条自定义的空规则链 # iptables [-t table] -X chain 删除一条自定义的空规则链 # iptables [-t table] -E old-chin-name new-chain-name 为链表改名 # iptables [-t table] -P chain name target 为链表指定默认策略
# iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]
-F:清空链中的规则
-L:list 列出表中的所有规则
-Z:把规则的计数器清零# iptables [-t table] {-A|-D} chain rule-specification
-A:append,附加一条规则
rule-specification:匹配条件 -j 处理机制
匹配条件:(通用匹配)
-s 匹配源地址,可以IP,也可以网络地址:可以使用!操作符取反,!172.168.0.0/16 相当于 --src,或 --source
-d 匹配目标地址,可以IP,也可以网络地址:可以使用!操作符取反,!172.168.0.0/16
-p 匹配协议,通常只能使用{TCP|UDP|ICMP}三者之一
-i 数据报文流入的接口,通常只用于INPUT,FORWARD和PREROUTING
-o 数据报文流出的接口,通常只用OUTPUT,FORWARD和POSTROUTING
扩展匹配
-m 扩展模块名称 --专用选项1 --专用选项2
模块名称及其常用选项
multiport
--source-ports
--destination-ports
--ports
iprange
[!]--src-range from[-to]
time
--datestart
--datestop
--weekday
string
--alog {bm|kmp}
--string "String"
limit
--limit-burst #
state
--state # 5种状态
NEW:新发起的一个连接
ESTABLISHED(netfilter内部维持的会话列表)
RELATED(相关联的命令)(仅仅第一次)
INVALID(无法识别)
UNTRACKED:未被追踪连接
















