LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: nobody_am

最近学习IPTABLES,有兴趣者请进来说话,谁是谁非,等你定论(多问题跟贴)

[复制链接]
 楼主| 发表于 2003-8-23 03:58:03 | 显示全部楼层
顶一下。
 楼主| 发表于 2003-8-23 12:43:03 | 显示全部楼层
=========>《Redhat Press - Red Hat Linux Security and Optimization》449页有:

So the order of rules is crucial. One exception to the first matching rule wins is
the default policy rule—any default policy rule, as in this example:

/sbin/iptables -P  input DENY
/sbin/iptables -A  input -t filter -s 192.168.1.254 -j ACCEPT
/sbin/iptables -A  input -t filter -s 192.168.1.0/24 -j DROP

=========>注意两处:input没有大写对吗?
DENY在iptables里已经换成DROP了嘛。
 楼主| 发表于 2003-8-23 12:48:56 | 显示全部楼层
=============>《linux防火墙探秘》第200页有段话:
禁止声称来自C类私有地址及到C类私有地址的包:
脚本如下:
iptables -A INPUT -i eth1 -s 192.168.0.0/16 -j  DROP
iptables -A INPUT -i eth1 -d 192.168.0.0/16 -j  DROP
iptables -A OUTPUT -i eth1 -s 192.168.0.0/16 -j DROP
iptables -A OUTPUT -i eth1 -d 192.168.0.0/16 -j DROP

============>《rhl-sg-en》(redhat文档)第70页有段话:
To take the restrictions a step further, block all outside connections that attempt to spoof private IP
address ranges to inltrate your LAN. If a LAN uses the 192.168.1.0/24 range, a rule can set the
Internet facing network device (for example, eth0) to drop any packets to that device with an address
in your LAN IP range. Because it is recommended to reject forwarded packets as a default policy, any
other spoofed IP address to the external-facing device (eth0) will be rejected automatically.

iptables -A FORWARD -p tcp -s 192.168.1.0/24 -i eth0 -j DROP
iptables -A FORWARD -p udp -s 192.168.1.0/24 -i eth0 -j DROP

============>依照《rhl-sg-en》文档所写,
做到禁止声称来自C类私有地址及到C类私有地址的包,
我觉得用下列两句就可以了:
iptables -A INPUT -s 192.168.0.0/16  -i eth1  -j DROP
iptables -A OUTPUT -d 192.168.0.0/16 -o eth1  -j DROP

搞不清,为什么《linux防火墙探秘》作者会那样写,道理何在呢?会不会也有他的道理呢?
因为iptables调试比较困难,至少需要三台机才可以合理的调试,谁有条件,试试看。
欢迎讨论,以及提出疑点。
 楼主| 发表于 2003-8-23 12:53:30 | 显示全部楼层
难道:
iptables -A INPUT -i eth1 -s 192.168.0.0/16 -j DROP
iptables -A INPUT -i eth1 -d 192.168.0.0/16 -j DROP
iptables -A OUTPUT -i eth1 -s 192.168.0.0/16 -j DROP
iptables -A OUTPUT -i eth1 -d 192.168.0.0/16 -j DROP

<=>等价于

iptables -A FORWARD -s 192.168.0.0/16 -i eth1 -j DROP
iptables -A FORWARD -d 192.168.0.0/16 -o eth1 -j DROP

  

难道FORWARD可以用INPUT&OUTPUT替代?越想越糊涂。
 楼主| 发表于 2003-8-23 14:56:19 | 显示全部楼层
=========>《Redhat Press - Red Hat Linux Security and Optimization》502页末尾:
# Enable local (loopback) interface
$IPTABLES -A input -i lo -j ACCEPT
$IPTABLES -A output -i lo  -j ACCEPT

注:$IPTABLES=/sbin/iptables

==========>我认为这里的第二个规则的-i有问题。
应该用 -o,大家说呢?
 楼主| 发表于 2003-8-23 15:59:58 | 显示全部楼层
=========>《Redhat Press - Red Hat Linux Security and Optimization》504页
... ...
Allowing users at private network access
to external Web servers
... ...

$IPTABLES -A output -i $EXTERNAL_LAN_INTERFACE -p tcp \
-s $EXTERNAL_LAN_INTERFACE_ADDR 1024-65535 \
-d 0/0 80 -j ACCEPT
... ...
$IPTABLES -A input -i $EXTERNAL_LAN_INTERFACE -p tcp ! -y \
-s 0/0 80 \
-d $EXTERNAL_LAN_INTERFACE_ADDR 1024-65535 \
-j ACCEPT
... ...

注:$IPTABLES=/sbin/iptables
    $EXTERNAL_LAN_INTERFACE = eth0 外网卡
    $EXTERNAL_LAN_INTERFACE_ADDR = 207.183.233.18 外网卡为标准IP地址
    且:这个网络由网关,内网组成,内网用的是C类保留IP 192.168.1.0子网。   
===========>对于这句话这段话我是这样分析的:
看第一个规则:
它的目的是让网关这台机能够访问internet上任何http服务,用了-i,不知道和output矛盾吗?

看第二个规则:
它的目的是让任何提供http服务的机器不通过80端口和网关机建立连接,连 -y页用上了,显然有问题吧。

=========>我猜测的结论
1.这本书相关iptables的内容纯粹是在胡乱讲,有时把ipchains的语法都拿过来用在iptables上,如:input,output不大写,该用-o的地方老用 -i ,该用--syn的地方,跑出了-y
2.内网IP使用标准的国际唯一IP和C类保留IP这两类不同的方式,
防火墙类型是不同的吗?
各位可以看看打标题:Allowing users at private network access
to external Web servers
他的目的是让内网访问internet的任何web服务,
通过这两条规则达到目的的(是否达到?我也不知道,没条件做试验),

如果内网使用的是标准IP,我完全可以用FORWARD链,
例如:
iptables -A FORWARD -p tcp -i eth0  --sport 1024:65535 -d 0/0 --dport 80  -j ACCEPT
iptables -A FORWARD -p tcp -i eth1 -s 0/0 --sport 80 --dport 1024:65535 ! --syn -j ACCEPT
(不知道这样行不行?)
注:eht1为外网卡,eth0为内网卡。
 楼主| 发表于 2003-8-23 17:27:14 | 显示全部楼层
zubin006兄为提供了一个关于iptables文档的地址,现在贴出来,希望对大家有好处:

http://cmpp.linuxforum.net/NetSnake/
发表于 2003-8-23 21:07:45 | 显示全部楼层
谢谢你提供的信息,我正好也在看这个。
 楼主| 发表于 2003-8-24 01:43:03 | 显示全部楼层
ppsda兄,一起学习,可以讨论。
 楼主| 发表于 2003-8-24 10:27:21 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表