Setting Up a Minecraft Proxy

• minecraft, servers, proxy

Why?

Because I found myself running multiple Minecraft servers out of my basement, and didn't want to have to have two different entries in my Minecraft game client for each server (on LAN, and off LAN). Rather than having multiple ports and port forwards, I created a couple DNS entries (CNAME) externally and internally, pointed them to the machine running the proxy I describe below, and now I use the same server names and ports no matter where I play from.

The Fine Details

All The Mods (ATM) and SkyFactory (SF) are two Minecraft modpacks I run servers for, mainly for me and my son to play in. We both want the ability to play from anywhere (naturally). I wanted to have a system that made it really easy for me to manually maintain (I don't need a control panel setup and all that fancy stuff; it's not hard to ssh into a machine and do basic maintenance). I have two separate networks on which two different gameservers reside, and those networks share an internet connection. I have a server that bridges the two networks which runs the proxy. Minecraft traffic can come from outside the LAN or inside the LAN. Firewall sends Minecraft traffic to the proxy, the proxy looks at the requested hostname (hence the DNS stuff earlier), and sends the traffic to the appropriate backend from the perspective of the proxy. Done.

Docker-based

This guide assumes you have docker installed where you want to run the proxy, assumes you have the docker compose toolset working, and assumes that you can edit YAML files.

The docker compose file uses Minekube's Gate Lite.

services:
  minecraft_proxy:
    container_name: minecraft_proxy
    image: ghcr.io/minekube/gate:latest
    restart: unless-stopped
    volumes:
      - ./config.yml:/config.yml
    ports:
      - "25565:25565"

Whatever you set in the left side of your single ports entry (25565 by default) will be the port you point your router's port forwarding to.

Now you need to create your config file (config.yml) in the same directory.

config:
  lite:
    enabled: true
    routes:
      - host: mc-sf.myhostname.com:25565
        backend: 192.168.0.1:25565
      - host: mc-atm.myhostname.com:25565
        backend: 192.168.0.2:25565

Next it's just docker compose up -d to bring up the docker container in the background, and docker compose logs -f if you want to watch the logs. Note that you can't run the proxy AND a game server BOTH on the same port on the same IP address. Keep that in mind if you get port conflicts or errors.

If you want to bring down the proxy, docker compose down.