Setting Up a Minecraft Server Using FreeBSD Jails: A Step-by-Step Guide

In today’s technology-driven world, the gaming community continues to expand and evolve. One of the most requested topics from my son was how to set up a Minecraft server using FreeBSD Jails. This approach is similar to using Docker or Podman containers on Linux, but it provides a more secure environment for hosting your games.
\\n\\nPreparation Steps
\\nTo kick things off, we need to create the necessary directories and download the FreeBSD Base System version required for our Minecraft server setup. For this guide, we will use the 14.2-RELEASE
version of FreeBSD UNIX.
host # mkdir -p /jail/minecraft /jail/BASE
\\nhost # VER=$( freebsd-version | awk -F \'-\' \'{print $1 "-" $2}\' )
\\nhost # fetch -o /jail/BASE/${VER}-base.txz https://download.freebsd.org/releases/amd64/14.2-RELEASE/base.txz
\\n\\nWith the base system in place, we will proceed to create a dedicated FreeBSD Jail specifically for our Minecraft server. It is crucial that we also copy the /var/run/dmesg.boot
file, as the Minecraft server requires it to function correctly.
host # tar -C /jail/minecraft --unlink -xvf /jail/BASE/14.2-RELEASE-base.txz
\\nhost # cp /var/run/dmesg.boot /jail/minecraft/var/run/
\\n\\nConfiguring the FreeBSD Jails
\\nNext, we will establish the base configuration for FreeBSD Jails. This configuration will be the default for all future Jails unless they are redefined with new settings.
\\n\\nhost # cat /etc/jail.conf
\\nexec.start = "/bin/sh /etc/rc"; exec.stop = "/bin/sh /etc/rc.shutdown"; exec.consolelog = "/var/log/jail_console_${name}.log"; exec.clean; mount.devfs;
\\n\\nFor our specific Minecraft Jail, we will utilize the em0
LAN interface with an allocated IP address of 10.0.0.210
.
host # cat /etc/jail.conf.d/minecraft.conf
\\nminecraft { # GLOBAL exec.start = "/bin/sh /etc/rc"; exec.stop = "/bin/sh /etc/rc.shutdown"; exec.consolelog = "/var/log/jail_console_${name}.log"; exec.clean; mount.devfs; host.hostname = ${name}; path = /jail/${name}; # CUSTOM ip4.addr = 10.0.0.210; interface = em0; allow.raw_sockets; allow.sysvipc; devfs_ruleset=210; allow.mount; enforce_statfs=1; allow.mount.devfs; allow.mount.procfs; allow.mount.fdescfs; }
\\n\\nMoreover, the following /etc/devfs.rules
ruleset on the host provides the necessary permissions:
host # grep -A 4 minecraft /etc/devfs.rules
\\n[minecraft=210] add include $devfsrules_jail add path \'fd*\' unhide
\\n\\nStarting the Minecraft Jail
\\nWe are now ready to start our new Jail.
\\nhost # service jail onestart minecraft
\\nTo check if the jail has started successfully, we can use the following command:
\\nhost # jls
\\nJID IP Address Hostname Path 1 10.0.0.210 minecraft /jail/minecraft
\\n\\nFor those interested, you can also utilize the jmore(8)
tool to view your jails more interactively.
host # jmore JAIL JID TYPE VER DIR IFACE IP(s)
\\n\\nTo ensure that our Minecraft Jail starts automatically at boot, we need to add the following lines to the /etc/rc.conf
file:
host # grep jail /etc/rc.conf
\\njail_enable=YES jail_devfs_enable=YES jail_list="minecraft"
\\n\\nEntering the Minecraft Jail
\\nAt this point, we can enter the Minecraft Jail using the following command:
\\nhost # jmore minecraft c
\\nThis command is equivalent to executing env PS1=\'minecraft # \' jexec minecraft /bin/sh
.
Next, we need to configure basic settings such as DNS and update the package manager’s branch to the latest version.
\\nminecraft # echo nameserver 1.1.1.1 > /etc/resolv.conf
\\nminecraft # mkdir -p /usr/local/etc/pkg/repos
\\nminecraft # sed -e \'s|quarterly|latest|g\' /etc/pkg/FreeBSD.conf > /usr/local/etc/pkg/repos/FreeBSD.conf
\\nminecraft # pkg search -o minecraft games/minecraft-client Client for the block building game
\\n\\nWe will now proceed to install the necessary packages required to build the Minecraft server using FreeBSD Ports. The installation process includes accepting or ignoring license agreements manually.
\\nminecraft # pkg install gitup bsddialog ccache portconfig openjdk21 tmux jless
\\n\\nBuilding the Minecraft Server
\\nTo begin building the Minecraft server, we must first fetch the FreeBSD Ports tree with the gitup
tool. During the configuration process, make sure to select the DAEMON
option.
minecraft # gitup ports
\\nminecraft # cd /usr/ports/games/minecraft-server
\\nminecraft # make config
\\n\\nFollow the on-screen prompts to ensure the proper configuration.
\\n\\nFinalizing Minecraft Server Setup
\\nBefore we start the Minecraft server, we need to modify some settings in the configuration files. Add additional virtual filesystems to the /etc/fstab
file to ensure they are automatically mounted during the Jail\'s startup process.
minecraft # cat << FSTAB >> /etc/fstab
\\nfdesc /dev/fd fdescfs rw 0 0 proc /proc procfs rw 0 0
\\nminecraft # echo \'mount -a\' >> /etc/rc.local
\\nminecraft # mount -a
\\n\\nWe also need to configure the primary /etc/rc.conf
file for the Minecraft server, noting down the necessary options.
minecraft # cat << RC >> /etc/rc.conf
\\nminecraft_enable=YES
\\nminecraft_mems=1024M
\\nminecraft_memx=1024M
\\nRC
\\n\\nAdditionally, we must accept the EULA and configure the primary server properties at /usr/local/etc/minecraft-server/server.properties
.
minecraft # echo eula=true > /usr/local/etc/minecraft-server/eula.txt
\\nminecraft # cat << MINECRAFT > /usr/local/etc/minecraft-server/server.properties
\\nenable-jmx-monitoring=false
\\nrcon.port=25575
\\nmotd=FreeBSD Minecraft Server
\\nserver-ip= 10.0.0.210
\\nserver-port=25565
\\nmax-players=20
\\nlevel-name=world
\\nallow-flight=false
\\nMINECRAFT
\\n\\nStarting the Server
\\nWith everything configured correctly, we can now start the Minecraft server:
\\nminecraft # service minecraft start
\\nminecraft # service minecraft status
\\nTo verify that the server is running, we can check the list of open sockets:
\\nminecraft # sockstat -l4
\\n\\nIf you encounter issues, try running the server directly to debug any problems:
\\nminecraft # su mcserver -c \'/usr/local/bin/java -Xmx1024M -Xms1024M -jar /usr/local/minecraft-server/server.jar nogui\'
\\n\\nConnecting with Minecraft Client
\\nEnsure your Minecraft client is running the same version as the server — in this case, 1.21.4
. When setting up your client, navigate to the Multiplayer option, click Add Server, and enter your server\'s name and IP address. Upon joining the server, you will see the message "Connecting to the server…" and shortly after, you should be in.
Managing Users and Admins
\\nAs I am not a Minecraft expert, it took me some time to figure out how to define administrators for the server. Initially, I attempted to use the jless(8)
tool, which is designed for JSON management. Fortunately, I\'ve found a working solution.
When a player connects to the server, their name and UUID are added to the /usr/local/etc/minecraft-server/usercache.json
file:
host # cat /jail/minecraft/usr/local/etc/minecraft-server/usercache.json | tr \',\' \' \'
\\nTo grant admin privileges, add their UUIDs to the /usr/local/etc/minecraft-server/ops.json
file and restart the Minecraft server for the changes to take effect.
host # jless /jail/minecraft/usr/local/etc/minecraft-server/ops.json | cat
\\nLevel 4 permissions provide the highest level of authority within the server, allowing my son to utilize commands like /gamemode
or /time
.
Final Thoughts
\\nThis setup offers a robust and secure environment for running a Minecraft server. Feel free to share your thoughts regarding additional configurations or enhancements needed for a personal Minecraft server experience.
\\n\\nUpdate: FreeBSD Jails vs. Linux Podman
\\nThe initial discussion on this topic spurred considerable interest, prompting a deeper examination of the security differences between FreeBSD Jails and Linux Podman containers. While both have their merits, FreeBSD Jails generally provide enhanced security measures out-of-the-box compared to Podman. Isolation capabilities, kernel syscall surfaces, and firewall functionalities favor Jails, particularly when additional layers of security are incorporated.
\\nTo summarize, FreeBSD Jails stand as a well-established solution since their introduction in the late 1990s, with extensive real-world testing making them a top choice for server management in a secure environment.