相关疑难解决方法(0)

如何将外部 TCP 端口 80 路由到环回 (127.0.0.1) 端口 8080?

我有一个具有真实 IP 的测试 VDS 盒子。如果我在物理接口端口 80 上启动 Web 服务器,则可以通过其 IP 地址(和默认端口 80)从另一台计算机打开它:

python -m SimpleHTTPServer 80
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试将端口 80 从物理接口重新定向eth0到环回 127.0.0.1 端口 8080,我可以从端口 8080 上的另一台计算机连接它,但无法在端口 80 上连接,这只是无休止的“连接”。似乎没有发生重定向:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:8080
python -m SimpleHTTPServer 8080
Run Code Online (Sandbox Code Playgroud)

我做错了什么?:(

PS “127.0.0.1:8080”上的绑定服务器产生相同的结果,但这并不重要,因为在“0.0.0.0:8080”上运行的服务器将接受重定向到“127.0.0.1:8080”的连接。AFAIK。:(

iptables -L结果:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination …
Run Code Online (Sandbox Code Playgroud)

linux firewall iptables port-forwarding

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

firewall ×1

iptables ×1

linux ×1

port-forwarding ×1