What TCP/IP and DNS are and how they work
TCP/IP is the protocol suite that runs the internet and almost every local network. IP delivers packets between hosts, while TCP and UDP deliver data between programs on those hosts. DNS is a distributed database of names that turns example.com into an IP address.
Use this reference when a site or service won’t open, or when you need to split a network into subnets, open a port or set up a domain’s records. It follows the IETF standards (RFCs) and shows Linux diagnostic commands. For configuring specific systems, see the Linux, MikroTik, and Windows Server and AD references.
The TCP/IP stack has four layers, each with its own job. The link layer, such as Ethernet, delivers a frame within a single network. The internet layer is IP: it carries a packet from host to host through routers and guarantees nothing. The transport layer tells programs apart by port: TCP adds reliable delivery, UDP does not. The application layer holds the programs’ own protocols: HTTP, SSH, DNS.
On the way out, each layer adds its own header to the data — this is encapsulation. TCP turns the data into a segment, IP into a packet and the link layer into a frame. The receiver strips the headers in reverse order.
MAC, IP, port and name
| Address | Layer | What it identifies | Example |
|---|---|---|---|
| MAC address | link | an interface within one network | 00:00:5e:00:53:01 |
| IP address | internet | a host on any network | 192.0.2.10, 2001:db8::10 |
| Port | transport | a program on the host | 443 |
| Name | application (DNS) | a service, in human-friendly form | example.com |
A MAC address only matters on a single hop: a router strips the link-layer header and builds a new frame for the next network. The source and destination IP addresses travel the whole path, unless NAT rewrites them on the way.
A request to a website, step by step
- The program asks the resolver for the address of
example.com; the DNS query usually goes over UDP to port 53. - Once it has the address, the program opens a TCP connection to port 443 on the server, starting with the SYN of the three-way handshake.
- The system checks whether the destination is in its own subnet: if so, the packet goes directly, otherwise to the default gateway.
- ARP (Neighbor Discovery in IPv6) finds the MAC address of the next hop on the local network.
- Routers pass the packet from network to network, each one decrementing its TTL.
- The server’s kernel hands the data to the program listening on the destination port.
The TCP/IP model and the OSI model
Textbooks often use the seven-layer OSI model. The TCP/IP layers don’t map onto it one to one:
| TCP/IP layer | OSI layers | Protocols |
|---|---|---|
| Application | application (7), presentation (6), part of session (5) | HTTP, SSH, DNS |
| Transport | transport (4) and part of session (5) | TCP, UDP |
| Internet | network (3) | IP, ICMP |
| Link | data link (2); physical (1) lies below it | Ethernet, ARP |
Hence the administrators’ jargon: IP is a layer 3 (L3) protocol, TCP and UDP are layer 4 (L4).
Prerequisites
- Binary numbers: masks and prefixes are counted in bits
- Hexadecimal notation: IPv6 addresses are written in it
- Linux command-line basics: all diagnostic examples are for Linux; see the Linux reference for more
Section sources
the section is written from these pages- RFC 1122: Requirements for Internet Hosts - Communication Layersrfc-editor.org/rfc/rfc1122.html(opens in a new tab)
- RFC 1034: Domain names - concepts and facilitiesrfc-editor.org/rfc/rfc1034.html(opens in a new tab)
- RFC 1812: Requirements for IP Version 4 Routers, 2.2.1rfc-editor.org/rfc/rfc1812.html(opens in a new tab)