Linux on call · Chapter 23 of 30
Networking basics
By the end of this chapter you can find which programs are listening on which ports, talk to a web service from the terminal, and read your machine's network addresses. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Processes and the system
- 5 tasks
- Linux
- In the all labs plan
The first 2 chapters of Linux on call are free. This one comes with the all labs plan.
Why you need this
The kitchen tablet shows a spinning wheel: it needs Arjun's menu API, and Ravi needs to tell it where that is. Arjun's note says only:
cat NOTE.txt
The menu API is running on this box, on some port in the 8000s.
I never wrote down which one. Sorry! The kitchen tablet needs it.
- Arjun
ps from chapter 19 shows that a program runs, not where it can be reached. Without a better tool you would try a thousand ports one by one, and you still could not see what the API sends back, or the machine's address for the tablet.
What you build: 5 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Save the menu API's port in port.txt
Find the port that Arjun's menu API listens on, so the kitchen tablet can reach it.
1. In the chapter folder, run ss with -l to list the ports that programs listen on. Add -t and -n too.
2. Read the Local Address:Port column. The API's port is in the 8000s. Skip 8080: that is the lab's own port.
3. Save only the port number in port.txt, in the chapter folder.
To pass: port.txt has the API's port and nothing else, and you ran ss with -l in the chapter folder. A command with a typing mistake or an error does not count, so type it again.
- Task 2
Save the menu in menu.json with curl
Ask the menu API for its menu and save it in a file.
1. Run curl on the API's front page: http://127.0.0.1:PORT/ with your port in place of PORT. It tells you the menu's path.
2. Run curl again on the path /menu. Save the reply in menu.json, in the chapter folder, with -o. Add -s to hide the progress meter.
3. Do not ask for the headers in the same command, or they go into the file too.
4. Run cat menu.json to see what you saved.
To pass: menu.json has the JSON menu exactly as the API sends it, with no headers, and you ran curl on /menu in the chapter folder. A command with an error does not count.
- Task 3
Save the API version from its headers in version.txt
Find the API's version. The API sends it in a header.
1. Run curl -I on the API. -I shows the headers only. (-i or -v also show them.)
2. Find the line that starts with X-Tapri-Version.
3. Save only the value after the colon and the space in version.txt, in the chapter folder.
To pass: version.txt has the version number and nothing else, and you ran curl with -I (or -i or -v) in the chapter folder. A command with an error does not count.
- Task 4
Save this machine's own address in ip.txt
Find this machine's own address, the one other machines use to reach it.
1. In the chapter folder, run ip addr (or ip a, or hostname -I). It lists the network cards.
2. Skip the card lo, which has 127.0.0.1.
3. On the other card, find the inet line that says scope global. Its IPv4 address is the one you need.
4. Save that address in ip.txt, in the chapter folder. The slash and number after it may stay or go.
To pass: ip.txt has this machine's global IPv4 address (not 127.0.0.1) and nothing else, and you ran ip addr, ip a or hostname -I in the chapter folder.
- Task 5 · interview question
Interview: what 127.0.0.1 means, in loopback.txt
Interview question: what does the address 127.0.0.1 mean?
1. Think about which machine answered when you used 127.0.0.1 in this chapter.
2. Write one sentence in your own words. Say which machine it reaches, and what that card is called.
3. Save the sentence in loopback.txt, in the chapter folder.
To pass: loopback.txt has your sentence, and it says which machine a program reaches when it talks to 127.0.0.1.
What you will learn
- Ports and ss: which programs listen on which ports.
- curl: send a request to a web service, save the reply, and read the headers that come before it.
- ip addr: the machine's network cards and their addresses.
More in Processes and the system
Build "Networking basics" yourself
Tapri’s ordering app moves onto a Linux server, and the server is now yours to run. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Linux on call are free. This one comes with the all labs plan.