免费注册 查看新帖 |

Chinaunix

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

转发不成功,请看规则。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2002-12-18 11:11 |只看该作者 |倒序浏览
iptables -F -t filter
iptables -F -t nat
iptables -F -t mangle

modprobe ip_talbes
modprobe ip_nat_ftp
modprobe ip_conntrack
modprobe ip_conntrack_ftp

iptables -A INPUT -i lo -s 127.0.0.2 -j ACCEPT
iptables -A INPUT -s 127.0.0.2 -j DROP
iptables -A INPUT -s 172.16.0.0/12 -j DROP
iptables -A INPUT -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i eth1 -s 192.168.0.166 -j DROP


iptables -t nat -A PREROUTING   -p tcp     -d $WAN_IPADDRESS --dport 5555 -j DNAT --to-destination 192.168.0.250
iptables -t nat -A PREROUTING   -p tcp     -d $WAN_IPADDRESS --dport 5556 -j DNAT --to-destination 192.168.0.2
iptables -t nat -A PREROUTING   -p tcp     -d $WAN_IPADDRESS --dport 23 -j DNAT --to-destination 192.168.0.8


iptables -t nat -A POSTROUTING  -p tcp     -s 192.168.0.250  --sport 22   -j SNAT --to-source 61.185.207.246:5555
iptables -t nat -A POSTROUTING  -p tcp     -s 192.168.0.2    --sport 22   -j SNAT --to-source 61.185.207.246:5556
iptables -t nat -A POSTROUTING  -p tcp     -s 192.168.0.8       -j SNAT --to-source 61.185.207.246:23

iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j MASQUERADE
iptables -A FORWARD -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -s $LAN_IPADDRESS -j ACCEPT

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2002-12-18 11:14 |只看该作者

转发不成功,请看规则。

先能说一下你要实现的功能吗?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2002-12-18 11:16 |只看该作者

转发不成功,请看规则。

对于POSTROUTING PREROUTING最好指定设备

论坛徽章:
0
4 [报告]
发表于 2002-12-18 11:20 |只看该作者

转发不成功,请看规则。

因为我要所有的ethX设备都适应以上的规则,所以没有指定界面的入口和出口,
主要功能是到61.185.207.246的5555转发到192.168.0.2的22端口等,转发不成功,但是我找不出错误。

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
5 [报告]
发表于 2002-12-18 11:25 |只看该作者

转发不成功,请看规则。

--to-source 61.185.207.246:5556这个成功了吗?

论坛徽章:
0
6 [报告]
发表于 2002-12-18 11:26 |只看该作者

转发不成功,请看规则。

没有成功。

论坛徽章:
0
7 [报告]
发表于 2002-12-18 11:27 |只看该作者

转发不成功,请看规则。

[这个贴子最后由Badmi在 2002/12/18 11:30am 编辑]

/etc/sysctl.conf

net.ipv4.ip_forward = 1


你的iptables的三个tab默认rule哪有写?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
8 [报告]
发表于 2002-12-18 11:29 |只看该作者

转发不成功,请看规则。

你这样作想实现什么?
访问192.168.0.2的22端口,然后跳 到外面的IP上吗?
还是?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
9 [报告]
发表于 2002-12-18 11:30 |只看该作者

转发不成功,请看规则。

SNAT的应用一般都是为了将真实的IP给保护起来
你这样的应用不太懂
:)

论坛徽章:
0
10 [报告]
发表于 2002-12-18 11:36 |只看该作者

转发不成功,请看规则。

是访问题61.185.207.246的5555端口时转发到192.168.0.2的22端口上等。
下面是各个表的输出内容。
[root@xfpower etc]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
DNAT       tcp  --  anywhere             smtp.xfpower.com   tcp dpt:5555 to:192.168.0.250
DNAT       tcp  --  anywhere             dns.xfpower.com    tcp dpt:5556 to:192.168.0.2
DNAT       tcp  --  anywhere             smtp.xfpower.com   tcp dpt:telnet to:192.168.0.8

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
SNAT       tcp  --  192.168.0.250        anywhere           tcp spt:ssh to:61.185.207.246:5555
SNAT       tcp  --  192.168.0.2          anywhere           tcp spt:ssh to:61.185.207.246:5556
SNAT       tcp  --  192.168.0.8          anywhere           to:61.185.207.246:23
MASQUERADE  all  --  192.168.0.0/24       anywhere           

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  
[root@xfpower etc]# iptables -t filter -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  127.0.0.2            anywhere           
DROP       all  --  127.0.0.2            anywhere           
DROP       all  --  172.16.0.0/12        anywhere           
DROP       all  --  10.0.0.0/8           anywhere           
DROP       all  --  192.168.0.166        anywhere           

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere           state RELATED,ESTABLISHED
ACCEPT     all  --  192.168.0.0/24       anywhere           

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
[root@xfpower etc]# iptables -t mangle -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
看看出了什么误。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP