Localhost
Lesson 12 of 47 in Coddy's Networking with the Terminal course.
localhost, and the address it resolves to, 127.0.0.1, mean this machine. A request sent there never touches the network. It goes down to the network stack and comes straight back up.
That makes it the ideal place to learn, because you can be both ends at once:
python3 -m http.server 9106 &
sleep 1
curl -s http://localhost:9106/It is also behind a problem you will meet in real work. A service can be bound to only localhost, which means it accepts requests from its own machine and refuses everything from outside. It works perfectly for the person who started it and is invisible to everyone else. That is one of the real meanings of "it works on my machine".
So when a colleague cannot reach your service, one of the first questions is what address it is listening on, not just which port.
Challenge
MediumServe yourself, and measure what came back.
- Create
page.htmlcontaining exactlylocal traffic only - Serve the folder on port 9106 in the background
- Fetch it using the name
localhostand pipe the response intowc -cto count the bytes
The text is 18 characters, plus the newline echo adds, so:
19The request never leaves the machine, which is why this works with no network at all.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Networking with the Terminal
Practice on your own: Terminal playground