大网数据广告活动
服务器运维问答

Forward traffic with iptables without exposing real IP/Port

· 52CE 我爱测

I want to forward traffic with iptables without showing a different ip/port to sending host. My application listens on host x.x.15.42, port 23555 using TCP. The client will be connecting to x.x.15.42:5555. I want the connection t…

问题原文

原帖链接 · mrmc · CC BY-SA 4.0

I want to forward traffic with iptables without showing a different ip/port to sending host.

My application listens on host x.x.15.42, port 23555 using TCP. The client will be connecting to x.x.15.42:5555. I want the connection to be forwarded to port 23555 without exposing that port to the client.

I already tried using DNAT:

iptables -t nat -A PREROUTING -p tcp --dport 5555 -j DNAT --to-destination x.x.15.42:23555

But to the client it will show that they're connecting to port 23555.

I also tried using REDIRECT, but for some reason that doesn't work at all. The client can't connect.

iptables -t nat -A PREROUTING -p tcp --dport 5555 -d x.x.15.42 -j REDIRECT --to-port 23555

How do I forward this traffic while making it look like the application is listening on port 5555?

已采纳解答

原帖链接 · mrmc · CC BY-SA 4.0

So the first firewall rule I used works:

iptables -t nat -A PREROUTING -p tcp --dport 5555 -j DNAT --to-destination x.x.15.42:23555

The only problem was indeed that the server was telling the client to connect to port 23555 instead of port 5555 like I wanted. Changing that on the server part fixes the issue.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-08-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。