We decided to try out minecraft as a family. Our setup includes a half dozen devices (some iOS, some android, Xbox one, etc) with users spread out across the country.
Rather than pay for a realms subscription, we chose to host our own server. Besides being cheaper this gives us flexibility and control over the world data.
Run the docker container (we used the Bedrock Minecraft Server):
docker run -d -e EULA=TRUE --name cworld -e GAMEMODE=creative -e DIFFICULTY=normal -e SERVER_NAME=fenhome2 -v /home/<user>/data:/data -p 127.0.0.1:19132:19132/udp itzg/minecraft-bedrock-server
Note 1 – I purposefully run the minecraft server only the localhost – not on the public IP. More on this later.
Note 2 – I specify a volume for the data. This lets you preserve minecraft state across server restarts and allows you to port it to other servers easily. Replace <user> with your username on your server.
For the sake of security we would like to allow access to only the clients that we specifically want to allow. To do this I found the easiest thing is to use one firewall-cmd per allowed host:
firewall-cmd --direct --add-rule ipv4 nat PREROUTING 0 -s <allowedHostIp>/32 -p udp --dport 19132 -j DNAT --to-destination <dockerIp>:19132
Substitute the ip of the allowed host in place of <allowedHostIp>. To find your ip just go to http://whatismyip.com. The <dockerIp> can be found with the following command:
docker exec -it cworld ip addr | grep 172
Connecting Android/iOS Clients
Its really easy to connect Android and iOS clients. Just click on the servers tab (shown here):
Then click on the “Add Server” button.
You will fill in the server name with whatever you want, however the hostname and port will be the hostname of your server and port (19132 in this example). See this example:
Connecting XBox One Clients
XBox clients are more challenging than Android/iOS because they don’t have the “Add Server” button. However there is still a way to make it work! The magic involves adding a “network proxy” on your network that tricks the XBox into thinking there is a local server. The XBox connects to this proxy which forwards traffic to your server.
- Download phantom from https://github.com/jhead/phantom
- Inside your phantom checkout run
- Copy phantom_windows.exe to your windows box.
- On your windows box type:
- In your console type
cd <path to downloaded phantom-windows.exe">
phantom-windows.exe -server <server>:19132
- If prompted by windows to allow phantom through your firewall say “yes.”
IMPORTANT: You will need to ensure phantom is running for the duration of your game play.
If you trust me (why would you?!) you can use the copy of phantom I built (md5 5e7595f82f117b545c511629df3304ba)
Add a Second Server for Survival Mode
If you want to start a second server for survival mode games the process is almost identical. The docker image is created as follows:
docker run -d -e EULA=TRUE --name cworld_survival -e GAMEMODE=survival -e DIFFICULTY=normal -e SERVER_NAME=fenhome2_survival -v /home/<user>/data_survival:/data -p 127.0.0.1:19133:19132/udp itzg/minecraft-bedrock-server
And for the firewall
firewall-cmd --direct --add-rule ipv4 nat PREROUTING 0 -s <allowedHostIp>/32 -p udp --dport 19133 -j DNAT --to-destination <dockerIp2>:19132
Where <dockerIp2> is the IP of the second minecraft server.
You can now add a second server in your android/iOS clients with the name “<server> survival”, <server> for the ip, and 19133 for the port.
Note that on XBox you will need a second phantom instance with 19133 as the port, as in:
phantom-windows.exe -server <server>:19133