Introduction
This tutorial shows you how to set up your own Minecraft server on a Hetzner Cloud Server. Tested on Ubuntu 24.04 LTS (as of October 2025)
Prerequisites
- A local device – to connect to the game
- A Hetzner Cloud Server with Ubuntu to host Minecraft
- Access as root or a user with sudo privileges
- Basic configuration, including firewall, should be complete
→ Initial Server Setup with Ubuntu
Example terminology
203.0.113.1– Public IP address of your servermcserver– Example user on the server
Step 1 – Create a new user
It is not recommended to work as root permanently. Instead, create a user with sudo privileges:
adduser mcserver
usermod -aG sudo mcserver
su - mcserverChoose a secure password. You can leave the rest of the information blank.
Step 2 – Prepare the server
Minecraft requires Java and port 25565.
Step 2.1 – Open port 25565
If you are using UFW, activate the rules:
sudo ufw allow proto tcp to any port 25565
sudo ufw allow proto udp to any port 25565
sudo ufw reload
sudo ufw statusIf you are using the Hetzner Cloud Firewall:
| Direction | Protocol | Port | Source |
|---|---|---|---|
| Inbound | TCP | 25565 | Any IPv4 / IPv6 |
| Inbound | UDP | 25565 | Any IPv4 / IPv6 |
You can enter this in the Hetzner Console under Firewalls → Rules.
Step
2.2 – Install Java 21
Minecraft 1.21.1 requires Java 17 or newer. Ubuntu 24.04 provides OpenJDK 21 LTS:
sudo apt update
sudo apt install openjdk-21-jdk-headless -y
java --versionStep 3 – Install Minecraft Server
Create a directory for the server:
mkdir ~/mcraftserver
cd ~/mcraftserverDownload the latest server file – either officially from Mojang or PaperMC (recommended):
PaperMC (recommended):
wget -O server.jar https://api.papermc.io/v2/projects/paper/versions/1.21.1/builds/120/downloads/paper-1.21.1-120.jarOfficial (Mojang):
wget -O server.jar https://piston-data.mojang.com/v1/objects/0d03b59cc3e1eecbcb5b0b6f0c79e6a19c6b01ce/server.jarAccept EULA Start the server once to generate the EULA:
java -jar server.jarThen edit the file:
nano eula.txtChange:
eula=falseto
eula=trueSave with Ctrl + X, Y, Enter.
Step 4 – Start Minecraft Server
Install the screen tool to run the server in the background:
sudo apt install screen -y
screen -S MinecraftServerChange to your server directory:
cd ~/MinecraftServerStart the server (replace
With recommended JVM flags:
java -Xms512M -Xmx<MEMORY>M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+AlwaysPreTouch -jar server.jar noguiExample:
java -Xms512M -Xmx4096M -jar server.jar noguiAs soon as you see the message:
[Server thread/INFO]: Done (X.XXXs)! For help, type “help”the server has started.
Step 5 – Manage screen session
- Exit session: Ctrl + A, then D
- Display all sessions:
screen -list- Return to session:
screen -r mcraftserver- End session:
screen -X -S mcraftserver quitStep 6 – Change server port
If you want to start multiple servers:
nano server.propertiesChange
server-port=25565e.g. to:
server-port=25567Then adjust your firewall rules.
Step 7 – Set up automatic restart
Create a start script that automatically restarts the server in case of a crash:
cat <<‘EOF’ > ~/mcraftserver/run.sh
#!/bin/bash
while true; do
java -Xms512M -Xmx4096M -jar server.jar nogui
echo “Server will restart in 5 seconds – CTRL+C to cancel.”
sleep 5
done
EOF
chmod +x ~/mcraftserver/run.shStart the server with the script:
./run.shStep 8 – Connect to the server
Start Minecraft → Multiplayer → Add Server Enter the following address:
<your-server-ip>or with port:
<your-server-ip>:<port> Example:
203.0.113.1:25567If you are playing locally:
localhost:25565Conclusion
You have successfully set up your own Minecraft server on a Hetzner Cloud Server. You can now make further adjustments in the server.properties file, install plugins via PaperMC, or set up automatic backups. For better performance, we recommend using PaperMC's JVM optimizations.