Menu
Coddy logo textTech

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 icon

Challenge

Medium

Serve yourself, and measure what came back.

  1. Create page.html containing exactly local traffic only
  2. Serve the folder on port 9106 in the background
  3. Fetch it using the name localhost and pipe the response into wc -c to count the bytes

The text is 18 characters, plus the newline echo adds, so:

19

The request never leaves the machine, which is why this works with no network at all.

Try it yourself

Terminal
quiz iconTest 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