Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Networking & DNSNetwork series

Anatomy of a connection tuple

A server sees 10.0.4.7:49152 connect to 10.0.8.20:443, and those addresses and ports are the connection.

Quick reference

text
10.0.4.7:49152 -> 10.0.8.20:443
PartNameWhat it means
10.0.4.7Source IPThe client. Private in the VPC, NATed before it reaches the internet.
:49152Source portEphemeral, chosen per connection. The half that makes the tuple unique.
->The arrowDirection of the first packet. Every reply reverses it.
10.0.8.20Destination IPThe server the client resolved. Anycast may land on another machine.
:443Destination port443 means TLS. The listener that accepts the connection.

Explained

The tuple

Source IP. 10.0.4.7 is the client. It is private in the VPC. The server routes its reply here, so changing it changes the return path.

Source port. 49152 is the ephemeral port. The client picks it from the kernel's range, usually 32768 to 60999 on Linux, to tell this connection from every other to the same server. Two connections to one host get two source ports.

The arrow. The arrow is direction, not a field. The first packet travels from source to destination, and every reply reverses the addresses and ports. A stateful firewall remembers the direction, so the reply needs no rule.

Destination IP. 10.0.8.20 is the server. The client got it from DNS, and with anycast it may not be the machine that runs the code.

Destination port. 443 is the listener. It tells the server which service receives the packet, and it rarely changes between connections.

What NAT does

NAT rewrites the source address and port on the way out and keeps the mapping, so the reply finds its way back. The server sees the NAT address, not 10.0.4.7, which is why a connection can look healthy on the client and unknown on the server.

The honest caveat: the real key is a five-tuple, and the drawing leaves out the protocol. TCP and UDP can share the same addresses and ports.

The lesson: a connection is an address pair and a port pair, and NAT rewrites half of it.

In one line

The tuple is the connection. Change one field and it is a different connection.

See your tuples

ss -tanp

More notes: Networking & DNS

Open in the notes app: search, filters, copy This note on GitHub