免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6149 | 回复: 11
打印 上一主题 下一主题

[网络管理] iptables---想加一条内部地址是广播地址的规则,好像不起作用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-30 15:57 |只看该作者 |正序浏览
我的想法是这样的:
从外网进来的到NAT服务器17001端口的数据包 希望通过NAT后 转发广播地址到内网每台机器的17001端口上
也就是想加一条内部地址是广播地址的规则,希望进来的数据向内网所有的机器都发送,但是根本不能实现

哪位大哥能帮忙解释一下原因???

我加的规则:
nat(PREROUTING):
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:17001 to:255.255.255.255:17001-0
filter(FORWARD):
ACCEPT     udp  --  0.0.0.0/0            255.255.255.255     udp dpt:17001

论坛徽章:
0
12 [报告]
发表于 2006-09-01 21:17 |只看该作者
试试:

iptables -t nat -A PREROUTING -p udp --dport 17001 -j DNAT --to 255.255.255.255:17001

iptables -A FORWARD -p udp --dport 17001 -j ACCEPT
iptables -A FORWARD -p udp --sport 17001 -j ACCEPT


还有,你可以抓包看看,虽然是广播出去了,可是回应的包的源地址应该不是255.255.255.255,所以你将17001端口(不管是源端口还是目的端口)的udp包全部放行试试看。

论坛徽章:
0
11 [报告]
发表于 2006-08-31 16:10 |只看该作者
原帖由 platinum 于 2006-8-31 14:06 发表

iptables 默认有 filter、nat 和 mangle 三个表
若想用 iptables 命令贴全所有规则,应该用

  1. # for i in filter nat mangle;do iptables -vnL -t $i;done
复制代码


我打印出来了,这个是恢复出厂值后的规则:
#
# for i in filter nat mangle;do iptables -vnL -t $i;done
Chain INPUT (policy ACCEPT 131 packets, 23008 bytes)
pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     udp  --  eth0   *       192.168.1.0/24       0.0.0.0/0           udp dpt:3000
6
    0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:3000
5
    0     0 ACCEPT     udp  --  br0    *       0.0.0.0/0            0.0.0.0/0           udp dpts:173
84:17390
    0     0 ACCEPT     udp  --  br0    *       0.0.0.0/0            0.0.0.0/0           udp dpts:534
56:53462
    0     0 ACCEPT     udp  --  br0    *       0.0.0.0/0            0.0.0.0/0           udp dpt:5060

    0     0 ACCEPT     all  --  eth0   *       0.0.0.0/0            0.0.0.0/0           state RELATE
D,ESTABLISHED
    0     0 LOG        tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x
16/0x02 limit: avg 6/hour burst 5 LOG flags 0 level 1 prefix `Intrusion -> '
  117 13072 DROP       all  --  eth0   *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     udp  --  eth0   *       192.168.1.0/24       0.0.0.0/0           udp dpt:3000
6
    0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:3000
5
    0     0 ACCEPT     all  --  eth0   *       0.0.0.0/0            0.0.0.0/0           state RELATE
D,ESTABLISHED
    0     0 LOG        tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x
16/0x02 limit: avg 6/hour burst 5 LOG flags 0 level 1 prefix `Intrusion -> '
    0     0 DROP       all  --  eth0   *       0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT 168 packets, 116K bytes)
pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  *      eth0    0.0.0.0/0            239.255.255.250
Chain PREROUTING (policy ACCEPT 154 packets, 15624 bytes)
pkts bytes target     prot opt in     out     source               destination
    0     0 DNAT       udp  --  br0    *       0.0.0.0/0            192.168.1.1         udp dpt:53 t
o:172.17.36.11

Chain POSTROUTING (policy ACCEPT 9 packets, 602 bytes)
pkts bytes target     prot opt in     out     source               destination
    0     0 MASQUERADE  all  --  *      eth0    192.168.1.0/24       0.0.0.0/0

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source               destination
Chain PREROUTING (policy ACCEPT 287 packets, 40311 bytes)
pkts bytes target     prot opt in     out     source               destination

Chain INPUT (policy ACCEPT 248 packets, 36080 bytes)
pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 168 packets, 116K bytes)
pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 226 packets, 133K bytes)
pkts bytes target     prot opt in     out     source               destination
#


还是上面的问题:想加一条内部地址是广播地址的规则,希望从端口17001进来的数据向内网所有的机器的17001都发送
我是这样做的,加了2条规则,使用的命令如下:
iptables -I FORWARD -i eth0 -p udp --dport 17001 -d 255.255.255.255 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 17001 -j DNAT --to-destination 255.255.255.255:17001

添加的规则如下:
[Chain PREROUTING]DNAT       udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:17001 to:255.255.255.255:17001
[Chain FORWARD]ACCEPT     udp  --  0.0.0.0/0            255.255.255.255     udp dpt:17001

这样不能实现,为什么?

怎样才能达到这种目的呢?
thanks

论坛徽章:
0
10 [报告]
发表于 2006-08-31 14:06 |只看该作者
原帖由 yangliu817 于 2006-8-31 10:15 发表

iptables命令是编译iptables这个组件得来的 我刚看了下 关于iptables-save和iptables-restore的文件都没编译进去

以前也没用过iptables-save这个命令 就知道它是把规则保存到文件中去 我用iptables [-t nat] ...

iptables 默认有 filter、nat 和 mangle 三个表
若想用 iptables 命令贴全所有规则,应该用

  1. # for i in filter nat mangle;do iptables -vnL -t $i;done
复制代码

论坛徽章:
0
9 [报告]
发表于 2006-08-31 11:08 |只看该作者
原帖由 extend 于 2006-8-30 16:59 发表
lz应该先看看iptables的流程,在iptables接收和转发封包间有一个路由寻址过程,在linux上这是通过router或iprouter2实现的。路由设计一个最基本的原理就是屏蔽广播包,防止不同网段上的广播风暴,所以你不会成功的 ...

关于iptables的具体实现目前我还不清楚,如果像你说的在接收和转发包间还有一个路由寻址过程的话,那就有可能是这方面的问题。

thanks

论坛徽章:
0
8 [报告]
发表于 2006-08-31 10:15 |只看该作者
原帖由 platinum 于 2006-8-30 22:49 发表

那么我想问了,你的  iptables 这个命令又是如何来的呢?不是你亲手装的嘛?
若不是,去问那个装 iptables 的人要 iptables-save

iptables命令是编译iptables这个组件得来的 我刚看了下 关于iptables-save和iptables-restore的文件都没编译进去

以前也没用过iptables-save这个命令 就知道它是把规则保存到文件中去 我用iptables [-t nat] -L -n显示的规则拿出来看行不行?

论坛徽章:
0
7 [报告]
发表于 2006-08-30 22:49 |只看该作者
原帖由 yangliu817 于 2006-8-30 16:33 发表
斑斑 不好意思 我们开发板上的uClinux系统不支持这个命令 没法拿出来看

我在PC上验证过了 加一条内部地址是广播地址的规则 不能实现 但就是不知道为什么

那么我想问了,你的  iptables 这个命令又是如何来的呢?不是你亲手装的嘛?
若不是,去问那个装 iptables 的人要 iptables-save

论坛徽章:
0
6 [报告]
发表于 2006-08-30 16:59 |只看该作者
lz应该先看看iptables的流程,在iptables接收和转发封包间有一个路由寻址过程,在linux上这是通过router或iprouter2实现的。路由设计一个最基本的原理就是屏蔽广播包,防止不同网段上的广播风暴,所以你不会成功的。为什么不试试multicast也许有成功的可能。

论坛徽章:
0
5 [报告]
发表于 2006-08-30 16:44 |只看该作者

回复 3楼 extend 的帖子

刚才搜索了一下 没找到什么有用的讯息

这位兄弟能给点意见吗

论坛徽章:
0
4 [报告]
发表于 2006-08-30 16:33 |只看该作者
斑斑 不好意思 我们开发板上的uClinux系统不支持这个命令 没法拿出来看

我在PC上验证过了 加一条内部地址是广播地址的规则 不能实现 但就是不知道为什么
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP