messagebus
V2EX  ›  DNS

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

  •  
  •   messagebus · May 28, 2013 via Android · 3728 views
    This topic created in 4914 days ago, the information mentioned may be changed or developed.
    我把我安卓手机网络共享了,而且搭建了web环境。

    我想让所有连接这个无线的网络的http访问全部定向到我手机的ip192.168.43.1
    22 replies  •  1970-01-01 08:00:00 +08:00
    tarsier
    tarsier
    May 28, 2013❤️2
    1
    安卓如果root了,可以使用iptables来完成

    iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.42.1
    messagebus
    messagebus
    OP
    May 28, 2013 via Android
    2
    @tarsier 有root 权限。

    这样做后,如何关闭呢?
    tarsier
    tarsier
    May 28, 2013❤️1
    3
    @ccbikai 再删除这条iptables规则呗(-A表示append, -D表示delete)

    iptables -t nat -D PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.42.1
    messagebus
    messagebus
    OP
    May 28, 2013 via Android
    4
    @tarsier 感谢你的帮助


    这个对手机正常上网没有影响吧?
    tarsier
    tarsier
    May 28, 2013
    5
    @ccbikai 我记得安卓好像共享wifi之后,自己就不能上网了吧
    messagebus
    messagebus
    OP
    May 28, 2013 via Android
    6
    @tarsier 还是可以的。
    messagebus
    messagebus
    OP
    May 28, 2013
    7
    @tarsier 执行这个命令出错了

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

    是手机iptables的问题?
    tarsier
    tarsier
    May 28, 2013
    9
    @ccbikai 搜了下,你试试这个解决办法 http://stackoverflow.com/questions/10331699/getprotobyname-error-iptables

    iptables -A INPUT -p 6 替代 iptables -A INPUT -p tcp
    tarsier
    tarsier
    May 28, 2013
    10
    @ccbikai 还有人说,虽然有这个警告,但是实际上iptables执行成功了


    你可以 iptables -t nat -L 贴一下结果
    messagebus
    messagebus
    OP
    May 28, 2013
    11
    @tarsier

    貌似添加好了

    但是浏览器访问 dfnjb.com 不会跳转
    messagebus
    messagebus
    OP
    May 28, 2013
    12
    @tarsier 用6替代后 出现的结果

    tarsier
    tarsier
    May 28, 2013
    13
    @ccbikai “但是浏览器访问 dfnjb.com 不会跳转” 这个浏览器是连接这个网络的其他机器的浏览器?
    tarsier
    tarsier
    May 28, 2013
    14
    @ccbikai 看这个图还是感觉iptables没成功
    messagebus
    messagebus
    OP
    May 28, 2013
    15
    @tarsier 多的 ,其他机器的浏览器
    tarsier
    tarsier
    May 28, 2013
    16
    @ccbikai 不用iptables之前,其他浏览器能通过这个wifi正常上网吗?
    messagebus
    messagebus
    OP
    May 28, 2013
    17
    @tarsier 可以的 。
    tarsier
    tarsier
    May 28, 2013
    18
    @ccbikai

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

    iptables -t nat -A PREROUTING -s xxxx/xx(你的共享wifi所在的网段) -p tcp --dport 80 -j REDIRECT --to-ports 80
    tarsier
    tarsier
    May 28, 2013
    19
    xxxx/xx 是 类似 192.168.1.0/24 这种格式的ip段
    messagebus
    messagebus
    OP
    May 28, 2013
    20
    @tarsier 还是那句fix me

    莫非是安卓的iptables是精简的?
    tarsier
    tarsier
    May 28, 2013
    21
    @ccbikai 我也有点怀疑是iptables的问题
    Perry87
    Perry87
    May 29, 2013
    22
    @ccbikai
    @tarsier

    搭车问一下,使用2.3的系统自带的热点共享程序,是使用b/g/n哪种模式的?有没有办法进行设置?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2451 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 04:44 · PVG 12:44 · LAX 20:44 · JFK 23:44
    ♥ Do have faith in what you're doing.