LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 806|回复: 1

关于转发的问题

[复制链接]
发表于 2007-6-18 16:16:01 | 显示全部楼层 |阅读模式
我要实现的目的:内网上的IP既能ping通172.168.1.1,也能ping通58.20.51.1

三个网络:
1、网络光纤,IP:58.20.51.xx/24 GW:58.20.51.1                eth0
2、电信ADSL,IP:172.168.1.123/24 GW:172.168.1.1        eth2
3、内网IP, IP:10.0.4.1/24                                eth1

现在做了下面的规则,内网机器(10.0.4.0/24网段)可以ping通下列IP:
10.0.4.1
58.20.51.1
172.168.1.123
就是跳不到172.168.1.1上面去。

关了iptables用这个命令
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
可以实现转发,但是打开iptables就是不行

路由表信息如下:
麻烦了




Table: nat
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination
1    vpn        all  --  10.0.4.0/24          0.0.0.0/0
2    MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0
3    MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0
4    MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0
5    MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain vpn (1 references)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            10.0.0.0/16
2    ACCEPT     all  --  0.0.0.0/0            172.16.101.0/24
3    ACCEPT     all  --  0.0.0.0/0            83.136.93.138
4    ACCEPT     all  --  0.0.0.0/0            83.136.93.149
5    SNAT       all  --  0.0.0.0/0            0.0.0.0/0           to:58.20.51.xx

Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
发表于 2007-6-19 06:09:44 | 显示全部楼层
首先,确认在那个有eth0,1,2的网关机器上ping
58.20.51.1 和 172.168.1.1 没有问题。而你的问题是让内网的机器,比如10.0.4.2,也能同时ping通这两个地址。

问题似乎出在这里,你把所有内网的包都从eth0发出去了。
5 SNAT all -- 0.0.0.0/0 0.0.0.0/0 to:58.20.51.xx

在网关机器,清空所有的规则,同时加上这两条规则试试:
iptables -t nat -X
iptables -t nat -F
iptables -F
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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