1。The first is the mangle table which is responsible for the alteration of quality of service bits in the TCP header.
2。The second table is the filter queue which is responsible for packet filtering.
* Forward chain: Filters packets to servers protected by the firewall.
* Input chain: Filters packets destined for the firewall.
* Output chain: Filters packets originating from the firewall.
3。The third table is the nat queue which is responsible for network address translation. It has two built-in chains; these are:
* Pre-routing chain: NATs packets when the destination address of the packet needs to be changed.
* Post-routing chain: NATs packets when the source address of the packet needs to be changed
iptables 是采用规则堆栈的方式来进行过滤,当一个封包进入网卡,会先检查 Prerouting,然后检查目的 IP 判断是否需要转送出去,接着就会跳到 INPUT 或 Forward 进行过滤,如果封包需转送处理则检查 Postrouting,如果是来自本机封包,则检查 OUTPUT 以及 Postrouting。过程中如果符合某条规则将会进行处理,处理动作除了 ACCEPT、REJECT、DROP、REDIRECT 和 MASQUERADE 以外,还多出 LOG、ULOG、DNAT、SNAT、MIRROR、QUEUE、RETURN、TOS、TTL、MARK 等,其中某些处理动作不会中断过滤程序,某些处理动作则会中断同一规则炼的过滤,并依照前述流程继续进行下一个规则炼的过滤,一直到堆栈中的规则检查完毕为止。
iptables -A FORWARD -p tcp --dport 22 -j REJECT --reject-with tcp-reset
iptables -t nat -I PREROUTING -p tcp --dport 8080 -j REDIRECT --to-ports 80
iptables -t nat -A POSTROUTING -p tcp -j MASQUERADE --to-ports 1024-3000
LOG 将封包相关讯息纪录在 /var/log/messages 中,进行完此处理动作后,将会继续比对其它规则。例如:
iptables -A INPUT -p tcp -j LOG --log-prefix ‘INPUT packets‘
iptables -t nat -A POSTROUTING -p tcp -o eth0 -j SNAT --to-source 1.1.1.1-1.1.1.3:1024-3000
iptables -t nat -A PREROUTING -d 1.1.1.1 -p tcp --dport 80 -j DNAT --to-destination 1.1.1.2-1.1.1.5
iptables -t mangle -A PREROUTING -p udp --dport 22 -j MARK --set-mark 22
原文:https://www.cnblogs.com/dissipate/p/13746781.html