当前位置:操作系统 > Unix/Linux >>

转发不成功,请看规则

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

  【发表回复】【查看CU论坛原帖】【关闭】

  wind521 回复于:2002-12-18 11:14:23

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

  wind521 回复于:2002-12-18 11:16:56

  对于POSTROUTING PREROUTING最好指定设备

  weizhishu 回复于:2002-12-18 11:20:20

  因为我要所有的ethX设备都适应以上的规则,所以没有指定界面的入口和出口,

  主要功能是到61.185.207.246的5555转发到192.168.0.2的22端口等,转发不成功,但是我找不出错误。

  wind521 回复于:2002-12-18 11:25:26

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

  weizhishu 回复于:2002-12-18 11:26:07

  没有成功。

  Badmi 回复于:2002-12-18 11:27:35

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

  /etc/sysctl.conf

  net.ipv4.ip_forward = 1

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

  wind521 回复于:2002-12-18 11:29:10

  你这样作想实现什么?

  访问192.168.0.2的22端口,然后跳 到外面的IP上吗?

  还是?

  wind521 回复于:2002-12-18 11:30:05

  SNAT的应用一般都是为了将真实的IP给保护起来

  你这样的应用不太懂

  :)

  weizhishu 回复于:2002-12-18 11:36:40

  是访问题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

  看看出了什么误。

  wind521 回复于:2002-12-18 12:05:31

  DNAT实现了吗?

  Badmi 回复于:2002-12-18 12:28:19

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

  telnet smtp.xfpower.com 23,转到telnet 192.168.0.8 23,这时192.168.0.8 23响应的结果又送到61.185.207.246:23,这是你要的结果?

  别的不看了

  Badmi 回复于:2002-12-18 12:48:00

  [这个贴子最后由Badmi在 2002/12/18 01:44pm 编辑]

  [quote][b]下面引用由[u]weizhishu[/u]在 [i]2002/12/18 11:20am[/i] 发表的内容:[/b]

  因为我要所有的ethX设备都适应以上的规则,所以没有指定界面的入口和出口,

  主要功能是到61.185.207.246的5555转发到192.168.0.2的22端口等,转发不成功,但是我找不出错误。

  [/quote]

  iptables -t nat -A PREROUTING -p tcp -d 61.185.207.246 --dport 5555 -j DNAT --to-destination 192.168.0.2:22

  iptables -L -t nat -vn

  target prot opt in out source destination

  DNAT tcp -- * * 0.0.0.0/0 61.185.207.246 tcp dpt:5555 to:192.168.0.2:22

  weizhishu 回复于:2002-12-18 19:29:38

  我想telnet smtp.xfpower.com时转发到内部的23端口。

  求badmi说清楚点,这个问题郁闷很长时间了,多谢了。

  weizhishu 回复于:2002-12-19 10:30:11

  顶。

  Badmi 回复于:2002-12-19 11:41:54

  [这个贴子最后由Badmi在 2002/12/19 12:15pm 编辑]

  明白了,你是要实现ip及port的重定向,而不是nat的功能。

  iptables有一个转发的功能redirect,但只支持到localhost的端口。

  我想正确的做法是用iptables和ipmasqadm这两个软件结合使用,会容易些。

  我以前用ipchains和ipmasqadm实现过类似你的这样的要求。

  另还有一个只用iptables的方法

  iptables -t nat -A PREROUTING -p tcp -d smtp.xfpower.com --dport 23 -j DNAT --to 192.168.0.8:23

  iptables -t nat -A POSTROUTING -p tcp -d 192.168.0.8 --dport 23 -j SNAT --to 网关IP

  这个我试验成功了。

  Badmi 回复于:2002-12-19 11:46:12

  真正的DNAT或SNAT的应用可以参考

  http://www.zzzyk.com/engineer/bye2000/doc/nat.htm

  我想你与这个要求不是一样的吧。

  weizhishu 回复于:2002-12-19 12:13:43

  我有公网只有一个有效的ip,那么怎么用其它方法解决以上问题?iptables有没有其它方法,用一个公网ip

  dnat一个内部机的没有那么多公网的ip.

  Badmi 回复于:2002-12-19 12:16:34

  [这个贴子最后由Badmi在 2002/12/19 12:19pm 编辑]

  另还有一个只用iptables的方法

  iptables -t nat -A PREROUTING -p tcp -d smtp.xfpower.com --dport 23 -j DNAT --to 192.168.0.8
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,