问个网关上写iptables的问题

75 views
Skip to first unread message

Yang Fan

unread,
Sep 19, 2015, 7:59:23 AM9/19/15
to sh...@googlegroups.com
只有一个网卡的树莓派当网关,装了 redsocks 全局 x 土啬,在树莓派上是能走通了,其他把它当网关的机器走不出去,几乎翻遍了所有中文文章,都是说加个 PREROUTING 就能搞定了,但我就是不行:

#chnroute...
-A SS -d 223.255.236.0/22 -j RETURN
-A SS -d 223.255.252.0/23 -j RETURN
-A SS -p tcp -j REDIRECT -o eth0 --to-ports 58100 #redsocks 开的端口
-A PREROUTING -p tcp -j SS #貌似光这句不行
# localhost redirect to ss
-A OUTPUT -p tcp -j SS #树莓派自己能 x 出去
-A POSTROUTING -s 192.168.0.0/16 -j MASQUERADE
COMMIT

现在的问题是,因为加了 chnroute ,所以国内 IP 都是没问题的,但国外 IP ,树莓派本身是走 OUTPUT 链的,没问题,其他把树莓派当网关的机器貌似是走 PREROUTING 的,但实际上没走 redsocks 的样子,还是直连出去了。如果把-A SS -p tcp -j REDIRECT -o eth0 --to-ports 58100中的-o eth0去掉,则直接没响应了,连都连不上了。

看了很多帖子文章,比如 https://www.v2ex.com/t/127172 里面貌似说是可以搞定的,求详细。

--
Regards,
Fan Yang

依云

unread,
Sep 21, 2015, 11:06:17 AM9/21/15
to sh...@googlegroups.com
你的 redsocks 监听的 IP 是?我的测试结果是,必须在来源网络接口的 IP 上监听。我是把 vboxnet0 的流量扔到 redsocks 的,规则如下:

iptables -t nat -A PREROUTING -i vboxnet0 -p tcp -m comment --comment vbox -j REDIRECT 31338

其中 redsocks 必须监听 vboxnet0 的 IP 或者 0.0.0.0。

--
Best regards,
lilydjwg

Linux Vim Python 我的博客:
http://lilydjwg.is-programmer.com/
--
A: Because it obfuscates the reading.
Q: Why is top posting so bad?

Yang Fan

unread,
Sep 21, 2015, 8:44:58 PM9/21/15
to sh...@googlegroups.com
确实是redsocks监听到127.0.0.1了,改成0.0.0.0就好了。
多谢!

--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout



--
Regards,
Fan Yang
Reply all
Reply to author
Forward
0 new messages