【问题标题】:IP address lookup with appended port带有附加端口的 IP 地址查找
【发布时间】:2015-01-25 01:55:27
【问题描述】:

我正在尝试为临时用户设置一个局域网信息网络服务器——因为我需要保持简单。我的路由器是一个 netgear wnr2000,运行 ddwrt 并设置了 dnsmasq 以提供本地 DNS。我的网络服务器是一个运行 PAWS http 服务器的廉价安卓机器。目前,用户必须输入“我的房子:8080/页面名称”作为 URL。这是必须输入完整 IP 地址的一个步骤,但我想消除端口引用。不完全确定如何做到这一点,特别是因为我在网络上唯一的计算资源是路由器和 android 盒子。想法?

【问题讨论】:

    标签: dns


    【解决方案1】:

    当用户想要访问您的“我的房子”URL 时,为了消除对端口引用的需要,您应该使用端口 80(默认 http 端口)而不是端口 8080。

    谷歌了一下,发现这篇文章是关于通过更改 iptables 让 PAW 监听端口 80 http://fun2code-blog.blogspot.co.uk/2011/11/running-paw-on-port-80.html

    链接中的代码如下(我没有测试过,请自行决定使用),你需要是root用户

    import de.fun2code.android.pawserver.util.*;
    
    execRootShell(String[] commands) {
      shellCmd = "su -c sh";
    
      sh = Runtime.getRuntime().exec(shellCmd);
      os = sh.getOutputStream();
    
      for(cmd : commands) {
        os.write((cmd + "\n").getBytes());
      }
    
      os.write(("exit\n").getBytes());
      os.flush();
      sh.waitFor(); 
    }
    
    /* ---- Config -------- */
    ip = Utils.getLocalIpAddress();
    redirectFrom = 80;
    redirectTo = 8080;
    action = "ADD"; // Can be ADD or DELETE
    /* -------------------- */
    
    action = "-" + action.substring(0, 1);
    
    String[] iptablesCmds = new String[] {
      "iptables -t nat " + action + " OUTPUT -d 127.0.0.1 -p tcp --dport " + redirectFrom + " -j REDIRECT --to-ports " + redirectTo,
      "iptables -t nat " + action + " OUTPUT -d " + ip + " -p tcp --dport " + redirectFrom + " -j REDIRECT --to-ports " + redirectTo,
      "iptables -t nat " + action + " PREROUTING -d " + ip + " -p tcp --dport " + redirectFrom + " -j REDIRECT --to-ports " + redirectTo
    };
    
    execRootShell(iptablesCmds);
    

    【讨论】:

      猜你喜欢
      • 2019-03-05
      • 2017-06-27
      • 2011-11-28
      • 1970-01-01
      • 2019-05-31
      • 1970-01-01
      • 2022-06-18
      • 2014-03-14
      相关资源
      最近更新 更多