Alright, so the other day, I decided to set up a Minecraft server on my Linux box. It wasn’t too complicated, but the firewall part got me scratching my head a bit. I figured I’d share my experience, so here goes nothing.
First, I got the Minecraft server up and running. That was the easy part. Download the server file, run it, and boom, server’s live. But, of course, nobody could connect. Firewall’s blocking everything, as it should.
So, I logged into my server and started poking around. I’m not super familiar with all the firewall tools, but I know there’s one called GUFW, which is like the user-friendly version of UFW (Uncomplicated Firewall). I installed it because, well, who doesn’t like things uncomplicated, right?
Installation, by the way, was a breeze:
sudo apt update
sudo apt install gufw
Ran those two commands and bam, GUFW was ready to go.
After that, I opened up GUFW. Nice, clean interface. I wanted to be really strict with the rules, only allowing what’s absolutely necessary. I mean, better safe than sorry, you know?
I added a new rule, and there are a bunch of options, but I kept it simple. I allowed both TCP and UDP traffic on port 25565. That’s the default Minecraft port, so if you changed yours, you’ll need to adjust accordingly.
Here’s how I set it up in GUFW:
- Clicked the “+” button to add a rule.
- Chose “Preconfigured” because it is easier.
- Selected “Games” in “Category”.
- Selected “Minecraft” in “Application”.
- Clicked “Add”.
And that is it. My rule was in place.
I also wanted to limit access to only certain IP addresses. My friends’ IPs, to be exact. You can add that in the rule settings too, under the “From” section. Just put in the IP addresses you want to allow, separated by commas if there are multiple.
Once I saved the rule, I went back to my Minecraft client, tried to connect, and… it worked! My friends could join too. Success! But later, some of my friends said they could not connect to the server. I realized that some routers might block the port. So I logged into my own router and found the port forwarding settings. And forward port 25565 to my server.
It’s a bit different for every router, but basically, you need to:
- Log into your router’s admin panel. Usually by typing something like 192.168.1.1 into your browser.
- Find the “Port Forwarding” or “Virtual Server” section.
- Create a new rule.
- Enter your server’s local IP address.
- Put in 25565 for both the start and end ports.
- Choose both TCP and UDP as the protocol.
- Save and apply the settings.
After that, everything worked fine! If you’re having trouble, there are other tools and methods to manage your firewall, like using iptables directly, but I found GUFW to be the easiest and quickest way to get things done. I guess it depends on how comfortable you are with the command line and stuff.
Anyway, that’s my little adventure with setting up a Minecraft server and dealing with the firewall. Hope it helps someone out there! Happy crafting!