Running a Minecraft Server on Raspberry Pi
Minecraft is a sandbox video game developed my Mojang. It is one of the most popular video games in the world. In Minecraft Wikipedia page, it introduces:
In Minecraft, players explore a blocky, procedurally-generated 3D world with infinite terrain, and may discover and extract raw materials, craft tools and items, and build structures or earthworks. Depending on game mode, players can fight computer-controlled “mobs“, as well as cooperate with or compete against other players in the same world. Game modes include a survival mode, in which players must acquire resources to build the world and maintain health, and a creative mode, where players have unlimited resources. Players can modify the game to create new gameplay mechanics, items, and assets.
If you want to play with your friends, an doable method is to pay $14.99 for an official server. Fortunately, we can also set up the server on Raspberry Pi with almost zero cost.
Java or Bedrock?
Notice there is two version of Minecraft. Java edition uses Java language and works only on PC. Bedrock edition uses C++ and works on Android, iOS, Nintendo, and Win10 PC. It is easy to set a multilayer server on Java edition. Just run the following command:
1 |
|
However, I want the server have a wider device compatibility, so I decide to set up a Bedrock server. Unfortunately, it only works on Windows or Ubuntu 64-bit system. For some unknown reason, though Raspberry Pi 4B has a 64-bit CPU, its operating system Raspbian is still 32-bit. I manage to install a third-party Debian but still cannot run the Ubuntu package.
So I have to use third-party server package. And here it is, https://getbukkit.org/
Configuration
1 After downloading the jar file, FTP the file to Raspberry Pi
2 Writing a sh script to simply the start up process. As you need to allocate the RAM every time.
1 |
|
Type in:
1 |
|
After done, Ctrl+O to write the file and Ctrl+X to exit.
Note that -Xms and -Xmx indicate the maximum and minimum RAM the server can use. nogui means run without user interface.
Running the server
1 |
|
The sever cannot run successfully at first time as you need to agree the EULA statement first. Stop the server, open eula.txt with nano:
1 |
|
Change eula to true:
1 |
|
Run the server again:
1 |
|
And the server is running!
Change server properties
Open server.properties with nano:
1 |
|
The server properties can be changed in the file. These is the explanation from Offical Minecraft Wiki
1 |
|
Port Forwarding on Ngrok
You may notice the server can only be found in local network. How can I invite friends all around the world to the server? Port forwarding is a easy option.
In computer networking, port forwarding or port mapping is an application of network address translation (NAT) that redirects a communication request from one address and port number combination to another while the packets are traversing a network gateway, such as a router or firewall. This technique is most commonly used to make services on a host residing on a protected or masqueraded (internal) network available to hosts on the opposite side of the gateway (external network), by remapping the destination IP address and port number of the communication to an internal host. —From Wikipedia
Port forwarding can be set by logging in the wifi configuration page. The step may be varying for different network providers. I set up easily on my Rogers wifi–just a few clicks.
Port forwarding doesn’t work?
In some cases, network providers disable port forwarding as they have limited IP address. In this case, we can use Ngrok VPN tunnel instead.
Ngrok exposes local servers behind NATs and firewalls to the public Internet over secure tunnels. –From Ngork
Set up Ngrok is also straight-forward.
1 Register an account on Ngrok website and go to https://dashboard.ngrok.com/get-started/setup. Download Linux(ARM) file. FTP to Raspberry Pi and unzip
2 Add your authtoken.
1 |
|
3 Start tunnel. Note that Minecraft server uses tcp and port 25565. If you want to forward website or email services, notice they uses different agreement and different port.
1 |
|
4 Check the tunnel IP address on https://dashboard.ngrok.com/endpoints/status. Enter the IP address in Minecraft. The server should be able to connect.
Multilayer is also supported.