安卓手机共享了无线,如何将所有http 请求定向到手机在局域网的ip ?

2013-05-28 10:08:10 +08:00
 ccbikai
我把我安卓手机网络共享了,而且搭建了web环境。

我想让所有连接这个无线的网络的http访问全部定向到我手机的ip192.168.43.1
2912 次点击
所在节点    DNS
22 条回复
tarsier
2013-05-28 10:43:30 +08:00
安卓如果root了,可以使用iptables来完成

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.42.1
ccbikai
2013-05-28 11:10:26 +08:00
@tarsier 有root 权限。

这样做后,如何关闭呢?
tarsier
2013-05-28 11:45:05 +08:00
@ccbikai 再删除这条iptables规则呗(-A表示append, -D表示delete)

iptables -t nat -D PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.42.1
ccbikai
2013-05-28 12:18:10 +08:00
@tarsier 感谢你的帮助


这个对手机正常上网没有影响吧?
tarsier
2013-05-28 12:23:04 +08:00
@ccbikai 我记得安卓好像共享wifi之后,自己就不能上网了吧
ccbikai
2013-05-28 12:29:40 +08:00
@tarsier 还是可以的。
ccbikai
2013-05-28 13:14:33 +08:00
@tarsier 执行这个命令出错了

http://p13.freep.cn/p.aspx?u=v20_p13_photo_1305281314072205_0.jpg

是手机iptables的问题?
ccbikai
2013-05-28 13:21:53 +08:00
tarsier
2013-05-28 14:09:37 +08:00
@ccbikai 搜了下,你试试这个解决办法 http://stackoverflow.com/questions/10331699/getprotobyname-error-iptables

iptables -A INPUT -p 6 替代 iptables -A INPUT -p tcp
tarsier
2013-05-28 14:12:18 +08:00
@ccbikai 还有人说,虽然有这个警告,但是实际上iptables执行成功了


你可以 iptables -t nat -L 贴一下结果
ccbikai
2013-05-28 16:43:20 +08:00
@tarsier

貌似添加好了

但是浏览器访问 dfnjb.com 不会跳转
ccbikai
2013-05-28 16:46:53 +08:00
@tarsier 用6替代后 出现的结果

tarsier
2013-05-28 16:47:31 +08:00
@ccbikai “但是浏览器访问 dfnjb.com 不会跳转” 这个浏览器是连接这个网络的其他机器的浏览器?
tarsier
2013-05-28 16:51:20 +08:00
@ccbikai 看这个图还是感觉iptables没成功
ccbikai
2013-05-28 17:08:55 +08:00
@tarsier 多的 ,其他机器的浏览器
tarsier
2013-05-28 17:18:20 +08:00
@ccbikai 不用iptables之前,其他浏览器能通过这个wifi正常上网吗?
ccbikai
2013-05-28 17:28:53 +08:00
@tarsier 可以的 。
tarsier
2013-05-28 21:46:23 +08:00
@ccbikai

把上面的命令换成这个试试:

iptables -t nat -A PREROUTING -s xxxx/xx(你的共享wifi所在的网段) -p tcp --dport 80 -j REDIRECT --to-ports 80
tarsier
2013-05-28 21:46:57 +08:00
xxxx/xx 是 类似 192.168.1.0/24 这种格式的ip段
ccbikai
2013-05-28 22:25:00 +08:00
@tarsier 还是那句fix me

莫非是安卓的iptables是精简的?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/70369

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX