Setting up a Vanilla Minecraft Java Server on Debian 12
Specifications of the Server
The exact machine I used was an ASUS ZenBook Flip 15 Q528. It originally had Windows 10 installed but I've wiped it in favor of Debian 12 for this personal project. The performance of the server was extraordinary since the laptop was more than enough to handle server requirements stated by Mojang. This documentation assumes that the installation of Debian 12 has already been set up and was successful. The particular preseed I used was in the following: preseed
Note that the installation will be done as if the server is headless, so strictly through the command-line. I'm sure it can be done with a GUI, but I want to avoid that for the many benefits the command-line provides. Therefore, this will require some proficiency with the Linux command-line. As always, make sure your installation has been updated and upgraded.
Installing the Server
The Minecraft version I'm focusing on is 1.19.2 since me and my friends want to play on that version. In order to install the server onto your Linux machine, we need server.jar files that correspond to our desired version of Minecraft. Fortunately, Mojang Studios themselves distribute this software for free. The following link is the direct download url for the server.jar file for version 1.19.2:
https://piston-data.mojang.com/v1/objects/f69c284232d7c7580bd89a5a4931c3581eae1378/server.jar
If the version of Minecraft you need is different refer to the official Minecraft wiki to find the corresponding link. Be cautious as some third parties can give you compromised server.jar files, the above domain (piston-data.mojang.com) is owned by Microsoft and Mojang Studios and is therefore safe to download and execute.
Assuming that you have a terminal open and its current directory is the home directory, simpy use the wget command to download the server.jar file directly from the url:
$ wget https://piston-data.mojang.com/v1/objects/f69c284232d7c7580bd89a5a4931c3581eae1378/server.jar
This will download and place the server.jar file in our home directory.
The next step is to install Java onto our machine using the following command:
$ sudo apt install default-jre
After installing Java, we need to make a directory to store the server files, the name doesn't really matter but I'll name it minecraft_server:
$ mkdir minecraft_server
We can then use the mv command to place the server.jar file into the minecraft_server directory. Once this has been done enter the minecraft_server directory and execute the following command:
$ java -Xmx1024M -Xms1024M -jar server.jar nogui
This will launch the server.jar file, which will build the server within the minecraft_server directory. Before we can officially start the server, we must agree to the End-user license agreement or EULA and set up a firewall to monitor our ports for our linux machine.
To agree to the EULA, we must edit the eula.txt file that is now present within the minecraft_server directory.
Simply, use a command line text editor and change the eula value to eula=true.
The reason to set up a firewall is to allow the minecraft server process to communicate with the network by configuring a firewall, I used the firewalld package to configure this. This is to accept connections from outside the Local Area Network, or LAN, or your home network. If you do not plan to have outside connections, you can skip to the next section of starting the server and connecting through LAN. However, if you want online friends to join the server, then proceed.
First install firewalld if it's not installed, then set up the firewall with the following:
$ sudo apt install firewalld
$ sudo firewall-cmd --zone=public --add-port=25565/tcp --permanent
$ sudo firewall-cmd --zone=public --add-port=25565/udp --permanent
$ sudo firewall-cmd --reload
$ sudo firewall-cmd --list-ports
The first two opens the 25565 port for both internet protocols, since changes require the firewalld to restart we use the reload option on the command, and the last command lists the ports verifying that the reload worked.
Starting the Server
The installation is officially completed now that everything is set up. All we need to do is simply reuse the java command we used earlier and the server should start building the Minecraft world and be online. If you forgot here is the java command:
$ java -Xmx1024M -Xms1024M -jar server.jar nogui
To test the server, launch Minecraft, make sure the versions are identical, since this is version 1.19.2 our Minecraft version will also have to be 1.19.2. After this, connecting depends on how you're hosting the server, since I'm hosting on a laptop and I want to connect to the server from a separate desktop in my home, to achieve this I use the ip of the laptop.
You can get the ip of the laptop using the following:
$ ip a
Assuming you only have one network interface, you should look at the ipv4 address of the interface that is not
lo: or Loopback.
If you have multiple (more than 2) network interfaces, look into determining the main network interface by seeing which one is associated with the gateway ip. The exact commands are beyond the scope of this documentation, but that is a good lead to research or google.
Now that we have our LAN ip, it should look relatively something like: 192.168.1.x This is the IP of your server within the LAN. When adding a server in Minecraft through the multiplayer option, the name can be anything, but the ip must match what we found. Note that this will only allow people within your home network to join the server.
If you are running the server and plan to join the server on the same computer, then use "localhost" when adding the server. "localhost" tells your computer that the server is the computer itself. Therefore, you can play minecraft on your computer as it hosts the server, this works for both Windows and Linux. However, its not recommended as you need a strong system to both play on and host the server. Hence why I'm hosting the server on my laptop but joining on my separate desktop system.
To extend the server to people outside your home network, continue to the next section.
Port Fowarding
While using the LAN network might be enough for most people, I want to play with friends that aren't always in my house and have their own computers at home. To achieve this, you have to set up something called port forwarding
Port forwarding allows connections from other computers on a specific port to be sent to the appropiate device that handles that connection. In this case, the laptop is the device that handles all connections for port 25565. Normally, under LAN, the device is known to every other device on the network and thus no port fowarding is needed. However, since my friends' computers are outside my LAN network, I need to tell my router where to send their port 25565 connection requests, which is to my Laptop.
Unfortunately, this cannot be done through the terminal and must be done through your service provider's router. However, here's the general process use the following command to obtain the gateway, or the router ip.
sudo route -n
We then enter this ip into a web browser, this will either give you a dashboard for configuring the router or more information on how to configure the router. In my case, it gave a QR code allowing me to download an app to configure my router from my phone. Once you find out how to set up port forwarding the general information you need is a name for the process, external port, internal port, and protocol. In some cases, you may need the local ip of the server itself, simply use the ip a command to get it.
For name, enter minecraft, anything works
For both external and internal ports, use 25565
For protocol, its best to use both TCP and UDP protocols.
Please refer to your service provider's method of configuring the router.
To check if the port forwarding has worked use the following site or similar sites: https://mcsrvstat.us/ If port-forwarding has worked the site should report that the port is open on your public ip address. Simply searching What is my ip on any web browser should immediately give you your public ip.
Once verified, to have friends join your server once port forwarding has been setup you simply need to provide them your public ip. When having them join, the address should look something like this ww.xx.yy.zz:25565 Obviously, the ww.xx.yy.zz should be replaced with your public ip.
Security
Important Security notes
- Configure the firewall to improve security and disable any unwanted ports
- Create a separate user for the server to run under, this is so the server is isolated, NEVER use sudo to start the server when difficulties are met
- Be cautious when sharing public ip, only give this to those you trust, especially if your server is located at your household
- Always backup your server
- Within the minecraft_server directory, a whitelist file has been created, use it to block unwanted visitors and only accept trusted friends
Automation
The best part about doing this strictly through the terminal is being able to automate everystep. The only step we can't automate is the port forwarding part as that involves a separate interface entirely.
This script automatically installs java, adds the minecraft user, makes the server directory within the home directory of the minecraft user, gets the server.jar file, and makes a text file containing the java command to start the server. The password for the minecraft account is "vm", please change the password something more secure with passwd command.
In addition, switch to the minecraft user, cd into the minecraft_server directory and apply executable
permissions to the start.txt, and use the command $ ./start.txt to start the server. Change the eula.txt file
like before, and repeat the command to set it up. In addition, it sets up the firewall ports,
reloads the firewall, and lists the ports and status of firewalld. It also checks if firewalld has been installed