免费注册 查看新帖 |

Chinaunix

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

[网络管理] Iptables NAT tcp连接中断 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-07 16:51 |只看该作者 |倒序浏览
20可用积分
本帖最后由 DreamAndLove 于 2012-11-07 20:41 编辑

系统描述(linux):
PC1 -> nat服务器, kernel: 2.6.37
     eth0:  10.27.16.65
     usb0:  192.168.0.254

iptable rules:
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -s 255.255.255.252/30 -j ACCEPT
iptables -t nat -A PREROUTING -d 10.27.16.65 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
iptables -t nat -A POSTROUTING -s 192.168.0.253 -j SNAT --to 10.27.16.65

route table:
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.252   0.0.0.0         255.255.255.252 U     0      0        0 usb0
10.27.16.0      0.0.0.0         255.255.248.0   U     0      0        0 eth0
0.0.0.0         10.27.16.1      0.0.0.0         UG    0      0        0 eth0



PC2 -> 客户端 route add default gw 192.168.0.254
     usb0:  192.168.0.253

route table:
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.0.254   0.0.0.0         UG    0      0        0 usb0
192.168.0.252   *               255.255.255.252 U     0      0        0 usb0


问题描述:PC2上tcp连接随机中断
PC2 -> wget http://10.27.16.157/a.apk
    走同网段的地址,tcp连接正常,不会出任何错误

   -> wget http://10.27.122.64/a.apk
    走其他网段地址, tcp连接出现随机中断
    error_1 string:  - stalled -
    error_2 string:  wget: read error: Connection reset by peer

   -> 出现错误时, 在10.27.122.64服务器端抓包,会有一系列的TCP RST状态的包; 但是在PC2上的抓包,却没有发现PC2发出这些RST状态的包.

最佳答案

查看完整内容

规则没有问题啊,太奇怪了. 请@platinum版主帮忙吧

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
2 [报告]
发表于 2012-11-07 16:51 |只看该作者
规则没有问题啊,太奇怪了. 请@platinum版主帮忙吧

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
3 [报告]
发表于 2012-11-07 19:42 |只看该作者
iptables -A FORWARD -s 255.255.255.252/30 -j ACCEPT
iptables -t nat -A PREROUTING -d 10.27.16.65 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

这几行注释下看看

论坛徽章:
0
4 [报告]
发表于 2012-11-07 19:58 |只看该作者
本帖最后由 DreamAndLove 于 2012-11-07 20:01 编辑

回复 2# chenyx
  1. iptables -A FORWARD -s 255.255.255.252/30 -j ACCEPT
  2. iptables -t nat -A PREROUTING -d 10.27.16.65 -j DNAT --to 192.168.0.253
  3. iptables -t nat -A POSTROUTING -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
复制代码
注释了这三行,还是会出现这个错误!


   

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
5 [报告]
发表于 2012-11-07 20:07 |只看该作者
你将PC1上iptables的规则和路由表都贴一下吧.
另外,你在PC1上wget122网段的,会不会出现中断的现象?

论坛徽章:
0
6 [报告]
发表于 2012-11-07 20:19 |只看该作者
单独在PC1上wget http://10.27.122.64/a.apk, 没有任何错误,
只有在PC2上执行wget时,才会出现tcp连接中断的问题

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
7 [报告]
发表于 2012-11-07 20:25 |只看该作者
挺奇怪的,你把iptables -t nat -L -nv的结果贴一下.

论坛徽章:
0
8 [报告]
发表于 2012-11-07 20:28 |只看该作者
本帖最后由 DreamAndLove 于 2012-11-07 20:32 编辑

回复 6# chenyx
iptable rules
  1. # iptables -nvL
  2. Chain INPUT (policy ACCEPT 2915 packets, 335K bytes)
  3. pkts bytes target     prot opt in     out     source               destination         

  4. Chain FORWARD (policy ACCEPT 3 packets, 180 bytes)
  5. pkts bytes target     prot opt in     out     source               destination         
  6. 2554 2690K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

  7. Chain OUTPUT (policy ACCEPT 1252 packets, 176K bytes)
  8. pkts bytes target     prot opt in     out     source               destination

  9. # iptables -t nat -nvL
  10. Chain PREROUTING (policy ACCEPT 170 packets, 24890 bytes)
  11. pkts bytes target     prot opt in     out     source               destination         

  12. Chain INPUT (policy ACCEPT 168 packets, 24770 bytes)
  13. pkts bytes target     prot opt in     out     source               destination         

  14. Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
  15. pkts bytes target     prot opt in     out     source               destination         

  16. Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
  17. pkts bytes target     prot opt in     out     source               destination         
  18.     2   120 SNAT       all  --  *      *       192.168.0.253       0.0.0.0/0            to:10.27.16.65
复制代码

论坛徽章:
0
9 [报告]
发表于 2012-11-07 20:37 |只看该作者
回复 8# chenyx
谢谢!
platinum版主在线吗?

   

论坛徽章:
0
10 [报告]
发表于 2012-11-08 10:41 |只看该作者
@platinum版主, 帮忙看看大概什么原因产生这种bug
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP