当前位置:
首页
文章
前端
详情

Linux中iptables的正确使用

1.首先介绍一下指令和相关配置文件

启动指令:service iptables start

重启指令:service iptables restart

关闭指令:service iptables stop

然后是相关配置:/etc/sysconfig/iptables

如何操作该配置呢?

vim /etc/sysconfig/iptables

然后进去修改即可,修改完了怎么办?这里很多人会想到/etc/rc.d/init.d/iptables save指令,但是一旦你这么干了你刚才的修改内容就白做了。。。

具体方法是:

只修改/etc/sysconfig/iptables 使其生效的办法是修改好后先service iptables restart,然后才调用/etc/rc.d/init.d/iptables save,

因为/etc/rc.d/init.d/iptables save会在iptables服务启动时重新加载,要是在重启之前直接先调用了/etc/rc.d/init.d/iptables save那么你

的/etc/sysconfig/iptables 配置就回滚到上次启动服务的配置了,这点必须注意!!!

2.下面介绍一些指令用法(主要还是man iptables看下相关资料才行)

-A:指定链名

-p:指定协议类型

-d:指定目标地址

--dport:指定目标端口(destination port 目的端口)

--sport:指定源端口(source port 源端口)

-j:指定动作类型

3.如果我不像修改文件直接打命令可以吗,当然没问题,步骤如下:

例如我给SSH加放行的语句:

添加input记录: iptables -A INPUT -p tcp --dport 22 -j ACCEPT

添加output记录: iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT

最后注意需要再执行一下 /etc/init.d/iptables save,这样这两条语句就保存到刚才那个/etc/sysconfig/iptables 文件中了。

4.接下来说明一下步骤,如果机器不在我身边,我只能SSH进去做iptables规则,那么我必须注意每一步,千万别搞错了,否则就SSH链接不上都有可能!

禁止ssh 远程登录,从其它计算机上禁止使用 ssh 上使用 192.168.62.1 只允许在
ACCEPT -j 22 --dport tcp -p 192.168.62.1 -s INPUT -A #iptables
DROP -j 22 --dport tcp -p INPUT -A #iptables禁止代理端口
REJECT -j 3128 --dport tcp -p INPUT -A #iptables端口 icmpicmpicmpicmp 禁止我的主机 ping 外,禁止其它人 192.168.62.1 除
ACCEPT -j echo-request --icmp-type icmp -m icmp -p 192.168.62.1/32 -s eth0 -i INPUT -A #iptables
?DROP j – echo-request --icmp-type icmp -p eth0 -i INPUT -A #iptables或
ACCEPT -j 8 --icmp-type icmp -m icmp -p 192.168.62.1/32 -s eth0 -i INPUT -A #iptables
DROP -j 8 --icmp-type icmp -m icmp -p eth0 -i INPUT -A #iptables类型 ICMP 查看 --help icmp --protocol iptables 注:可以用
? 还有没有其它办法实现端口 QQQQQQQQ 禁止
REJECT -j 8000 --dport udp -p FORWARD -D #iptables强制访问指定的站点
3128 --to-ports上网 NATNATNATNAT 通过上网 NATNATNATNAT 典型连接外 eth0 , eth1 、 eth0 的计算机同时也是局域网的网关,假定该机有两块网卡 NAT 一般做为
192.168.62.10 为 IP 连接局域网, eth1 ; 202.96.134.134 为 IP 网,转发功能 ip 先在内核里打开 1.
/proc/sys/net/ipv4/ip_forward > 1 #echo
nat 所要做的 internet 使局域网用户能访问 2.?
--to?202.96.134.134 SNAT -j eth0 -o tcp -p POSTROUTING -A nat -t #iptables,则使用以下规则: IP 是动态 IP 如果上网的
MASQUERADE -j 192.168.62.0/24 -s eth0 -o POSTROUTING -A nat -t #iptables,则使用以下规则: IP 是动态 IP 上网,且公网 ADSL 如果是通过
MASQUERADE -j 192.168.62.0/24 -s ppp0 -o POSTROUTING -A nat -t #iptables
nat 主机所要做的 web 用户可以访问局域网内 internet 使 3.
--to-destination DNAT -j 80 --dport 202.96.134.134 -d tcp -p PREROUTING -A nat -t #iptables
192.168.62.10
IP 设为防火墙的 DNS 注:局域网内的客户端需将默认网关、共享上网 NATNATNATNAT 在我们的网络机房实现使用该代理的权限 (192.168.62.111) ,只授予教师机 192.168.60.6(4480) 上层代理: 工作环境的方式上网 NAT 代理上网,而是使用 squid 目标:不使用方法:或其它代理服务 squid 的 (192.168.62.111) 确保停止教师机 1)。测试在当 192.168.60.6(4480) ,浏览器代理设置为 192.168.62.111 均指向 DNS 客户端网关、 2)前情况下能否上网规则: iptables 上添加如下 (192.168.62.111) 在教师机 3)
--to-source SNAT -j 4480 --dport 192.168.60.6/32 -d tcp -p POSTROUTING -A nat -t #iptables
192.168.62.111:10000-30000将其源地 , 在经过防火墙路由后 , 包 TCP 的 4480 目的端口为 、 192.168.60.6 对于目的地为 : 解释间的某个端口。 10000-30000 ,端口转换为 192.168.62.111 址转换为客户端测试能否上网 4)规则的保存与恢复 IPIPIPIP)自动装载 /etc/rc.d/init.d/iptables 下的脚本( rc.d 把规则保存到文件中,再由目录 iptables-save来保存规则。一般用 iptables-save 使用命令
/etc/sysconfig/iptables > iptables-save, /etc/sysconfig/iptables 生成保存规则的文件也可以用
save iptables service中。 /etc/sysconfig/iptables 它能把规则自动保存在。 从而就自动恢复了规则 , 调用这个文件 iptables-restore 下的脚本将用命令 rc.d , 当计算机启动时指令语法 iptablesiptablesiptablesiptables
target/jump] [-j [match] command table] [-t iptables指定规则表 table]table]table]table] [-t[-t[-t[-t则一 , 当未指定规则表时 , filter 和 mangle 、 nat : 分别是 , 内建的规则表有三个 , 参数用来 -t。个规则表的功能如下: filter 律视为是、 两个规则链,主要功能为进行一对一 POSTROUTING 和 PREROUTING :此规则表拥有 nat请不要做 , 这个规则表除了作网址转换外 , ) DNAT 、 SNAT ( 多对多等网址转换工作 、 一对多其它用途。除了进 。 三个规则链 POSTROUTING 和 FORWARD 、 PREROUTING 此规则表拥有 : mangle)或者是 TOS 、 TTL 行网址转换工作会改写封包外,在某些特殊应用可能也必须去改写封包(规 mangle 这时就必须将这些工作定义在 , ) 以进行后续的过滤 , 将封包作记号 ( MARK 设定的用法。 mangle 则表中,由于使用率不高,我们不打算在这里讨论这个 , 三个规则链 OUTPUT 和 FORWARD 、 INPUT 拥有 , 这个规则表是默认规则表 : filter, ) REJECT 或 ACCEPT 、 LOG 、 DROP : 例如 ( 规则表顾名思义是用来进行封包过滤的处理动作我们会将基本规则都建立在此规则表中。常用命令列表: commandcommandcommandcommand
--append -A, 命令
... INPUT -A iptables 范例新增规则到某个规则链中,该规则将会成为规则链中的最后一条规则。 说明
--delete -D, 命令
DROP -j 80 --dport INPUT -D iptables 范例
1 INPUT -D iptables从某个规则链中删除一条规则,可以输入完整规则,或直接指定规则编号加以删除。 说明
--replace -R, 命令
DROP -j 192.168.0.1 -s 1 INPUT -R iptables 范例取代现行规则,规则被取代后并不会改变顺序。 说明
--insert -I, 命令
ACCEPT -j 80 --dport 1 INPUT -I iptables 范例插入一条规则,原本该位置上的规则将会往后移动一个顺位。 说明
--list -L, 命令
INPUT -L iptables 1 范例列出某规则链中的所有规则。 说明
-L nat -t iptables 2 范例表所有链中的所有规则。 nat 列出 说明
--flush -F, 命令
INPUT -F iptables 范例链的所有规则。 INPUT 表中 filter 删除 说明
--zero -Z, 命令
INPUT -Z iptables 范例是过滤阻断式攻击不可或 , 封包计数器是用来计算同一封包出现次数 。 将封包计数器归零 说明缺的工具。
--new-chain -N, 命令
allowed -N iptables 范例定义新的规则链。 说明
--delete-chain -X, 命令
allowed -X iptables 范例删除某个规则链。 说明
--policy -P, 命令
DROP INPUT -P iptables 范例默认的处理方式。 也就是未符合过滤条件之封包, 定义过滤政策。 说明
--rename-chain -E, 命令
disallowed allowed -E iptables 范例自定义规则链的名称。 修改某 说明常用封包匹配参数 [match][match][match][match]
--protocol -p, 参数
tcp -p INPUT -A iptables 范例运算符进行反向匹配,例如: ! 匹配通讯协议类型是否相符,可以使用 说明
!tcp -p等。 ... icmp 、 udp 以外的其它类型,如 tcp 意思是指除关键词,例如: all 如果要匹配所有类型,则可以使用
all -p
--source --src, -s, 参数
192.168.1.1 -s INPUT -A iptables 范例, 子网掩码 ,可以匹配单机或网络,匹配网络时请用数字来表示 IP 用来匹配封包的来源 说明例如:
192.168.0.0/24 -s运算符进行反向匹配,例如: ! 时可以使用 IP 匹配。 !192.168.0.0/24 -s
--destination --dst, -d, 参数
192.168.1.1 -d INPUT -A iptables 范例,设定方式同上。 IP 用来匹配封包的目的地 说明
--in-interface -i, 参数
eth0 -i INPUT -A iptables 范例来做大范围匹配,例如: + 用来匹配封包是从哪块网卡进入,可以使用通配字符 说明
eth+ -i网卡 ethernet 表示所有的运算符进行反向匹配,例如: ! 也可以使用
!eth0 -i
--out-interface -o, 参数
eth0 -o FORWARD -A iptables 范例块网卡送出,设定方式同上。 用来匹配封包要从哪 说明
--source-port --sport, 参数
22 --sport tcp -p INPUT -A iptables 范例用来匹配封包的源端口,可以匹配单一端口,或是一个范围,例如: 说明
22:80 --sport端口之间都算是符合条件,如果要匹配不连续的多个端口,则必须使用 80 到 22 表示从运算符进行反向匹配。 ! 参数,详见后文。匹配端口号时,可以使用 --multiport
--destination-port --dport, 参数
22 --dport tcp -p INPUT -A iptables 范例用来匹配封包的目的地端口号,设定方式同上 说明
--tcp-flags 参数
SYN SYN,FIN,ACK --tcp-flags tcp -p iptables 范例第二 , 匹配的标志 第一个部分列举出想 , 参数分为两个部分 , 封包的状态标志 TCP 说明匹配
SYN : 状态标志包括 TCP 。 未被列举的标志必须是空的 , 部分则列举前述标志中哪些有被设置等 ) 强迫推送 ( PSH 、 ) 紧急 ( URG 、 ) 重设 ( RST 、 ) 结束 ( FIN 、 ) 应答 ( ACK 、 ) (同步进行匹配。匹配标志时,可 NONE 和 ALL 均可使用于参数中,除此之外还可以使用关键词运算符行反向匹配。 ! 以使用
--syn 参数
--syn tcp -p iptables 范例的初 TCP 位关闭的分组,即 FIN 与 ACK 位被打开,而 SYN 通信协议中, TCP 用来表示 说明, 运算符! 的作用完全相同,如果使用 SYN SYN,FIN,ACK --tcp-flags tcp -p iptables 始连接,与匹配非要求连接封包。 可用来
--source-port multiport -m 参数
22,53,80,110 --source-port multiport -m tcp -p INPUT -A iptables 范例运算符进行反 ! 可以使用 , 个端口 15 一次最多可以匹配 , 说明用来匹配不连续的多个源端口向匹配。
--destination-port multiport -m 参数
22,53,80,110 --destination-port multiport -m tcp -p INPUT -A iptables 范例匹配不连续的多个目的地端口号,设定方式同上 说明用来
--port multiport -m 参数
22,53,80,110 --port multiport -m tcp -p INPUT -A iptables 范例在 : 这个参数比较特殊,用来匹配源端口和目的端口号相同的封包,设定方式同上。注意 说明,这种封包并不算符合条件。 110 目的地端口号为 80 本范例中,如果来源端口号为
--icmp-type 参数
8 --icmp-type icmp -p INPUT -A iptables 范例
icmp -p iptables 请打 。 匹配 可以使用代码或数字编号来进行 , 的类型编号 ICMP 说明用来匹配来查看有哪些代码可用。 --help
--limit limit -m 参数
3/hour --limit limit -m INPUT -A iptables 范例匹配:每小时平均流量是否超 用来匹配某段时间内封包的平均流量,上面的例子是用来 说明除了每小时平均次外,也可以每秒钟、每分钟或每天平均一次,默认值为 个封包。 3 过一次包数量的匹配外,设定 除了进行封 。 /day 、 /minute 、 /second 每小时平均一次,参数如后:这个参数也会在条件达成时,暂停封包的匹配动作,以避免因骇客使用洪水攻击法,导致服务被阻断。
--limit-burst 参数
5 --limit-burst limit -m INPUT -A iptables 范例
5 用来匹配瞬间大量封包的数量,上面的例子是用来匹配一次同时涌入的封包是否超过 说明个(这是默认值),超过此上限的封包将被直接丢弃。使用效果同上。
--mac-source mac -m 参数
00:00:00:00:00:01 --mac-source mac -m INPUT -A iptables 范例和 OUTPUT 用来匹配封包来源网络接口的硬件地址,这个参数不能用在 说明通 ARP 卡后,才能由网卡驱动程序透过 规则链上,这是因为封包要送到网 POSTROUTING并不知道封包会送到哪个 , 在进行封包匹配时 iptables 所以 , 地址 MAC 讯协议查出目的地的网络接口去。
--mark 参数
1 --mark mark -m INPUT -A mangle -t iptables 范例处理 MARK 匹配成功时,我们可以透过 用来匹配封包是否被表示某个号码,当封包被 说明。 4294967296 动作,将该封包标示一个号码,号码最大不可以超过
--uid-owner owner -m 参数范例
500 --uid-owner owner -m OUTPUT -A iptables
root 这样可以避免服务器使用 , 是否为某特定使用者所产生的 , 用来匹配来自本机的封包 说明匹配出来自其它 可惜这个功能无法 。 可以降低系统被骇的损失 , 或其它身分将敏感数据传送出主机的封包。
--gid-owner owner -m 参数
0 --gid-owner owner -m OUTPUT -A iptables 范例用来匹配来自本机的封包,是否为某特定使用者群组所产生的,使用时机同上。 说明
--pid-owner owner -m 参数范例
78 --pid-owner owner -m OUTPUT -A iptables用来匹配来自本机的封包,是否为某特定进程所产生的,使用时机同上。 说明
--sid-owner owner -m 参数范例
100 --sid-owner owner -m OUTPUT -A iptables。 使用时机同上 , 的响应封包 ) ID Session ( 连接 是否为某特定 , 用来匹配来自本机的封包 说明
--state state -m 参数范例
RELATED,ESTABLISHED --state state -m INPUT -A iptables和 NEW 、 ESTABLISHED 、 INVALID 连接状态共有四种: 用来匹配连接状态, 说明。 RELATED)无法辨识或编号不正确。 ID Session 表示该封包的连接编号( INVALID表示该封包属于某个已经建立的连接。 ESTABLISHED表示该封包想要起始一个连接(重设连接或将连接重导向)。 NEW连接 FTP-DATA : 例如 。 所建立的新连接 , 表示该封包是属于某个已经建立的连接 RELATED连接。 FTP 必定是源自某个常用的处理动作: target/jump]target/jump]target/jump]target/jump] [-j[-j[-j[-j、 DROP 、 REJECT 、 ACCEPT 参数用来指定要进行的处理动作,常用的处理动作包括: -j, MARK 、 RETURN 、 QUEUE 、 MIRROR 、 SNAT 、 DNAT 、 LOG 、 MASQUERADE 、 REDIRECT分别说明如下:直接跳往下一个规则链 , 将不再匹配其它规则 , 进行完此处理动作后 , 将封包放行 : ACCEPT)。 natostrouting (
ICMP 拦阻该封包,并传送封包通知对方,可以传送的封包有几个选择: : REJECT进行完此 , ) 连接 这个封包会要求对方关闭 ( tcp-reset 或是 echo-reply ICMP 、 port-unreachable范例如下: 处理动作后,将不再匹配其它规则,直接中断过滤程序。
tcp-reset --reject-with REJECT -j 22 --dport TCP -p FORWARD -A iptables。 直接中断过滤程序 , 将不再匹配其它规则 , 进行完此处理动作后 , 丢弃封包不予处理 : DROP),进行完此处理动作后,将会继续匹配 PNAT 将封包重新导向到另一个端口( : REDIRECT服务器。例如: web 这个功能可以用来实现透明代理或用来保护 其它规则。
8080 --to-ports REDIRECT -j 80 --dport tcp -p PREROUTING -A nat -t iptables进行完此 , 对应的范围 port 可以指定 , IP NIC 为防火墙 IP 改写封包来源 : MASQUERADE当 , 略有不同 SNAT )。这个功能与 manglepostrouting 链( 处理动作后,直接跳往下一个规则
P I 号接连时, 会从网卡直接读取,当使用拨 IP , IP 伪装时,不需指定要伪装成哪个 IP 进行: 特别有用。范例如下 MASQUERADE 服务器指派的,这个时候 DHCP 公司的 ISP 通常是由
1024-31000 --to-ports MASQUERADE -j TCP -p POSTROUTING -A nat -t iptables配置文件,进行 /etc/syslog.conf 中,详细位置请查阅 /var/log 将封包相关讯息纪录在 : LOG完此处理动作后,将会继续匹配其规则。例如:
packets" "INPUT --log-prefix LOG -j tcp -p INPUT -A iptables进行完此处 , 对应的范围 port 可以指定 , 范围 IP 或 IP 为某特定 IP 改写封包来源 : SNAT)。范例如下: mangleostrouting 理动作后,将直接跳往下一个规则(
SNAT -j eth0 -o tcp -p POSTROUTING -A nat -t iptables
--to-source?194.236.50.155-194.236.50.160:1024-32000进行完此 , 对应的范围 port 可以指定 , 范围 IP 或 IP 为某特定 IP 改写封包目的地 : DNAT)。范例如下: filter:forward 或 filter:input 处理动作后,将会直接跳往下一个规则链(
--to-destination DNAT -j 80 --dport 15.45.23.67 -d tcp -p PREROUTING -A nat -t iptables
192.168.1.1-192.168.1.10:80-100进行完此处理动 , 将封包送回 , 对调后 IP 与目的地 IP 也就是将来源 , 镜射封包 : MIRROR作后,将会中断过滤程序。中断过滤程序,将封包放入队列,交给其它程序处理。通过自行开发的处理程序, : QUEUE可以进行其它应用,例如:计算连接费用等。如果把自定义规则链看 , 返回主规则链继续过滤 , 结束在目前规则链中的过滤程序 : RETURN成是一个子程序,那么这个动作,就相当于提前结束子程序并返回到主程序中。, 进行完此处理动作后 , 以便提供作为后续过滤的条件判断依据 , 将封包标上某个代号 : MARK将会继续匹配其它规则。范例如下:
2 --set-mark MARK -j 22 --dport tcp -p PREROUTING -A mangle -t iptables实例 iptablesiptablesiptablesiptables单个规则实例
-F? iptables的所有链的规则都清空 TABLE FILTRE 是清除的意思,作用就是把 -F #
ACCEPT -j NEW,ESTABLISHED,RELATED --state state -m 172.20.20.1/32 -s INPUT -A iptables是 的主机,状态分别 172.20.20.1 链匹配源地址是 INPUT 表的 FILTER 在 #的都放行。 NEW,ESTABLISHED,RELATED
multiport -m tcp -p NEW,ESTABLISHED --state state -m 172.20.20.1/32 -s INPUT -A iptables
ACCEPT -j 123,110 --dport模块的作用就是可以连续匹配多各不相邻的端口号。完 ,multiport 指定模块 -m 指定协议, -p #, 的 ESTABLISHED,RELATED NEW, 的主机,状态分别是 172.20.20.1 整的意思就是源地址是的数据包都可以通过。 110 和 123 协议,目的端口分别为 TCP
multiport -m tcp -p NEW,ESTABLISHED --state state -m 172.20.22.0/24 -s INPUT -A iptables
ACCEPT -j 123,110 --dport
DROP -j 123,110 --dport multiport -m tcp -p NEW --state state -m 0/0 -s INPUT -A iptables端口。 110 和 123 数据包都禁止访问我的 TCP 状态的的 NEW 的 0/0 这句意思为源地址是 #
-j 1230,110 --dport multiport -m tcp -p NEW --state state -m 172.20.89.0/24 ! -s INPUT -A iptables
DROP。 DROP 段的地址都 IP 这个 172.20.89.0 取反。就是除了 号的意思 " ! " #
ACCEPT -j 22 --dport tcp -p 192.168.6.99 -s 1 INPUT -R iptables链中的第一条规则 INPUT 替换
-vn INPUT -L filter -t iptables链的规则 INPUT 表 filter 以数字形式详细显示
IP-------------------------------------- #-------------------------------NAT里面完成的。请大家注意。 TABLE NAT 以下操作是在 #
-F nat -t iptables
172.20.11.1:800 --to DNAT -j 90 --dport tcp -p 192.168.102.55 -d PREROUTING -A nat -t iptables目的地 , 的路由前处理 TABLE NAT 完整的意思是在 。 指定在路由前做的 PREROUTING #-A那里去。 172.20.11.1:800 处理,给他转向到 DNAT 的我们做 90 目的端口为 的 192.168.102.55 为
192.168.102.55 --to SNAT -j 172.20.11.1 -d POSTROUTING -A nat -t iptables
172.20.11.1 凡是目的地为 , 的路由后处理 TABLE NAT 意思为在 。 路由后 POSTROUTING #-A。 192.168.102.55 转换,把源地址改写成 SNAT 的,我们都给他做
DROP -j eth1 -i 192.168.20.0/255.255.255.0 -d INPUT -A iptables
DROP -j eth1 -i 192.168.20.0/255.255.255.0 -s INPUT -A iptables
DROP -j eth1 -o 192.168.20.0/255.255.255.0 -d OUTPUT -A iptables
DROP -j eth1 -o 192.168.20.0/255.255.255.0 -s OUTPUT -A iptables上述规则用来 , 则是内部网的网络号 192.168.20.0 而 , 相连 Internet 是一个与外部 eth1 , 上例中 #
IP 应该是公共 ip 的包的 eth1 欺骗,因为出入 IP 防止
DROP -j eth0 -i 255.255.255.255 -s INPUT -A iptables
DROP -j eth0 -i 224.0.0.0/224.0.0.0 -s INPUT -A iptables
DROP -j eth0 -i 0.0.0.0 -d INPUT -A iptables代理服务器进入局域网: IP 防止广播包从 #
DROP -j 5000 --sport tcp -m tcp -p INPUT -A iptables
DROP -j 5000 --sport udp -m udp -p INPUT -A iptables
DROP -j 5000 --dport tcp -m tcp -p OUTPUT -A iptables
DROP -j 5000 --dport udp -m udp -p OUTPUT -A iptables
5000 屏蔽端口 #
DROP -j 3306 --dport tcp -m tcp -p eth1 -i 211.148.130.129 -s INPUT -A iptables
ACCEPT -j 3306 --dport tcp -m tcp -p eth0 -i 192.168.20.0/255.255.255.0 -s INPUT -A iptables
ACCEPT -j 3306 --dport tcp -m tcp -p eth1 -i 211.148.130.128/255.255.255.240 -s INPUT -A iptables
DROP -j 3306 --dport tcp -m tcp -p INPUT -A iptables端口) 3306 服务器(就是 MySQL 网的用户访问 Internet 防止 #
tcp-reset --reject-with REJECT -j 22 --dport TCP -p FORWARD -A iptables指定的信息,从而可以很好 --reject-with ,但向发送该包的主机回复由 DROP 类似于 #REJECT,地隐藏防火墙的存在实例 iptablesiptablesiptablesiptables 的 wwwwwwwwwwww
#!/bin/bash
PATH=/sbin:/usr/sbin:/bin:/usr/bin export加载相关模块 #
iptable_nat modprobe
ip_nat_ftp modprobe
ip_nat_irc modprobe
ip_conntrack modprobe
ip_conntrack_ftp modprobe
ip_conntrack_irc modprobe
ipt_limit modprobe
>;/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 1 echo
>;/proc/sys/net/ipv4/conf/all/accept_source_route 0 echo
>;/proc/sys/net/ipv4/conf/all/accept_redirects 0 echo
>;/proc/sys/net/ipv4/icmp_ignore_bogus_error_responses 1 echo
>;/proc/sys/net/ipv4/conf/all/log_martians 1 echo
>;/proc/sys/net/ipv4/tcp_syncookies 1 echo
-F iptables
-X iptables
-Z iptables
traffic unlimited Allow - ?Loopback 允许本地回路 ##
ACCEPT -j lo -i INPUT -A iptables
ACCEPT -j lo -o OUTPUT -A iptables
Protection ?SYN-Flooding 洪水 SYN 防止 ##
syn-flood -N iptables
syn-flood -j --syn tcp -p ppp0 -i INPUT -A iptables
RETURN -j 4 --limit-burst 1/s --limit limit -m syn-flood -A iptables
DROP -j syn-flood -A iptables
packets SYN are connections TCP new that sure ?Make 标记的包 SYN 确保新连接是设置了 ##
DROP -j NEW --state state -m --syn ! tcp -p eth0 -i INPUT -A iptables的规则 HTTP 允许 ##
-j ESTABLISHED,RELATED --state state -m 80 --sport 0/0 -s tcp -p ppp0 -i INPUT -A iptables
ACCEPT
-j ESTABLISHED,RELATED --state state -m 443 --sport 0/0 -s tcp -p ppp0 -i INPUT -A iptables
ACCEPT
ACCEPT -j 80 --dport 0/0 -d tcp -p ppp0 -i INPUT -A iptables
ACCEPT -j 443 --dport 0/0 -d tcp -p ppp0 -i INPUT -A iptables的规则 DNS 允许 ##
ACCEPT -j ESTABLISHED --state state -m 53 --sport 0/0 -s udp -p ppp0 -i INPUT -A iptables
ACCEPT -j 53 --dport 0/0 -d udp -p ppp0 -i INPUT -A iptables
limit packets ?IP 包流量限制 IP ##
ACCEPT -j 100 --limit-burst 100/s --limit limit -m -f INPUT -A iptables
DROP -j icmp -p eth0 -i INPUT -A iptables
SSH 允许 ##
ACCEPT -j 22 --dport ip1/32 -s tcp -p INPUT -A iptables
ACCEPT -j 22 --dport ip2/32 -s tcp -p INPUT -A iptables
allowed not else ?Anything 其它情况不允许 ##
DROP -j eth0 -i INPUT -A iptables一个包过滤防火墙实例等模块 time string 加载了 redhat9 环境:
ppp0 ── 接外网 eth0
192.168.0.0/24 ── 接内网 eth1
#!/bin/sh

ipt_MASQUERADE modprobe
ip_conntrack_ftp modprobe
ip_nat_ftp modprobe
-F iptables
-F nat -t iptables
-X iptables
-X nat -t iptables
################################### 键 ###########################INPUT
DROP INPUT -P iptables
ACCEPT -j ESTABLISHED,RELATED --state state -m INPUT -A iptables
ACCEPT -j 110,80,25 --dports multiport -m tcp -p INPUT -A iptables
ACCEPT -j 139 --dport 192.168.0.0/24 -s tcp -p INPUT -A iptables连接 samba,smtp,pop3, 允许内网 #
ACCEPT -j 53 --dports multiport -m udp -p eth1 -i INPUT -A iptables连接 dns 允许 #
ACCEPT -j 1723 --dport tcp -p INPUT -A iptables
ACCEPT -j gre -p INPUT -A iptables连接 vpn 允许外网 #
ACCEPT -j ESTABLISHED,RELATED --state state -m tcp -p 192.186.0.0/24 -s INPUT -A iptables
DROP -j 15 --connlimit-above connlimit -m --syn tcp -p ppp0 -i INPUT -A iptables超过的丢弃, 个初始连接 15 那么可以允许最多, 太多连接进来 DoS 为了防止 #
DROP -j 15 --connlimit-above connlimit -m --syn tcp -p 192.186.0.0/24 -s INPUT -A iptables超过的丢弃, 个初始连接 15 那么可以允许最多, 太多连接进来 DoS 为了防止 #
IN: packet "ICMP --log-prefix INFO --log-level LOG -j 3/s --limit limit -m icmp -p INPUT -A iptables
"
DROP -j icmp -p INPUT -A iptables不通 -ping 通信 icmp 禁止 #
MASQUERADE -j 192.168.0.0/24 -s ppp0 -o POSTROUTING -A nat -t iptables内网转发 #
syn-flood -N iptables
syn-flood -j --syn tcp -p INPUT -A iptables
RETURN -j 6 --limit-burst 3/s --limit limit -m tcp -p syn-flood -I iptables
REJECT -j syn-flood -A iptables轻量 攻击 SYN 防止 #
########################### 链 #######################FORWARD
DROP FORWARD -P iptables
ACCEPT -j 80,110,21,25,1723 --dports multiport -m 192.168.0.0/24 -s tcp -p FORWARD -A iptables
ACCEPT -j 53 --dport 192.168.0.0/24 -s udp -p FORWARD -A iptables
ACCEPT -j 192.168.0.0/24 -s gre -p FORWARD -A iptables
ACCEPT -j 192.168.0.0/24 -s icmp -p FORWARD -A iptables网络连接外网 vpn 客户走 vpn 允许 #
ACCEPT -j ESTABLISHED,RELATED --state state -m FORWARD -A iptables
8:15 --timestart time -m "tencent" --string string -m 53 --dport udp -p FORWARD -I iptables
DROP -j Mon,Tue,Wed,Thu,Fri,Sat --days 12:30 --timestop通信 qq 禁止 8:00-12:30 星期一到星期六的 #
8:15 --timestart time -m "TENCENT" --string string -m 53 --dport udp -p FORWARD -I iptables
DROP -j Mon,Tue,Wed,Thu,Fri,Sat --days 12:30 --timestop通信 qq 禁止 8:00-12:30 星期一到星期六的 #
13:30 --timestart time -m "tencent" --string string -m 53 --dport udp -p FORWARD -I iptables
DROP -j Mon,Tue,Wed,Thu,Fri,Sat --days 20:30 --timestop
13:30 --timestart time -m "TENCENT" --string string -m 53 --dport udp -p FORWARD -I iptables
DROP -j Mon,Tue,Wed,Thu,Fri,Sat --days 20:30 --timestop通信 QQ 禁止 13:30-20:30 星期一到星期六的 #
8:15 --timestart time -m "qq.com" --string string -m 192.168.0.0/24 -s FORWARD -I iptables
DROP -j Mon,Tue,Wed,Thu,Fri,Sat --days 12:30 --timestop网页 qq 禁止 8:00-12:30 星期一到星期六的 #
13:00 --timestart time -m "qq.com" --string string -m 192.168.0.0/24 -s FORWARD -I iptables
DROP -j Mon,Tue,Wed,Thu,Fri,Sat --days 20:30 --timestop网页 QQ 禁止 13:30-20:30 星期一到星期六的 #
DROP -j "ay2000.net" --string string -m 192.168.0.0/24 -s FORWARD -I iptables
DROP -j " 宽频影院 " --string string -m 192.168.0.0/24 -d FORWARD -I iptables
DROP -j " 色情 " --string string -m 192.168.0.0/24 -s FORWARD -I iptables
DROP -j " 广告 " --string string -m 80 --sport tcp -p FORWARD -I iptables不是很理想 !但中文 ,宽频影院,色情,广告网页连接 ay2000.net 禁止 #
DROP -j --bit --kazaa --edk ipp2p -m FORWARD -A iptables
DROP -j --ares ipp2p -m tcp -p FORWARD -A iptables
DROP -j --kazaa ipp2p -m udp -p FORWARD -A iptables连接 BT 禁止 #
--connlimit-mask 15 --connlimit-above connlimit -m 80 --dport --syn tcp -p FORWARD -A iptables
DROP -j 24端口转发 80 个 15 同时 ip 只允许每组 #
#######################################################################
&>/dev/null net.ipv4.ip_forward=1 -w sysctl打开转发 #
#######################################################################
&>/dev/null net.ipv4.tcp_syncookies=1 -w sysctl攻击) DOS (轻量级预防 syncookie 打开 #
&>/dev/null net.ipv4.netfilter.ip_conntrack_tcp_timeout_established=3800 -w sysctl秒(此选项可以大大降低连接数) 3800 连接痴呆时长为 TCP 设置默认 #
&>/dev/null net.ipv4.ip_conntrack_max=300000 -w sysctl需要 connection 版本来,每个 iptables (这个根据你的内存和 30W 设置支持最大连接树为 #多个字节) 300
#######################################################################
ACCEPT -j 192.168.0.50 -s INPUT -I iptables
ACCEPT -j 192.168.0.50 -s FORWARD -I iptables是我的机子,全部放行! #192.168.0.50
squid+iptablessquid+iptablessquid+iptablessquid+iptables实现网关防火墙 squid+iptables ] 原创 [
10:40:01 2007-05-27 发表于: :jackylau 作者 http://www.chinaunix.net服务器讨论区】【关闭】 Proxy 【发表评论】【查看原文】【服务器,内部一 DHCP 、 FTP 、 pop3) 、 smtp 、 web 开启 MAIL( 需求说明:此服务器用作网关、, 服务器 ssh 为了不让无意者轻易看出此服务器开启了, 服务 dns 对外提供 (192.168.0.254) 台机器
60080 的端口改为 proxy 另把 2018. 端口改为 ssh 故把外网口 eth0:218.28.20.253,内网口 eth1:192.168.0.1/24,
) 部份如下 /etc/squid/squid.conf( init.d]$cat [jackylau@proxyserver
192.168.0.1:60080 http_port
80 httpd_accel_port
virtual httpd_accel_host
on httpd_accel_with_proxy
on httpd_accel_uses_host_header
192.168.0.0/24 src allow_lan acl
allow_lan allow http_access
proxyserver visible_hostname
firewall cat init.d]$ [jackylau@proxyserver
#!/bin/sh
squidipt@yahoo.com.cn; jackylau Author: #
92 08 2345 chkconfig: #
firewall description: #
2005.08.02 on Time #
killproc #
ENV Set #
INET_IP="218.28.20.253"
INET_IFACE="eth0"
LAN_IP="192.168.0.1"
LAN_IP_RANGE="192.168.0.0/24"
LAN_BROADCAST_ADDRESS="192.168.0.255"
LAN_IFACE="eth1"
LO_IFACE="lo"
LO_IP="127.0.0.1"
IPTABLES="/sbin/iptables"
start(){
firewall:" $"Starting -n echo
-a /sbin/depmod
ip_tables /sbin/modprobe
ip_conntrack /sbin/modprobe
iptable_filter /sbin/modprobe
iptable_mangle /sbin/modprobe
iptable_nat /sbin/modprobe
ipt_LOG /sbin/modprobe
ipt_limit /sbin/modprobe
ipt_state /sbin/modprobe
/proc/sys/net/ipv4/ip_forward >; "1" echo
policies Set #
DROP INPUT -P $IPTABLES
DROP OUTPUT -P $IPTABLES
DROP FORWARD -P $IPTABLES
icmp_packets and allowed bad_tcp_packets, Add #
bad_tcp_packets -N $IPTABLES
tcp_packets -N $IPTABLES
udp_packets -N $IPTABLES
allowed -N $IPTABLES
icmp_packets -N $IPTABLES
bad_tcp_packets #
INFO --log-level LOG -j NEW --state state -m --syn ! tcp -p bad_tcp_packets -A $IPTABLES
syn:" not "New --log-prefix
DROP -j NEW --state state -m --syn ! TCP -p bad_tcp_packets -A $IPTABLES
allowed #
ACCEPT -j --syn TCP -p allowed -A $IPTABLES
ACCEPT -j ESTABLISHED,RELATED --state state -m TCP -p allowed -A $IPTABLES
DROP -j TCP -p allowed -A $IPTABLES
ACCEPT -j $LAN_BROADCAST_ADDRESS -d $LAN_IFACE -i ALL -p INPUT -A $IPTABLES
rules TCP #
allowed -j 20 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
allowed -j 21 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
allowed -j 25 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
allowed -j 80 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
allowed -j 110 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
allowed -j 2018 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
rules UDP #
ACCEPT -j 67 --destination-port 0/0 -s UDP -p udp_packets -A $IPTABLES
rules ICMP #
ACCEPT -j 8 --icmp-type 0/0 -s ICMP -p icmp_packets -A $IPTABLES
ACCEPT -j 11 --icmp-type 0/0 -s ICMP -p icmp_packets -A $IPTABLES
chain INPUT #
bad_tcp_packets -j tcp -p INPUT -A $IPTABLES
ACCEPT -j $LAN_IP_RANGE -s $LAN_IFACE -i ALL -p INPUT -A $IPTABLES
ACCEPT -j $LO_IP -s $LO_IFACE -i ALL -p INPUT -A $IPTABLES
ACCEPT -j $LAN_IP -s $LO_IFACE -i ALL -p INPUT -A $IPTABLES
ACCEPT -j $INET_IP -s $LO_IFACE -i ALL -p INPUT -A $IPTABLES
-j ESTABLISHED,RELATED --state state -m $INET_IP -d ALL -p INPUT -A $IPTABLES
ACCEPT
tcp_packets -j $INET_IFACE -i TCP -p INPUT -A $IPTABLES
udp_packets -j $INET_IFACE -i UDP -p INPUT -A $IPTABLES
icmp_packets -j $INET_IFACE -i ICMP -p INPUT -A $IPTABLES
DEBUG --log-level LOG -j 3 --limit-burst 3/minute --limit limit -m INPUT -A $IPTABLES
" died: packet INPUT "IPT --log-prefix
chain FORWARD #
bad_tcp_packets -j tcp -p FORWARD -A $IPTABLES
ACCEPT -j $LAN_IFACE -i FORWARD -A $IPTABLES
ACCEPT -j ESTABLISHED,RELATED --state state -m FORWARD -A $IPTABLES
DEBUG --log-level LOG -j 3 --limit-burst 3/minute --limit limit -m FORWARD -A $IPTABLES
" died: packet FORWARD "IPT --log-prefix
chain OUTPUT #
bad_tcp_packets -j tcp -p OUTPUT -A $IPTABLES
ACCEPT -j $LO_IP -s ALL -p OUTPUT -A $IPTABLES
ACCEPT -j $LAN_IP -s ALL -p OUTPUT -A $IPTABLES
ACCEPT -j $INET_IP -s ALL -p OUTPUT -A $IPTABLES
DEBUG --log-level LOG -j 3 --limit-burst 3/minute --limit limit -m OUTPUT -A $IPTABLES
" died: packet OUTPUT "IPT --log-prefix
table SNAT #
$INET_IP --to-source SNAT -j $INET_IFACE -o POSTROUTING -A nat -t $IPTABLES
table DNAT #
--to-destination DNAT -j 53 -dport $INET_IP -d icmp ! -p PREROUTING -A nat -t $IPTABLES
192.168.0.254:53
REDIRECT #
-j 80 --dport $LAN_IP_RANGE -s tcp -p $LAN_IFACE -i PREROUTING -A nat -t $IPTABLES
60080 --to-ports REDIRECT
/var/lock/subsys/firewall touch
}
stop(){
firewall:" $"Stoping -n echo
"0">;/proc/sys/net/ipv4/ip_forward echo
ACCEPT INPUT -P $IPTABLES
ACCEPT FORWARD -P $IPTABLES
ACCEPT OUTPUT -P $IPTABLES
ACCEPT PREROUTING -P nat -t $IPTABLES
ACCEPT POSTROUTING -P nat -t $IPTABLES
ACCEPT OUTPUT -P nat -t $IPTABLES
ACCEPT PREROUTING -P mangle -t $IPTABLES
ACCEPT OUTPUT -P mangle -t $IPTABLES
-F $IPTABLES
-F nat -t $IPTABLES
-F mangle -t $IPTABLES
-X $IPTABLES
-X nat -t $IPTABLES
-X mangle -t $IPTABLES
/var/lock/subsys/firewall -f rm
}
status(){
clear
"-------------------------------------------------------------------" echo
-L $IPTABLES
"-------------------------------------------------------------------" echo
POSTROUTING -L nat -t $IPTABLES
"-------------------------------------------------------------------" echo
PREROUTING -L nat -t $IPTABLES
}
in "$1" case
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
[start|stop|restart|status]" "$0 echo
;;
esac
/etc/init.d/ firewall cp
/etc/init.d/firewall 700 chmod
firewall --add chkconfig脚本代码 rc.firewallrc.firewallrc.firewallrc.firewall
#!/bin/sh

iptables and 2.4.x Linux for script Firewall IP SIMPLE Initial - rc.firewall

Andreasson 2001?Oskar (C) Copyright

modify and/or it redistribute can you software; free is program This #
by published as License Public General GNU the of terms the under it #
License. the of 2 version Foundation; Software Free the #

useful, be will it that hope the in distributed is program This
of warranty implied the even without WARRANTY; ANY WITHOUT but #
the PURPOSE.?See PARTICULAR A FOR FITNESS or MERCHANTABILITY #
details. more for License Public General GNU #

License Public General GNU the of copy a received have should You
it downloaded you that site the from or program this with along #
Temple 59 Inc., Foundation, Software Free the to write not, if from; #
MA?02111-1307?USA Boston, 330, Suite Place, #

###########################################################################

. 配置选项 1.

. 相关变量设置 Internet 1.1

INET_IP="194.236.50.155"
INET_IFACE="eth0"
INET_BROADCAST="194.236.50.255"
##相关设置 DHCP 1.1.1
###相关设置 PPPoE 1.1.2

. 局域网相关变量设置 1.2
#地址 IP 防火墙连接局域网的 # LAN_IP="192.168.0.2"局域网地址 # LAN_IP_RANGE="192.168.0.0/16"防火墙连接局域网的网络接口 # LAN_IFACE="eth1"

. 非军事区相关变量设置 DMZ 1.3

. 本机相关变量设置 1.4
#本地接口名称 # LO_IFACE="lo"
IP 本地接口 # LO_IP="127.0.0.1"

. 路径设置 IPTables 1.5

IPTABLES="/usr/sbin/iptables"

. 其它配置 1.6

###########################################################################

. 要加载的模块 2.
###初始加载的模块

-a /sbin/depmod
##需加载的模块 2.1

ip_tables /sbin/modprobe
ip_conntrack /sbin/modprobe
iptable_filter /sbin/modprobe
iptable_mangle /sbin/modprobe
iptable_nat /sbin/modprobe
ipt_LOG /sbin/modprobe
ipt_limit /sbin/modprobe
ipt_state /sbin/modprobe
##不需加载的模块 2.2

ipt_owner #/sbin/modprobe
ipt_REJECT #/sbin/modprobe
ipt_MASQUERADE #/sbin/modprobe
ip_conntrack_ftp #/sbin/modprobe
ip_conntrack_irc #/sbin/modprobe
ip_nat_ftp #/sbin/modprobe
ip_nat_irc #/sbin/modprobe
###########################################################################

. 设置 /proc 3.
###配置 proc 需要的 3.1

/proc/sys/net/ipv4/ip_forward > "1" echo
##配置 proc 不需要的 3.2

/proc/sys/net/ipv4/conf/all/rp_filter > "1" #echo
/proc/sys/net/ipv4/conf/all/proxy_arp > "1" #echo
/proc/sys/net/ipv4/ip_dynaddr > "1" #echo
###########################################################################

. 建立规则 4.

######表 Filter 4.1 #

##建立策略 4.1.1

DROP INPUT -P $IPTABLES
DROP OUTPUT -P $IPTABLES
DROP FORWARD -P $IPTABLES

chains userspecified Create 创建自定义链 4.1.2

packets tcp bad for chain Create 包建立自定义链 tcp 为不可靠的

bad_tcp_packets -N $IPTABLES

UDP and TCP ICMP, for chains separate Create 协议建立自定义链 UDP 和 TCP ICMP, 分别为
traverse to

allowed -N $IPTABLES
tcp_packets -N $IPTABLES
udp_packets -N $IPTABLES
icmp_packets -N $IPTABLES

chains userspecified in content Create 在自定义链建立规则 4.1.3

chain bad_tcp_packets 链 bad_tcp_packets
##)的包头是否不正常或有没有其他问题,并进 packet incoming 这条链包含的规则检查进入包(是 位但又 SYN 没有设置 : 我们使用它只是为了过滤掉一些特殊的包 , 但事实上 。 行相应地处理包。这条链 TCP 状态的 NEW 但也被认为是 SYN/ACK 包,还有那些设置了 TCP 状态的 NEW可以用来检查所有可能的不一致的东西
-j NEW --state state -m SYN,ACK SYN,ACK --tcp-flags tcp -p bad_tcp_packets -A $IPTABLES
tcp-reset --reject-with REJECT
not "New --log-prefix LOG -j NEW --state state -m --syn ! tcp -p bad_tcp_packets -A $IPTABLES
syn:"
DROP -j NEW --state state -m --syn ! tcp -p bad_tcp_packets -A $IPTABLES

chain ?allowed 链 allowed

ACCEPT -j --syn TCP -p allowed -A $IPTABLES
ACCEPT -j ESTABLISHED,RELATED --state state -m TCP -p allowed -A $IPTABLES
DROP -j TCP -p allowed -A $IPTABLES

rules ?TCP 规则 TCP

allowed -j 21 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
allowed -j 22 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
allowed -j 80 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES
allowed -j 113 --dport 0/0 -s TCP -p tcp_packets -A $IPTABLES

ports ?UDP 端口 UDP

ACCEPT -j 53 --destination-port 0/0 -s UDP -p udp_packets -A #$IPTABLES
ACCEPT -j 123 --destination-port 0/0 -s UDP -p udp_packets -A #$IPTABLES
ACCEPT -j 2074 --destination-port 0/0 -s UDP -p udp_packets -A $IPTABLES
ACCEPT -j 4000 --destination-port 0/0 -s UDP -p udp_packets -A $IPTABLES
##下面的指令将阻止这些 , 你会遭遇洪水一样的广播信息 , 网络的话 Microsoft 如果网络中存在
lines These broadcasts. by swamped be will you Networks Microsoft ?In 记录. # 广播并在日志中
logs. the in up showing from them prevent will #

$INET_BROADCAST -d $INET_IFACE -i UDP -p udp_packets -A #$IPTABLES
DROP -j --destination-port?135:139

we If 下面的指令 , 就会很快把我们的日志塞满 , 请求的话 DHCP 如果有来自我们网络之外的
will logs our network, our of Outside the from requests DHCP get
logged. getting from them block will rule This well. as swamped be #

67:68 --destination-port 255.255.255.255 -d $INET_IFACE -i UDP -p udp_packets -A #$IPTABLES
DROP -j

rules ?ICMP 规则 #ICMP

ACCEPT -j 8 --icmp-type 0/0 -s ICMP -p icmp_packets -A $IPTABLES
ACCEPT -j 11 --icmp-type 0/0 -s ICMP -p icmp_packets -A $IPTABLES

chain ?INPUT 链 INPUT 4.1.4

want. don't we packets TCP ?Bad 包 TCP 排除不良

bad_tcp_packets -j tcp -p INPUT -A $IPTABLES

Internet the of part not networks special for ?Rules 网络部分的规则 internet 非

ACCEPT -j $LAN_IP_RANGE -s $LAN_IFACE -i ALL -p INPUT -A $IPTABLES
ACCEPT -j $LO_IP -s $LO_IFACE -i ALL -p INPUT -A $IPTABLES
ACCEPT -j $LAN_IP -s $LO_IFACE -i ALL -p INPUT -A $IPTABLES
ACCEPT -j $INET_IP -s $LO_IFACE -i ALL -p INPUT -A $IPTABLES

caught not are which LAN, from requests DHCP for rule ?Special 的特殊规则 DHCP 有关本地
properly
otherwise. #

ACCEPT -j 68 --sport 67 --dport $LAN_IFACE -i UDP -p INPUT -A $IPTABLES

internet. the from packets incoming for Rules 来自因特网的进入包的规则

-j ESTABLISHED,RELATED --state state -m $INET_IP -d ALL -p INPUT -A $IPTABLES
ACCEPT
tcp_packets -j $INET_IFACE -i TCP -p INPUT -A $IPTABLES
udp_packets -j $INET_IFACE -i UDP -p INPUT -A $IPTABLES
icmp_packets -j $INET_IFACE -i ICMP -p INPUT -A $IPTABLES
##下面的指令将丢弃这 , 你会遭遇洪水一样的多播信息 , 网络的话 Microsoft 如果防火墙外存在
of outside the on Network Microsoft a have you If 记录 # 些包,所以日志就不会被这些东西淹没
may you firewall, your
by flooded get not do we so them drop We Multicasts. by flooded get also #
logs #

DROP -j 224.0.0.0/8 -d $INET_IFACE -i INPUT -A #$IPTABLES

above. the match don't that packets weird Log 将不满足上述规则的形为怪异的包记录在案

DEBUG --log-level LOG -j 3 --limit-burst 3/minute --limit limit -m INPUT -A $IPTABLES
" died: packet INPUT "IPT --log-prefix

chain ?FORWARD 链 FORWARD 4.1.5

want don't we packets TCP ?Bad 包 TCP 排除不良

bad_tcp_packets -j tcp -p FORWARD -A $IPTABLES

forward to want actually we packets the ?Accept 包 TCP 接收想要转发的

ACCEPT -j $LAN_IFACE -i FORWARD -A $IPTABLES
ACCEPT -j ESTABLISHED,RELATED --state state -m FORWARD -A $IPTABLES

above. the match don't that packets weird ?Log 将不满足上述规则的形为怪异的包记录在案

DEBUG --log-level LOG -j 3 --limit-burst 3/minute --limit limit -m FORWARD -A $IPTABLES
" died: packet FORWARD "IPT --log-prefix

chain ?OUTPUT 链 4.1.6?OUTPUT

want. don't we packets TCP ?Bad 包 TCP 排除不良

bad_tcp_packets -j tcp -p OUTPUT -A $IPTABLES

allow. to IP's which decide to rules OUTPUT ?Special 的规则 OUTPUT 包 IP 决定允许哪个

ACCEPT -j $LO_IP -s ALL -p OUTPUT -A $IPTABLES
ACCEPT -j $LAN_IP -s ALL -p OUTPUT -A $IPTABLES
ACCEPT -j $INET_IP -s ALL -p OUTPUT -A $IPTABLES

above. the match don't that packets weird ?Log 将不满足上述规则的形为怪异的包记录在案

DEBUG --log-level LOG -j 3 --limit-burst 3/minute --limit limit -m OUTPUT -A $IPTABLES
" died: packet OUTPUT "IPT --log-prefix

table ?nat 表 nat 4.2 #

policies ?Set 设置策略 4.2.1

chains specified user ?Create 创建用户自定义链 4.2.2

chains specified user in content ?Create 在用户自定义链中建立规则 4.2.3

chain ?PREROUTING 链 PREROUTING 4.2.4

chain ?POSTROUTING 链 POSTROUTING 4.2.5

Address Network and Forwarding IP simple ?Enable 转发及网络地址转换 IP 允许简单的
Translation

$INET_IP --to-source SNAT -j $INET_IFACE -o POSTROUTING -A nat -t $IPTABLES

chain ?OUTPUT 链 OUTPUT 4.2.6

table ?mangle 表 mangle 4.3 #

policies ?Set 设置策略 4.3.1

chains specified user ?Create 创建用户自定义链 4.3.2

chains specified user in content ?Create 在用户自定义链中建立规则 4.3.3

chain ?PREROUTING 链 PREROUTING 4.3.4

chain ?INPUT 链 INPUT 4.3.5

chain ?FORWARD 链 FORWARD 4.3.6

chain ?OUTPUT 链 OUTPUT 4.3.7

chain ?POSTROUTING 链 POSTROUTING 4.3.8
#初始化
-X IPTABLES
-X nat -t IPTABLES
-X mangle -t IPTABLES
-Z iptables
)))) 默认规则(((( 定义策略
ACCEPT INPUT -P iptables
ACCEPT OUTPUT -P iptables
ACCEPT FORWARD -P iptables
ACCEPT -j lo -i INPUT -A iptables
ACCEP

免责申明:本站发布的内容(图片、视频和文字)以转载和分享为主,文章观点不代表本站立场,如涉及侵权请联系站长邮箱:xbc-online@qq.com进行反馈,一经查实,将立刻删除涉嫌侵权内容。