ubuntu 端口转发,总显示 Connection refused

234 天前
 samohyes

各位大佬,请教个端口转发的问题。 我这边有服务运行在本地的 127.0.0.1: 8545 ,机子内网 ip 是 192.168.0.5 。我需要将所有到 192.168.0.5: 8549 的请求转发到 127.0.0.1:8545. 于是我使用 iptables 添加了如下规则并 save 。

iptables -t nat -A PREROUTING -d 192.168.0.5 -p tcp --dport 8549 -j DNAT --to-destination 127.0.0.1:8545
iptables-save

同时我确保 ufw 8549 打开了。

ufw allow 8549
~# ufw status
Status: active

To                         Action      From
--                         ------      ----
8549                       ALLOW       Anywhere                  
8549 (v6)                  ALLOW       Anywhere (v6)             

但是我 curl 依旧显示 connection refused

curl http://192.168.0.5:8549/ 
curl: (7) Failed to connect to 192.168.0.5 port 8549: Connection refused

求大佬们指点一下!

916 次点击
所在节点    程序员
3 条回复
pagxir
234 天前
不能用 127 开头,那个是回环地址
sduoduo233
233 天前
是不是 forwarding 没开
看看/etc/sysctl.conf 有没有 net.ipv4.ip_forward=1
secssion
231 天前
配置了 dnat , 也要配置回包的 snat

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/978065

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX