Hosting a Minecraft Server Without Extra Hardware

From Valentino Fans
Jump to: navigation, search

I would like to play Minecraft with my friends and I already have a server that is connected to the internet. My server isn't powerful enough to run a Minecraft server instance. On the other hand I have a spare beefy laptop that can handle the load, however port forwarding is not feasible. Both the server and the laptop are connected to my Tailscale network. Could I use all of this to set up a Minecraft server with a public IP? The answer was yes-and I was surprised at how easy it all was. Plus, the server is very playable and the latency was lower than trying random "free hosting" services.



Tailscale Halfway to Tailscale



Tailscale is already installed on all my devices. This means that if I create an Minecraft server instance on one device, I will be able to connect immediately to it from the other devices. My friends don't have Tailscale yet! Node sharing is not possible for my friends right now. However, I still have the advantage of Tailscale in that my laptop will always have a static IP in relation to the server and the server will always have a static IP in relation to the public internet. The connection will be reliable and I won't have to resort to dynamic tricks.



Let's try the theory.



Let's see whether Minecraft is able to see it if I enter the Tailscale IP...



Great success! Now we only need to expose it to the public internet.



iptables to the rescue!



In essence, iptables lets you to set the rules of the Linux kernel firewall. It's really simple in its terms of. The user creates tables, and packets are routed via the tables. Java edition Minecraft servers use TCP port 25565 between the client and server.



NixOS configuration



It was easy to enable IP forwarding, and add the number 25565 to my list of open TCP ports:



The rule is designed



Now we can go ahead add the following commands to our firewall configuration. Let dest_ip represent the Tailscale IP address of the server. The first command adds an order to the PREROUTING chain. This is where packets arrive before they are processed. The packet is then routed to Tailscale's IP address. The second command lets the IP address used to send packets remain the same, which means the server is only acting as an agent for routing.



We have the following setups:



We now restore the server configuration and check it again in Minecraft using the public IP. It works exactly as expected!



Final touches A DNS record



An A record was added to my configuration in order to give people an attractive URL instead of an IP address.



Performance



As far as performance is concerned, it's pretty good! My friends and I played without issue on the proxy server that is located on the East coast. Info The Minecraft server is located on the West coast. I was able pin people through the connection, and the latency was acceptable (77 milliseconds for someone from New York).



Refer to



Xe's article on Tailscale, NixOS and Minecraft inspired me to write this, however, my requirements were different. I didn't want to force my friends to install Tailscale to play on my server, and I wanted to use the hardware I had access to, making my server as a crappy router.