iptables basic
iptables basic iptables 是 Linux 内核集成的 IP 信息包过滤系统。该系统用于在 Linux 系统上控制 IP 数据包过滤和防火墙配置 iptables 操作的是 2.4 以上内核的 netfilter。所以需要 linux 的内核在 2.4 以上。其功能与安全性远远比其前辈 ipfwadm, ipchains 强大,iptables大致是工作在OSI七层的二、三、四层,其前辈ipchains不能单独实现对tcp/udp port以及对mac地址的的定义与操作 iptables-nft iptables vs. iptables-nft https://developers.redhat.com/blog/2020/08/18/iptables-the-two-variants-and-their-relationship-with-nftables#the_iptables_rules_appear_in_the_nftables_rule_listing iptables 包含4个表,5个链 其中表是按照对数据包的操作区分的,链是按照不同的Hook点来区分的,表和链实际上是netfilter的两个维度. 4个表: filter, nat, mangle, raw,默认表是 filter (没有指定表 ( -t ) 的时候就是filter表) 。 表的处理优先级: raw>mangle>nat>filter 4 个表 filter: 一般的过滤功能, 这是默认的表,包含了内建的链 INPUT (处理进入的包)、FORWARD (处理通过的包) 和OUTPUT (处理本地生成的包) 。 nat: 用于nat功能 (端口映射,地址映射等),对应的链: PREROUTING (修改到来的包)、OUTPUT (修改路由之前本地的包) 、POSTROUTING (修改准备出去的包) ,centos6没有input链,centos7 有 input 链。 mangle: 用于对特定数据包的修改, 对应的链: PREROUTING (修改路由之前进入的包) ,input, OUTPUT (修改路由 IPTABLES 之前本地的包), forward, postrouting raw: 优先级最高,设置raw时一般是为了不再让iptables做数据包的链接跟踪处理,提高性能 5 个链: PREROUTING, INPUT, FORWARD, OUTPUT, POSTROUTING PREROUTING: 数据包进入路由表之前 INPUT: 通过路由表后目的地为本机 FORWARD: 通过路由表后, 目的地不为本机 OUTPUT: 由本机产生, 向外转发 POSTROUTIONG: 发送到网卡接口之前 iptables 规则的语法 iptables [-t table] COMMAND chain CRETIRIA -j ACTION -t table : 3个filter nat mangle COMMAND: 定义如何对规则进行管理 chain: 指定你接下来的规则到底是在哪个链上操作的,当定义策略的时候,是可以省略的 CRETIRIA:指定匹配标准 -j ACTION :指定如何进行处理 iptables [-t table] COMMAND chain CRETIRIA -j ACTION iptables [-t table] -[AD] chain rule-specification [options] iptables [-t table] -I chain [rulenum] rule-specification [options] iptables [-t table] -R chain rulenum rule-specification [options] iptables [-t table] -D chain rulenum [options] iptables [-t table] -[LFZ] [chain] [options] # 创建新的链 iptables [-t table] -N chain iptables [-t table] -X [chain] iptables [-t table] -P chain target [options] iptables [-t table] -E old-chain-name new-chain-name # 创建链 iptables -t mangle -N chain0 指定链 iptables -t filter -L FORWARD nf_conntrack iptalbes 会使用 nf_conntrack 模块跟踪连接,而这个连接跟踪的数量是有最大值的,当跟踪的连接超过这个最大值,就会导致连接失败。 通过命令查看 ...