ccbikai
V2EX  ›  DNS

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

  •  
  •   ccbikai ·
    PRO
    · May 28, 2013 via Android · 3436 views
    This topic created in 4763 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
        1
    tarsier  
       May 28, 2013   ❤️ 2
    安卓如果root了,可以使用iptables来完成

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

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

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


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

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

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

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


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

    貌似添加好了

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

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

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

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

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

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