You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将本地Windows的Terraria服务器端口转发至Linux VPS?

实现Terraria跨端端口转发(TCP+UDP)

下面提供两种可靠的实现方式,分别基于SSH反向隧道(无需额外工具,适合快速部署)和frp(更稳定,适合长期运行)。

方案一:使用SSH反向隧道

Linux VPS 端配置

  1. 检查OpenSSH版本:UDP反向隧道需要OpenSSH 7.6及以上版本,执行以下命令确认:

    ssh -V
    

    版本不足的话,通过包管理器升级(如Debian/Ubuntu用apt update && apt install openssh-server)。

  2. 修改sshd配置:允许外部访问转发的端口,编辑/etc/ssh/sshd_config:

    GatewayPorts yes  # 允许外部连接转发的端口
    

    保存后重启sshd服务:

    systemctl restart sshd
    
  3. 开放防火墙端口:确保VPS防火墙允许7777端口的TCP和UDP流量(以ufw为例):

    ufw allow 7777/tcp
    ufw allow 7777/udp
    ufw reload
    

Windows 端操作

Windows 10/11自带OpenSSH客户端,若没有可通过「设置-应用-可选功能」安装,或使用Git Bash中的ssh命令。

执行以下命令建立双向(TCP+UDP)反向隧道:

ssh -Nf -R 0.0.0.0:7777:localhost:7777 -R 0.0.0.0:7777:localhost:7777/udp root@你的VPS_IP

参数说明:

  • -N:仅建立隧道,不执行远程命令
  • -f:后台运行
  • -R 0.0.0.0:7777:localhost:7777:将VPS的7777 TCP端口转发到本地Windows的7777端口
  • -R .../udp:对应UDP协议的转发规则

如果VPS的SSH端口不是默认22,添加-p 自定义端口参数即可。

验证

在VPS端执行以下命令,确认7777端口的TCP和UDP均被监听:

ss -tulpn | grep 7777

方案二:使用frp(更稳定的长期解决方案)

frp是专门的端口转发工具,支持TCP/UDP,且自带断线重连、后台运行等功能。

Linux VPS 端配置

  1. 下载并解压frp:根据VPS架构(x86/arm)下载对应版本,示例:

    wget https://github.com/fatedier/frp/releases/download/v0.51.3/frp_0.51.3_linux_amd64.tar.gz
    tar -zxvf frp_0.51.3_linux_amd64.tar.gz
    cd frp_0.51.3_linux_amd64
    
  2. 编辑frps.ini(服务端配置):

    [common]
    bind_port = 7000          # frp服务端与客户端的通信端口(TCP)
    bind_udp_port = 7000      # 支持UDP转发需开启此端口
    token = 你的自定义密钥    # 用于验证客户端连接,建议设置复杂值
    
  3. 启动frps并设置后台运行:

    # 直接启动(测试用)
    ./frps -c ./frps.ini
    # 或配置systemd服务长期运行(可选)
    sudo cp frps /usr/bin/
    sudo cp systemd/frps.service /etc/systemd/system/
    sudo systemctl enable --now frps
    
  4. 开放防火墙端口:

    ufw allow 7000/tcp
    ufw allow 7000/udp
    ufw allow 7777/tcp
    ufw allow 7777/udp
    ufw reload
    

Windows 端配置

  1. 下载并解压frp:下载对应Windows版本的frp,解压后得到frpc.exe和frpc.ini。

  2. 编辑frpc.ini(客户端配置):

    [common]
    server_addr = 你的VPS_IP
    server_port = 7000
    token = 你的自定义密钥  # 需与服务端一致
    
    [terraria_tcp]
    type = tcp
    local_ip = 127.0.0.1
    local_port = 7777
    remote_port = 7777
    
    [terraria_udp]
    type = udp
    local_ip = 127.0.0.1
    local_port = 7777
    remote_port = 7777
    
  3. 启动frpc:

    • 直接双击frpc.exe测试,或在命令行执行:
      frpc.exe -c frpc.ini
      
    • 若需开机自启,可将frpc注册为Windows服务(可借助nssm工具实现)。

验证

同样在VPS端执行ss -tulpn | grep 7777,确认端口监听状态。


通用注意事项

  1. Windows本地防火墙需允许Terraria Server的7777端口进出,或直接允许TerrariaServer.exe的网络权限。
  2. 若使用frp,确保VPS和Windows端的frp版本一致,避免兼容性问题。
  3. 好友连接时,直接输入VPS的IP地址和7777端口即可加入Terraria服务器。

内容的提问来源于stack exchange,提问作者thebluetropics

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 19:43:16