netfilter/iptables 指南

netfilter/iptables

簡述歷史

  • kernel 2.0.x IPfwadm
  • kernel 2.2.x IPchains
  • kernel 2.4.x Netfilter
  • kernel 3.13.x NFtables

iptables基礎

netfilter/iptables 分別是內核態模塊和用戶態工具,管理員經過iptables給netfilter變動規則tcp

netfilter/iptables 預設的表和鏈

  • 內置了五個表,分別是 filter, nat, mangle, raw, security 分別對應的內核模塊是 /lib/modules/x.x.x/kernel/net/ipv4/netfilter/ 目錄下的

<pre> iptable_filter.ko iptable_nat.ko iptable_mangle.ko iptable_raw.ko iptable_security.ko </pre>工具

  • 預設了五個chain 分別是 POSTROUTING, INPUT, FORWARD, OUTPUT, POSTROUTING 能夠用經過 iptable -t table_name -L 來查看,詳見 man iptables

iptables 的啓用與停用

以 默認的filter爲例ip

<pre> 啓用filter表:modprobe iptable_filter 啓用filter表:modprobe -r iptable_filter </pre>it

命令基本格式

iptables 語法分紅三部分:table

命令 動做 條件準則 處置方式
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  • iptables的基本操做

<pre> (iptable 命令默認約定 若是 -t 參數不指定 默認是 -t filter ) iptables -t filter -L # 列出filter表全部chain的規則 iptables -t filter -F # 清除全部默認 chain的規則 iptables -t filter -N # 新增自定義的chain iptables -t filter -X # 清除自定義的chain的以及對應的規則 iptables -t filter -P # </pre>基礎

  • 查看規則 iptables-save

<pre> # Generated by iptables-save v1.4.12 on Tue Apr 22 14:55:51 2014 *filter :INPUT ACCEPT [1689:106559] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [1608:154769] -A INPUT -s 192.168.1.0/32 -p tcp -m multiport --dports 80 -j ACCEPT -A INPUT -p tcp -m multiport --dports 80 -j DROP COMMIT # Completed on Tue Apr 22 14:55:51 2014 # Generated by iptables-save v1.4.12 on Tue Apr 22 14:55:51 2014 *raw :PREROUTING ACCEPT [2498:166654] :OUTPUT ACCEPT [2298:219551] COMMIT # Completed on Tue Apr 22 14:55:51 2014 </pre>module

相關文章
相關標籤/搜索