Setup Minecraft On FreeBSD 13
Introduction
This guide will explain setting up a Minecraft server on FreeBSD 13.
Requirements
- A Vultr VPS with FreeBSD 13.0, with at least 8 Gb of RAM
1. Install required packages
You'll need to install the following packages:
- Screen, a GNU utility that will allow your server to run in the background
- Nano, a simple command-line text editor
- OpenJDK 17, the required version for Minecraft 1.18
Run the following command to install all of the necessary packages:
# pkg install -y screen nano java/openjdk17
Once completed, run the following command to verify the installation of the JDK:
# java -version
If you see the following, you can proceed to the next step:
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-1)
OpenJDK 64-Bit Server VM (build 17.0.1+12-1, mixed mode, sharing)
2. Enable Firewall
To add an extra layer of security, set up a firewall. This will reduce the attack surface of your server. Furthermore, it'll also mitigate Log4Shell (if you happen to use an older version of Minecraft) and SSH brute force attempts.
In this guide, you'll use Packet Filter (PF) as it comes pre-installed on FreeBSD. To get started, run the following commands to enable PF and its logging service:
# sysrc pf_enable=yes
# sysrc pflog_enable=yes
Next up edit /etc/pf.conf
via the following command:
# nano /etc/pf.conf
Then paste the following rulesets into the file:
# block all incoming requests
block in all
# allow ping requests
pass inet proto icmp all icmp-type echoreq
# allow mc requests
pass in proto tcp from any to any port 25565
# allow all outgoing traffic & their responses
pass out all keep state
# block outgoing LDAP requests, to mitigate Log4Shell
block return out proto { tcp, udp } from any to any port { ldap, ldaps }
# Block rapid-fire brute force attempts
table <bruteforce> persist
block quick from <bruteforce>
# Enable SSH
# Change 22 to whichever port you use
pass in quick proto tcp to any port 22 keep state (max-src-conn 15, max-src-conn-rate 5/3, overload <bruteforce> flush global)
Exit nano
by pressing Ctrl+X, then Y. to save the file.
Finally, start the firewall:
# service pf start
# service pflog start
Note: You might need to reconnect to your SSH session.
3. Create Minecraft user
It is recommended to create a new user specifically for your server to ensure that the Minecraft server does not have root access. Giving a server or application root access poses a security risk.
To create a new user, run the following command and follow everything being prompted:
# adduser
Once finished, switch to that user (change minecraft with the name of the user you created):
# su - minecraft
4. Set up Minecraft
Create a directory for the server
$ mkdir ~/mcserver && cd ~/mcserver
Download Minecraft
Run the following commands to download Minecraft 1.18.1:
$ wget https://launcher.mojang.com/v1/objects/125e5adf40c659fd3bce3e66e67a16bb49ecc1b9/server.jar -O minecraft_server.jar
You can find the download link for the latest version on the Minecraft website
Accept the EULA
This applies to any server after version 1.7.9. By running this command, you agree to the Mojang EULA.
$ echo "eula=true" > eula.txt
Create startup script
To start, create a file called startup.sh
and populate it with the following:
#!/bin/sh
java -Xmx7G -Xms7G -XX:ParallelGCThreads=4 -jar minecraft_server.jar nogui
Save the file, then make it executable:
$ chmod +x startup.sh
Finally, run the following command to start the server:
$ screen sh startup.sh
If all is successful, you will be able to connect to the IP address of your VPS with the Minecraft Java game client. You have just set up Minecraft on FreeBSD 13.