ssh tunneling for minecraft proxy
Please forgive another newbie question. :D
I've got a Minecraft server that I don't necessarily want running 24/7 and want to proxy to it from a cheaper server that I do and that has an A record pointing to it, the idea being that players can connect to minecraft.mydomain.com (not the real domain name) rather than have to find out the endpoint IP every time I spin up a server. So on my server that I want to connect to I run
ssh -N -L 55265:127.0.0.1:55265 root@A.B.C.D
(where A.B.C.D is the IP address of the actual server). I thought that this would forward connections from port 55265 to the same port on the server I'm connecting to, but in fact I can't even connect to minecraft.mydomain.com. It's like it's not even listening for an outside connection, which I suspect is precisely the case--anybody know what I need to do to make this work?
1 Reply
Hey there,
I'm happy to point you in the right direction. You can use SSH to tunnel to a specific port. The command looks like this:
ssh user@IP.add.re.ss:$destination_port -D $local_port number -C -N
So if you wanted to connect to port 55265 on the host machine and destination machine, and the IP address is 8.8.8.8, the command would look like this:
ssh root@8.8.8.8:55265 -D 55265 -C -N
--
-D: Is the destination port.
-C: Adds compression to the data.
-N: Does not execute remote commands and meant to use for forwarding data.
It would be best if you also decided how the users will authenticate. When you SSH to another endpoint, you need to either use pubkey authentication or password when you connect.
In the end, this method may not be the best way to accomplish what you want to do. I would recommend using an HAProxy, so when users connect to minecraft.mydomain.com, it forwards all connections to the endpoint you spun up. I added a link to our guide for build an HAProxy. The guide meant for balancing a website, but you can configure the ports for anything that serves your purpose and will forward the connection. You would need to update the IP address each time you spin up the new Minecraft server. I also added a link to the HAProxy man page for more information.