转发外部stream量到127.0.0.1

我有一个在127.0.0.1:8000上运行的HTTP服务器。 我如何使用iptables或其他东西来路由外部stream量呢? 我希望能够从我的浏览器访问my.ip.addr:8000。

iptables -A PREROUTING -i eth0 -p tcp --dport 8000 -j REDIRECT --to-ports 8000 

没有帮助

编辑:

要testing这是否工作,我正在使用下面的node.js脚本:

 // Load the http module to create an http server. var http = require('http'); // Configure our HTTP server to respond with Hello World to all requests. var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello World\n"); }); // Listen on port 8000, IP defaults to 127.0.0.1 server.listen(8000, "127.0.0.1"); // Put a friendly message on the terminal console.log("Server running at http://127.0.0.1:8000/"); 

您不需要使用iptables,最简单的方法是在“server.listen”行上更改IP地址。 它可以是公共IP或“0.0.0.0”。 后者将把Web服务器绑定到所有可用的IP。

您的另一种select是使用另一个在代理configuration中设置的networking服务器。 Nginx或Apache的httpd适用于此。

REDIRECT不会将连接redirect到127.0.0.1 ,这是行不通的,因为127.0.0.1不能用于与客户端IP进行通信。

REDIRECT将stream量redirect到数据包到达的接口的IP地址。 您必须显式侦听该IP地址或绑定到任何地址0.0.0.0