AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-939389

AAron's questions

Martin Hope
AAron
Asked: 2021-11-19 06:47:06 +0800 CST

iptables 端口转发,同时保留客户端 IP

  • 0

TL;DR:如何让连接到远程托管 VPS 的客户端 IP 成为通过 iptables 转发/nat 到我家运行的游戏服务器的 IP?

我在家里托管了一个 Rust 游戏服务器。我希望将其公开,但我不一定想向所有人提供我的 IP 地址。所以我租了一个小型 VPS,它打算基本上用作反向代理。我目前正在使用 nginx 通过 clinet-server VPN 转发流量,效果很好。但是,在游戏服务器上,每个玩家的 IP 都是 VPS 的隧道地址,而不是实际的客户端 IP。我尝试proxy_pass $remote_addr:28015 transparancy; proxy_responses 0在我的 nginx 配置中使用,没有变化。所以我然后切换到通过 iptables 来做。

我可以按照我想要的方式让它工作 99%,就是这样做的:

sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 28015 -j NAT --to-destination my_ip:28015
iptables -t nat -A PREROUTING -p udp --dport 28015 -j NAT --to-destination my_ip:28015
iptables -t nat -A PREROUTING -p tcp --dport 28016 -j NAT --to-destination my_ip:28016
iptables -t nat -A PREROUTING -p udp --dport 28016 -j NAT --to-destination my_ip:28016
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -p tcp -d my_ip --dport 28015 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p ucp -d my_ip --dport 28015 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
ufw disable
ufw enable
vps reboot \

它的作用与 nginx 基本相同,它工作正常,但每个人都只有 VPS 的公共 ip(注意,VPS 的 LAN 和公共 ip 地址是相同的)。如果我省略化装舞会,它就不起作用。

有关设置的一些信息:
VPS 有一个界面:eth0
VPS 正在运行Ubuntu 20.04
在我家,调制解调器处于通向 pfsesne 的通路模式。在 pfsense 上,我有端口转发规则将 28015/28016 tcp/udp 传递到gameserver.

旁注:我不确定为什么 nginx 不能为此工作。几乎就像 nginx 对proxy_pass $remote_addr指令什么都不做一样。

nat port-forwarding iptables nginx
  • 1 个回答
  • 467 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve