Methods
42 (XI): NetPractice, serverless networks
A simulator for configuring networks: masks, routing, and what happens when
2 min read
At the final stretch of the common core —after the raycasting of 42 (X): Cub3D, raycasting and walls that look 3D—, 42 flipped the third one on me: the project doesn't compile. NetPractice is a web simulator with ten levels where you're given a network topology —routers and switches (the ones that connect and distribute the network) and machines—, a few configuration fields, some empty, and one dry objective: get two devices to ping each other (a "hey, you there?" between computers). It either works or it doesn't. Here, valgrind (the memory error detector) won't help.
The problem
My background with networks was that of an advanced user: opening a port on the router, setting a static IP at home, setting up a VPN (encrypted connection to another network). I knew that the mask (the number that says where your network ends) has four numbers and that the gateway (the exit door to the outside) is important, but I'd never traced the why. The first level already corrects your pretensions: one of the fields comes wrong from the factory, and you have to understand what each value does before touching anything. And when topologies arrive with half a dozen devices, guessing stops being an option: the possible combinations are an ocean.
How I approached it
I made my own helper: a Python script using the ipaddress module that calculates network address, broadcast (the one all machines listen to), and usable range from the IP and mask, and prints them in columns to compare hosts at a glance. I had it bound to a terminal alias, so I'd work with the simulator in one window and the calculations in the other. With that, each level boiled down to the same method: identify which subnets (little network pieces with their own boundary) there are, what free address each interface can have within its own, and what route each router is missing to reach the destination. The final levels add the tricky part: the exit to the Internet with its default address, and making the routes match in both directions.
What I learned
Three things. The mask isn't a formality: it's the boundary, and depending on how you set it, your device decides whether the destination is "next door" or "further away". Ping goes in two directions: the classic mistake is configuring the outbound and forgetting the return. And routing (the "to get there, go through here" choices) is a list of decisions ordered by specificity, not some kind of magic. Since then, when a network doesn't work, I no longer restart blindly: I go down layer by layer until I find the level where it breaks. Next stop, now with code: 42 (XII): C++, the modules.