You don’t get to explicitly use Linux namespaces very often; one usually gets to make use of them when setting up containers or some sort of smart web hosting platform that allows hard resource limits to be put in place for customers, but even then the actual setup is hidden somewhere in the back. There are scenarios when containers simply require too much work for the particular task; I, at one time, faced the need of ensuring some network communication between 2 instances of the same service.
Communication? Same service? Have them listen on different addresses or on different ports and you’re done, you might say – but it’s not always that simple. If you have no control over the code but just want to replicate a certain behavior, there may simply not be an option to have instances listen on different ports. If the protocol also involves broadcasting, things become really complicated, as you don’t always have 2 IP addresses, on different interfaces, connected to the same network. Such scenario is easy to solve with virtualization or containers, but for this particular problem they’re overkill. The lightweight solution comes from manipulating Linux network namespaces.
You’re in a tiny room at Googamazbook and the interviewer comes in, says hi (if you’re lucky), presents themselves (they’re really into doing you a favor) and then starts asking questions. The easy one comes first:
What happens when you run telnet www.brainware.ro 80 ? Please go on through all the layers.
Warmed up from the systems interview, you start talking about /etc/hosts and /etc/resolv.conf: name resolution and then the actual connection to the http port. If your knowledge stops here, please do go on reading this text. Or just do go on, maybe I forgot something.
1. Name Resolution
The name resolution protocol is performed by sending an UDP packet to each resolver found in /etc/resolv.conf. The UDP packet has a small header containing: