Processes, sockets, and ports
On this page
Web has one address. Laptop and phone both want its page, while web also accepts remote logins. An address gets a packet to web, but does not say which waiting program should receive it. You will find which program waits on each port, then see how web tells two clients apart.
- Settings: read and interpreted; their automatic source remains open.
- Finding a name: still open, for How DNS Finds Services.
- Own network or router: answered in Subnetting Foundations.
- Delivery on the cable: answered in Ethernet and Local Delivery and Finding a neighbor with ARP.
- Crossing and returning: answered in Reaching Another Device.
- Finding programs: the question here.
- Application words and privacy: still open, for Everyday Application Traffic.
Before you start
Section titled “Before you start”Finish Practice: Reaching Another Device. Use the running lab with modes off. Leave machine shells and run netlab reset from the VM if settings changed. Enter web with netlab shell web. Keep experiments inside this lab.
Find the waiting ends
Section titled “Find the waiting ends”Run ss -tln. The command lists sockets. Here -t selects TCP, the transport examined next; -l selects listeners; and -n shows port numbers instead of service names.
learner@web:~$ ss -tlnState Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 *:8080 *:*
LISTEN 0 5 *:443 *:*
LISTEN 0 5 *:80 *:*
LISTEN 0 128 [::]:22 [::]:* learner@web:~$ Steps (3)
- Type
ss -tln - Press Enter
- Output:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 5 *:8080 *:* LISTEN 0 5 *:443 *:* LISTEN 0 5 *:80 *:* LISTEN 0 128 [::]:22 [::]:*
The state LISTEN says an end is waiting for incoming connections. Listening means waiting for another program to start an exchange. A port is a number naming a program’s end of a conversation on a machine. A socket is an end of a conversation that the operating system keeps for a program.
The local address column ends with the port. A wildcard, *, means any local address supported by that socket. It does not mean every machine on the network. The peer wildcard means this listening socket is not tied to one client.
Read a listening socket
LISTEN 0 5 *:80 *:* LISTEN*80Reading the output
Pick a step to match a marked part of the output to the picture.
Steps (3)
- State. State: LISTEN. Shown on web's local as: State. The socket is waiting for incoming connections.
- Local address. Local address: *. Shown on web's local as: Local address. The wildcard accepts any supported local address.
- Port. Port: 80. Transport layer. Shown on web's local as: Port. The local port is the number after the colon.
| Part | Meaning |
|---|---|
LISTEN |
Waiting for connections |
* |
Any supported local address |
80 |
Local port |
Separate clients at the same server
Section titled “Separate clients at the same server”A server waits on a known port. A client normally gets an unused local port from its operating system.
Predict: two clients use the same destination port. What makes their conversations different?
Open three terminals. On laptop run curl telnet://10.77.20.80:80 and leave it running. On phone run the same command and leave it running too. This opens a connection without asking for a page. Both programs wait, so you have time to read the list. A page request ends too quickly to catch in the list.
In the third terminal, on web, run ss -tn. Removing -l selects active conversations instead of listeners. Then press Ctrl+C on phone and laptop to close their waiting commands.
learner@laptop:~$ curl telnet://10.77.20.80:80^Clearner@laptop:~$ Steps (4)
- Type
curl telnet://10.77.20.80:80 - Press Enter
- Phone has closed its connection after web listed both. Return to laptop and press Ctrl+C.
- Press Ctrl + C
learner@phone:~$ curl telnet://10.77.20.80:80^Clearner@phone:~$ Steps (4)
- Type
curl telnet://10.77.20.80:80 - Press Enter
- The third terminal on web listed both connections. Return to phone and press Ctrl+C.
- Press Ctrl + C
learner@web:~$ ss -tnState Recv-Q Send-Q Local Address:Port Peer Address:Port Process
ESTAB 0 0 [::ffff:10.77.20.80]:80 [::ffff:10.77.10.10]:36994
ESTAB 0 0 [::ffff:10.77.20.80]:80 [::ffff:10.77.10.11]:46882 learner@web:~$ Steps (3)
- Type
ss -tn - Press Enter
- Output:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process ESTAB 0 0 [::ffff:10.77.20.80]:80 [::ffff:10.77.10.10]:36994 ESTAB 0 0 [::ffff:10.77.20.80]:80 [::ffff:10.77.10.11]:46882
Web’s socket accepts IPv4 and IPv6, so it displays the IPv4 client as [::ffff:10.77.10.10]; IPv6 itself comes later.
Check your answer
Both local ends are 10.77.20.80:80. Laptop’s peer pair is 10.77.10.10:36994; phone’s is 10.77.10.11:46882. Within TCP, the two IP addresses and two ports distinguish a conversation. The client pairs differ, so web can tell these conversations apart.
You used these same two addresses and two ports to group rows in Following an exchange. A destination port alone does not tell web which client sent the bytes.
Mistakes to recognize
Section titled “Mistakes to recognize”“A port is a physical socket.” The hardware port in Switches, routers, and access points is a connector. This port is a number in transport communication.
“One port serves only one client.” The two ESTAB lines share web’s port. That state means established: the conversation is open.
Good to know
Section titled “Good to know”Line order and client ports vary. Match the address and port together, not the row number. The list shows what web is waiting for now. It does not prove that a client can reach web.
Try it yourself
Section titled “Try it yourself”On web, run ss -tln again. Match each distinct port to the services in the lab cast. Compare your matches with a program check: run sudo ss -tlnp, typing your Ubuntu password when asked. Explain what the added column tells you and what it leaves unanswered.
Solution
learner@web:~$ sudo ss -tlnp[sudo] password for learner: State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=113,fd=4))
LISTEN 0 5 *:8080 *:* users:(("python3",pid=107,fd=3))
LISTEN 0 5 *:443 *:* users:(("python3",pid=108,fd=3))
LISTEN 0 5 *:80 *:* users:(("python3",pid=106,fd=3))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=113,fd=3)) learner@web:~$ Steps (6)
- Type
sudo ss -tlnp - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Output:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=113,fd=4)) LISTEN 0 5 *:8080 *:* users:(("python3",pid=107,fd=3)) LISTEN 0 5 *:443 *:* users:(("python3",pid=108,fd=3)) LISTEN 0 5 *:80 *:* users:(("python3",pid=106,fd=3)) LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=113,fd=3))
Ports 80 and 8080 supply HTTP, 443 supplies HTTPS, and 22 accepts SSH. The added -p shows which programs own the sockets: python3 for the page services and sshd for SSH. The name tells you which program opened the socket. But python3 alone does not prove which application protocol its code speaks.
- Read local address and port together.
- Separate a listener from its established conversations.
- Use both client and server pairs to distinguish conversations.
Next, Opening and closing TCP connections explains the rows around a request.