Addresses and Ports
Which machine, which program, and the four numbers that name a connection.
An address picks a machine. A port picks a program on it.
An IP address
It belongs to an interface, not the machine. This container has two:
ip -4 -o addr show | sed -E 's/ +/ /g' | cut -d' ' -f2,4The /8 and /16 say how much of the address names the network. /16 makes the first two
octets the network, so 172.17.*.* are all neighbours.
lo is always 127.0.0.1. The second address is whatever Docker assigned, so yours
differs.
Loopback
127.0.0.1 never leaves the machine. Capture on eth0 and nothing appears:
cap "-i eth0 -n -c 1 tcp port 9000" "echo hi | nc -w 1 127.0.0.1 9000"The same command on lo caught three packets in chapter 1 — the kernel routes loopback
without a network card.
Private ranges
Three blocks are reserved for networks that are not the internet:
| Range | Size | Where you see it |
|---|---|---|
10.0.0.0/8 |
16 million | corporate networks, Kubernetes |
172.16.0.0/12 |
1 million | Docker’s default |
192.168.0.0/16 |
65 thousand | home routers |
The container’s address is in the second. A router rewrites these on the way out, which is why your laptop’s address is not what a server sees.
A port
A 16-bit number in the TCP header — 1 to 65535, nothing else. It follows the address in every capture:
cap "-i lo -n -c 1 tcp port 9000" "echo hi | nc -w 1 127.0.0.1 9000"What is listening
ss -tln shows the sockets waiting for a connection:
ss -tln | grep 90000.0.0.0 means every address on this machine, so both of its addresses reach it.
Bound to one address
A second listener, bound only to loopback:
nc -l -s 127.0.0.1 -p 9200 -k &From loopback it answers:
nc -z -w 1 127.0.0.1 9200 2>/dev/null && echo open || echo closedFrom the machine’s other address it does not:
nc -z -w 1 172.17.0.4 9200 2>/dev/null && echo open || echo closedThe 0.0.0.0 listener answers on both:
nc -z -w 1 172.17.0.4 9000 2>/dev/null && echo open || echo closedEphemeral ports
The client never picks its port — the kernel takes one from a range:
cat /proc/sys/net/ipv4/ip_local_port_rangeThat is the CLIENT the captures hide — a number from this range, different each time.
28,000 ports is the ceiling on simultaneous outbound connections to one destination — a load generator hits it, an application rarely does.
A connection is four numbers
Source address, source port, destination address, destination port. Two connections differ only in the second:
(nc -w 3 127.0.0.1 9000 </dev/null >/dev/null 2>&1 &)
(nc -w 3 127.0.0.1 9000 </dev/null >/dev/null 2>&1 &)
sleep 1
ss -tn 'dport = :9000' | tail -2Same destination, same server port, two connections. Only the client port differs.