匹配条件:
通用匹配:
-s:源地址
-d:目标地址
IP
NETWORK
!
-p:协议
{icmp|tcp|udp}
-i ininterface 数据包流入接口
PREROUTING、INPUT、FORWARD
-o outinterface 流出接口
OUTPUT、FORWARD、POSTROUTING
扩展匹配:
隐式扩展
-p tcp
--sport PORT[-PORT2]
--dport PORT[-PORT2]
--tcp-flags URG,ACK,SYN,RST,FIN,PSH,ALL,NONE
--syn=--tcp-flags
-p udp
--sport
--dport
-p icmp
--icmp-type
8:ping请求echo-reply
0:ping响应echo-request
显式扩展:需要指定扩展模块,模块位于/lib/iptables/
netfilter
-m state:链接的状态检测
--state
NEW,ESTABLISHED(新链接,正在进行链接)
RELATED,INVALID(一个服务多个链接,无效链接)
-m multiport
--source-ports PORT[,port..]
--ports
--destination-ports
iptable基本操作
iptables -L 列出iptables规则
iptables -F 清除iptables内置规则
iptables -X 清除iptables自定义规则
设定默认规则
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
源地址转换,隐藏内部地址
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT --to 1.1.1.1
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT --to 1.1.1.1-1.1.1.10
地址伪装,动态ip的NAT
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE
masquerade和snat的主要区别在于,snat是把源地址转换为固定的IP地址或者是地址池,而masquerade在adsl等方式拨号上网时候非常有用,因为是拨号上网所以网卡的外网IP经常变化,这样在进行地址转换的时候就要在每次都要修改转换策略里面的ip,使用masquerade就很好的解决了这个问题,他会自己去探测外网卡获得的ip地址然后自动进行地址转换,这样就算外网获得的ip经常变化也不用人工干预了。
