1. 程式人生 > >3.iptables 擴展模塊

3.iptables 擴展模塊

invalid containe quest bili ner -h soft inf aos

--tcp-flags

用於匹配報文的tcp頭的標誌位

iptables -t filter -I INPUT  -p tcp -m tcp --dport 22   --tcp-flags SYN,ACK,FIN,RST,URG,PSH SYN -j REJECT
iptables -t filter -I OUTPUT -p tcp -m tcp --sport 22 --tcp-flags SYN,ACK,FIN,RST,URG,PSH SYN,ACK -j REJECT
iptables -t filter -I INPUT -p tcp -m tcp --dport 22
--tcp-flags ALL SYN -j REJECT
iptables -t filter -I OUTPUT -p tcp -m tcp --sport 22 --tcp-flags ALL SYN,ACK -j REJECT
--syn

用於匹配tcp新建連接的請求報文,相當於“--tcp-flags SYN,RST,ACK,FIN SYN”

iptables -t filter -I INPUT -p tcp -m tcp --dport 22 --syn -j REJECT
udp

--sport 匹配udp報文的源地址
--dsport 匹配udp報文的目標地址

iptables -t filter -I INPUT -p udp -m udp --dport 137 -j ACCEPT
iptables -t filter -I INPUT -p udp -m udp --dport 137:157 -j ACCEPT
#可以結合multiport模塊指定多個離散的端口
icmp

--icmp-type 匹配icmp報文的具體類型

iptables -t filter -I INPUT -p icmp -m icmp --icmp-type 8/0 -j REJECT
iptables -t filter -I INPUT -p icmp --icmp-type 8
-j REJECT iptables -t filter -I OUTPUT -p icmp -m icmp --icmp-type 0/0 -j REJECT iptables -t filter -I OUTPUT -p icmp --icmp-type 0 -j REJECT iptables -t filter -I INPUT -p icmp --icmp-type "echo-request" -j REJECT
state
  1. NEW
  2. ESTABLISHED
  3. RELATED
  4. INVALID
  5. UNTRACKED
iptables -F
iptables -t filter -I  -m state --state RELATED,ESTABLISHED -j ACCEPET
iptables -t filter -A INPUT -j REJECT

3.iptables 擴展模塊