Trying to tunnel Minecraft

Hello, I’ve been trying for several days to establish a tunnel with my Minecraft server (non-HTTP) to a subdomain. I’ve read the non-HTTP documentation and several forums, but I can’t get it to work. I think I’m forgetting something or doing something wrong. The server works fine locally.

Procedure:

Server:

  1. I create the tunnel using Cloudflare’s web interface (/networks/tunnels).
  2. I download Cloudflared.
  3. I establish the tunnel: sudo cloudflared service install {token}.
  4. I add the DNS CNAME record: minecraft.{mydomain}.com pointing to {id_tunnel}.cfargotunnel.com.

Output:

shell

Copiar código

2024-08-09T21:50:49Z INF Using SysV
2024-08-09T21:50:49Z INF Linux service for cloudflared installed successfully

Client (Windows desktop):

  1. I download Cloudflared.
  2. I run cloudflared access tcp --hostname minecraft.{mydomain}.com --url localhost:25565.

Output:

shell

Copiar código

2024-08-09T21:43:04Z INF Start Websocket listener host=localhost:25565

When I try to connect with the Minecraft client, it says “connection refused.”

I tried checking if there is any trace using the following command:

powershell

Copiar código

Test-NetConnection -ComputerName localhost -Port 25565 -InformationLevel Detailed

Warning:

shell

Copiar código

TCP connect to (::1 : 25565) failed

Cloudflared logs:

shell

Copiar código

2024-08-09T21:51:47Z ERR failed to connect to origin error="dial tcp: lookup fastminecraft.{mydomain}.com: getaddrinfow: The requested name is valid, but no data of the requested type was found." originURL=https://minecraft.{mydomain}.com

I can trace the domain, but I can’t connect to Minecraft. What might I be overlooking?

hi did u ever figure out how to get this working im trying the same thing with a sock error on connect

Wondering the same thing and come across this post and your comment.

I have a domain that I own,

I managed to get this working but having a few technical difficulties with it, will require confirmation from players tomorrow to see if its on my end or theirs, I can connect to the server locally and via mc. but having connection issues on my end, but when I join via its local IP: 192.168.0.183:25565 I have no problems.

You can definitely tunnel a minecraft server, but I’m still in the process of working out fixing issues.

Did you ever get a reply from your players if it worked?

Yeah I did.

So it’s not possible to do this through a tunnel.

But you can use Cloudflare Spectrum which is essentially made for Minecraft servers. It does cost, but not much. Other then that the only thing you can do is, get a Static IP from your ISP and run it through spectrum (or your exposing your IP), and point your domain to it, so for me:

mc.braydon.id.au (just an example) points to my Public IP Address.

All other services like Crafty Controller and BlueMap have no issues with being connected through a tunnel. I think its just TCP/UDP traffic that has issues.

Ran into the same thing as you, this is honestly insane. They should actually state this somewhere

First make sure your server tunnel is set up correctly

  • cloudflared on server you setup normally on Zero Trust > Networks > Tunnels
  • Install the server tunnel when you create the tunnel
  • Add a public hostname
  • Point it to the minecraft server on the server
    • tcp://localhost:25565

Setup cloudflared on the client to tunnel traffic through cloudflare

  • winget install --id Cloudflare.cloudflared
    • This works on Windows 10 1709+ and Windows 11
    • It directly syncs with an MSI install for installing and uninstalling. It also does auto-updates if you run the command again.
  • cloudflared access tcp --hostname minecrafttun.example.com --url localhost:25565
    • Arbitrary TCP · Cloudflare Zero Trust docs
    • The URL is the url on the client that will be proxied through the tunnel. It has to be a hostname that resolved to this computers IP (localhost or other host names)
    • Most people will just use localhost to proxy through the tunnel, but if other PCs want to use the tunnel on the local network or through a port forward, then you could use it’s host name.
    • You don’t need a SRV record, as long as the port and host name is accessible on the tunnel client.

To connect on the client to the host minecraft server, you just type localhost (which will go to port 25565 by default for minecraft)

So you could script a powershell, cmd, or shortcut in Windows that runs winget, and then runs cloudflared access tcp. You could run a scheduled task to auto update cloudflared and create the tunnel.

If you want to do a direct IP exposure of your home router, you can:
Create an A record, but proxy it, so it is hidden from browsers directly querying it.

A minecraftd (Your External IP Address ex. 192.0.2.1) ProxyYes TTL Auto

Then create a SRV record
| Type | Name | Priority Weight Port Target | Proxy Status | TTL |
| SRV | _minecraft._tcp | 10 5 25565 minecraftd.example.com | DNS only | Auto |

The target has to be fully qualified, and the name needs the _service._protocol, but is relative to your domain.

When an app like minecraft uses an SRV, it looks for the _service._protocol and uses that port and that target. so in this case example .com would point to minecraftd.example .com which points to the IP address.

Lastly you will have to port forward on your router to the PC hosting the server (or in your case, a crypto pool)

Also for the SRV DNS method with an A record. I used GitHub - fire1ce/DDNS-Cloudflare-PowerShell: Cloudflare DDNS PowerShell Script for Windows OS. Choose any source IP address to update external or internal (WAN/LAN). Cloudflare’s options proxy and TTL configurable via the parameters. to update my DNS on cloudflare and run it as a scheduled task.

Ignore the crypto pool part, that was me copying from my other reply on another post.