There are a few guides out there on the internet, but since I run a few Minecraft servers myself, I thought I’d catalogue the process here for prosperity. This guide will deal with installing Minecraft on Ubuntu 12.04, hardening the install a little, then opening up the necessary ports for making your server available on the internet. Finally, a little tweaking of the Minecraft parameters to ensure that your server isn’t “griefed” by passers-by. It’s pretty much step by step, so hopefully I won’t be making too many wild assumptions about your ability. On the other hand, if you have any doubts about what’s written here, you probably shouldn’t be putting a Minecraft server publicly on the internet… just saying. So, what do we need?
To start with, you’ll need an Ubuntu installation. For my server, I use Ubuntu 12.04 LTS desktop edition. Sure, there’s a server edition, but I like the convenience of dealing with the desktop. And yeah, you can use the server edition and add a desktop – if that works for you, great. I’ve experienced a few little foibles around that in the past and given that my hardware is halfway-decent, I’ll take the performance hit of running the full desktop. So, bottom line, this guide will assume that your server has a desktop.
Set up a Games Directory
The bulk of your files for running the server will live in here. My installation uses ~/Apps/Games/Minecraft. Choose a directory path that works for you.
Fire onto your server and browse on over to Minecraft.net download section and download the linux server edition (at the time of writing, it’s the bottom link – it’s the jar file, NOT the exe file). What you’re downloading is just a “jar” file – pretty useless at this point. We’ll deal with that file later. For the moment, stick that file into the root of your Games Directory.
Note that this is the stock minecraft server, so you won’t be able to use any of the thousands of add-ons available on the internet. If you want to use those, you’ll need to download the CraftBukkit edition of the server jar file, which is usually located here : http://dl.bukkit.org. I’m hopefully going to write a later article on CraftBukkit, but for the moment, this guide will work with either version.
The server will need Java installed. I’ve heard reports that the default Java instance in the Ubuntu repositories will work, but I prefer to use the “official” version. Installation these days is a breeze, via WebUpd8’s PPA. Enter the following commands in a terminal on your server :
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-installer
Start It Up
We need to start the server briefly to get the defaults created for us. Do that now :
cd ~/Apps/Games/Minecraft java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
And after it’s calmed down (a minute or so, maximum), type “stop” at the console to stop it again. We just needed it to create the files which we’re now going to edit.
Edit The Files
There are two files we’re going to edit. The most important is server.properties
Here’s mine, with all the entries I changed in bold.
generator-settings= allow-nether=true level-name=MyServer enable-query=false allow-flight=false server-port=25565 level-type=DEFAULT enable-rcon=false level-seed=-7385098387213481225 server-ip= max-build-height=256 spawn-npcs=true white-list=true spawn-animals=true snooper-enabled=true hardcore=false texture-pack= online-mode=true pvp=true difficulty=1 gamemode=0 max-players=10 spawn-monsters=true generate-structures=true view-distance=12 spawn-protection=16 motd=Short Message Here
The full description of all this stuff is on the Minecraft WIKI here. But in short, the level name is the name of the directories that Minecraft will create to store your world. I’ll cover the port further down this post – it’s super important. The seed is customisable and you can type pretty much whatever you want in there – I got that one from the internet because it has a village nearby. The whitelist entry will restrict who can connect to your server. More on that later too. I reduce the max-players (from 20) because I only have a handful of people using my server. View distance default is 10, but I like bumping it up a bit (max 15) so that I can see greater distances. This will affect server performance though, so change with care. Finally, motd is the message that appears under your server name in the browser list.
The second file you need to change is the whitelist.txt. Earlier, we changed the white-list option to true so that we can restrict who can join our server. Now we need to create that list. Just fill it with the Minecraft user names of anyone you want to allow to play, one per line.
What’s next? Well, if this is going on the internet you should…
Choose Your Port
The default server port for a Minecraft server is 25565. It’s the server-port entry in the server.properties file we edited earlier. If you’re only running one Minecraft server then there’s probably no reason to change this and you’re good to go. If you’re going to run more than one, or you want to use a non-standard port (for some reason), you’ll have to bear that in mind in the next section.
Harden The Server
Stop! This is easier than it sounds, but you need to understand a little about your network, or you’ll end up cutting yourself off from your server. That’s fine if you’re like me and you have a desktop that you can just undo your change locally, but it’s a little more serious if you have a headless server and you’re using SSH to access your server.
So find out what network you’re on. You’re running a Minecraft server, so you should probably know this stuff, right? So, no, I’m not going to get into a detailed explanation of TCP/IP sub-netting. Hopefully, even if this is a mystery to you, the following example is enough for you to make the leap. However, if you’re in any doubt, seriously reconsider putting your server on the internet.
The two files we’ll be editing are /etc/hosts.allow and /etc/hosts.deny. Here’s mine :
ALL: 192.168.1. 25565: ALL
Now I’m on a 192.168.1.x network here at home. You might be on a 192.168.0 network. Or something else entirely – so edit those values appropriately! Get this wrong and you’ve cut yourself off from your server, which will now refuse all incoming connections that aren’t from 192.168.1.x. Well, your Minecraft server port will work (because of the 25565:ALL line), but that’s about all.
You can add multiple networks if you need to, just put them in a new line using the example above.
So at this point, I’d advise a good, old fashioned…
Fire up your server again and make sure that you can connect okay. Same command as before :
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
Everything okay? Time to put this on the internet then!
Here’s what many consider the hardest part of all this. They consider it hard perhaps because every single router out there seems to have a different name for what is actually a fairly simple operation. Basically, we’re going to ask our router to “port forward”. So someone on the internet connects to your public IP address on port 25565 and you have to tell your router that whenever it sees that port coming in, it has to forward the traffic on to your server.
I won’t lie, I can’t help with this one. There’s too many routers out there. Here’s what it looks like on a Netgear WDR3400 router. I browse to 192.168.1.1 (because I’m on a 192.168.1/24 network, remember? So if you’re 192.168.0/24, you’ll need to browse to 192.168.0.1), log into the web interface, scroll down to Port Forwarding / Port Triggering, then create a custom entry. Mine looks like this, because Minecraft runs on port 25565, using TCP (not UDP) and my server’s address is 192.168.1.100.
Done that? Test it again, but this time test it by asking a friend, from their house, to enter your server details into the Minecraft multiplayer option. What details? Well, if your server isn’t registered on a dynamic DNS service (and it’s sad to hear that DynDNS.org have stopped offering free accounts!), you’ll just have to pop on over to a website like whatismyip.org and tell your helpful friend to use the IP address instead (and of course update them any time that changes because of your ISP’s policies). So if your public IP was 22.214.171.124, AND you’d chosen a custom port for your Minecraft server, like 25570, then your helpful testing friend would put 126.96.36.199:25570 as the address, like so:
And that should be that.
I’ll try to follow this post up with an additional post on
- How to add the awesome DynMap plugin by changing your server to use the Bukkit jar instead of the official Minecraft jar
- How do perform automated hourly and daily backups of your server.
Until then, happy Mining!