Sunday, May 3, 2020

How does one connect to an ubuntu container from the internet?

Okay so I don't fully understand some basic things about networking. This is how I think it works, at some point my understanding is gone.

I know I have one public IP address, every ping I send from my router, no matter if I use my "Computer A" or my "Computer B", will be seen as the same IP address, the public one. I hope I got this right.

Then, every device connected to that router, has a unique internal/local IP. I can ping Computer A from Computer B using its local IP as long as I'm under the same network.

My understanding starts to fall short there. If I have an ubuntu server in one machine and it has some LXD/LXC containers inside, I guess the host machine also works as a router, and all those containers are together in a local network. Pretty much like my "real" setup but all done virtually inside a single machine.

Some things are still easy if I set it up like this. I can use those LXD containers to access the internet, and I can run services from there, for example, I've been running a noip service inside a container and works nicely. I've also been running a couple bots inside containers and they also work nicely.

The issue comes when I try to connect to one of those machines from the internet.

If I host, let's say, a Minecraft server on a computer on my local network, I can give someone the public IP and the port and he can use it to connect to my computer. I don't quite know how is this done but I guess it's all about the port. My best guess is that only my machine is listening to that specific port, so any packet coming to my router gets to my computer. I don't fully understand this, but I know it works.

The thing is... How would I connect to a container inside a machine on my local network? As far as my understanding goes, the container would be listening at packets arriving to the specific port of its host machine, not to the router hosting the local network.

My understanding tells me that I need to point the packets to that specific machine instead of pointing them to the router. But since I only have one public IP, how do I do it?

There is something I don't quite understand because if I am not mistaken, when you ping a machine the ping has to go out and come back. And if I ping from the LXD container to the internet, the ping goes out and back in.

So there has to be a way to point for that specific machine from the exterior. But I don't understand.

Any explanation or link would be useful. Thanks.



No comments:

Post a Comment