Minecraft Server On Raspberry Pi 4

This guide will show you how to install a Minecraft Server on Raspberry Pi4. Ubuntu 20.10 is used for the operating system however instructions should be similar for Ubuntu 18. This guide uses James Chambers’ excellent resources for easy install of the Minecraft software.

Table of Contents

    Requirements

    This guide assumes you are familiar with operation of a Raspberry Pi, writing images to SD cards, and accessing the Raspberry Pi via SSH. It also assumes you have admin access to your local modem/router for configuring port forwarding.

    It is recommended to use Raspberry Pi 4 with at least 2GB of RAM.

    1. Installation of Ubuntu Server on Raspberry Pi

    The following are instructions for installation of a secure 64-bit Ubuntu Server 20.10 on Raspberry Pi 4 with firewall.
    Ubuntu 20.04.1 LTS can also be used.

    Ubuntu Installation on SD card

    1. Download & Extract Ubuntu Server 20.10 64-bit Version
    2. Download & Install Raspberry Pi Imager v1.4 Software
    3. Write Ubuntu Image to SD card
    4. Insert SD card into Raspberry Pi

    Ubuntu Setup with Headless Operation + Ethernet Connection

    This guide assumes Raspberry pi is connected via ethernet and we will access via SSH.
    This guide gives instructions for creating a new user and for updating the hostname. These two items are optional.
    We are going to be exposing your pi to the internet outside of your local modem/router so we will setup a firewall to block access except for the single port use by the Minecraft game to connect to the server.

    1. Power up Raspberry Pi
    2. Wait a couple of minutes for initial bootup
    3. Determine local IP address of Raspberry Pi using your favorite method
      • login into your router and check the DHCP client list. Default hostname of the Pi is ubuntu
      • Fing is nice application on Android that I like to use.
    4. Open SSH connection. Putty is a good application for windows
      • Default login
        • user: ubuntu
        • password: ubuntu
      • On first login you will be asked to change default password
      • After changing password restart the SSH session with the new password
    5. Login with new password
    6. Switch to root environment
      • sudo -i
    7. Obtain latest versions of installed packages
      • apt update
    8. update all installed packages
      • apt upgrade
    9. Add new user admin. It will ask for password.
      • adduser admin
      • usermod -aG sudo admin
      • exit
      • exit
    10. Close SSH connection and login using new account
      • user: admin
      • password: your password
    11. Switch to root environment
      • sudo -i
    12. Delete ubuntu user
      • deluser ubuntu
      • rm -rf /home/ubuntu
    13. Configure basic firewall to close all ports except for SSH and Minecraft Server port. In a later section of the guide we will open up port 25565 to the internet however we will keep SSH port available for local network access only.
      • ufw allow 22
      • ufw allow 25565
      • ufw enable
    14. Optional: Open file and change hostname from ubuntu to minecraft.
      • nano /etc/hostname
    15. Optional: Open file and add this line: 127.0.0.1 minecraft
      • nano /etc/hosts
    16. Update Time Zone. Configure your specific timezone according to this guide – https://linuxize.com/post/how-to-set-or-change-timezone-on-ubuntu-18-04/
      • To get list of available timeszones:timedatectl list-timezones
      • Configure Timezone Example: timedatectl set-timezone America/Cambridge_Bay
    17. Find MAC address. This will be used later. The address will be after the line starting with link/ether
      • ip address show
    18. Reboot with new settings
      • reboot

    2. Configure DHCP Reservation

    The locally IP address of your Minecraft Server may change over time if your router or Pi is rebooted. Prior to configuring Port Forwarding it is best to reserve a permanent local address.

    In the advanced setting of your router look for DHCP Reservation settings. It will look something like this. Select the MAC address and IP address of your Pi and save.

    3. Port Forwarding

    The Minecraft server communicates to the players via internet port 25565. This is normally blocked so you need to reconfigure this in your router.

    The Port Forwarding configuration in your router should like similar to the screenshot below. In this case port 25565 has been forwarded to local IP address 192.168.1.90.

    4. Install Minecraft server

    James Chambers has a great installation script. The following instructions are based on his guide. See his guide for more details.

    1. SSH using user admin
    2. download james’ script
      wget https://raw.githubusercontent.com/TheRemote/RaspberryPiMinecraft/master/SetupMinecraft.sh
    3. make script executable
      chmod +x SetupMinecraft.sh
    4. run setup script
      ./SetupMinecraft.sh

    The script will setup the Minecraft sever and ask you some questions on how to configure it.

    • Use the recommended memory allocation settings.
    • I found that the automatic reboot was not working correctly so I disabled this feature. I haven’t had a chance to debug.
    • If you enable the Minecraft server to startup automatically on boot it will also do a backup before starting.

    5. Start, Stop and Restarting Server

    The server is setup to autostart on boot.
    If you need to manually configure use the following:

    cd ~/minecraft
    ./start.sh
    ./stop.sh
    ./restart.sh

    -OR-

    sudo systemctl start minecraft
    sudo systemctl stop minecraft
    sudo systemctl restart minecraft

    To switch to server console screen

    screen -r minecraft

    To detach from sever console screen

    ctrl-A then ctrl-D

    To view running screens

    screen -list

    To edit server properties

    cd minecraft
    nano server.properties