IP gets a packet to the right host. The transport layer gets the data to the right program on that host. Its two classic protocols are TCP and UDP.
Ports
A port is a 16-bit number from 0 to 65535. A server listens on a known port. The client normally gets a temporary one, called an ephemeral port.
IANA divides the range into system ports (0 to 1023), user ports (1024 to 49151) and dynamic ports (49152 to 65535). Linux picks ephemeral ports from its own range, which you can read:
$ cat /proc/sys/net/ipv4/ip_local_port_range
32768 60999On Linux, binding to a port below 1024 normally needs extra privilege.
A TCP connection is identified by source address, source port, destination address and destination port. That is why one web server can serve many clients on port 443.
TCP
TCP is connection oriented and provides a reliable, ordered stream of bytes. It opens a connection with a three-way handshake:
- client sends SYN
- server replies SYN-ACK
- client sends ACK
It numbers the data, expects acknowledgements and retransmits what is lost. It also slows down when the receiver or network cannot keep up.
UDP
UDP sends individual datagrams with no connection setup. It does not retransmit, and does not guarantee delivery or order. It has little overhead, so it suits DNS lookups, voice and video, and protocols such as QUIC that add their own reliability.
Inspecting sockets
ss shows sockets:
$ ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*-t is TCP, -u UDP, -l listening and -n numeric. Add -p to see the owning process. You usually need sudo to see processes belonging to other users. Older systems and guides use netstat.
A service on 127.0.0.1 accepts connections only from the same machine. 0.0.0.0 means all IPv4 addresses of the host.
Try it
Run ss -tuln and pick one line. Say which protocol it uses, which port, and whether other machines could reach it (a firewall may still block them). Practise in the networking and SSH lab.
Check your understanding
Transport Layer
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.