Linux › Section I · Your network and its configuration › Topic I.1
Network basics, packets, and layers
Before you can configure a Linux machine's network, you need a clear picture of what it is joining and which part of the system handles each job. This topic maps the familiar network layers onto Linux itself: what the kernel does, what user programs do, and which command shows you each piece.
A Linux machine on a small network
Picture a typical home or small-office network: a Linux laptop, a desktop, a printer and a broadband router, all joined by cable or Wi-Fi. The machines that run applications are hosts, or end systems, as in the Networking topic What the internet is. The hosts that sit close together and share one configuration form a local area network (LAN). The router is a machine with a second connection, the uplink or wide area network (WAN) link, that leads to the internet. Because the router belongs to both networks, every host on the LAN can reach the internet through it. In this section you look at that arrangement from the Linux laptop's point of view.
Packets: header and payload
Hosts do not send a file or a web page as one long stream of bits. They cut the data into small units called packets. Each packet has a header, which says where it comes from, where it is going and which protocol it uses, and a payload, which is the data itself, such as part of a page or an image. Small packets let a host interleave several conversations at once and resend only the piece that was damaged or lost. The operating system does the cutting up and reassembly, so programs on Linux rarely see packets at all.
The layers, Linux style
Networking software is built as a stack of layers, as the Networking topic Protocol layers and encapsulation explains with five layers. Many Linux texts use a four-layer view that merges link and physical: the application layer (HTTP, DNS, SSH), the transport layer (TCP and UDP, with port numbers), the internet or network layer (IP, which moves datagrams between hosts) and the link or physical layer (Ethernet or Wi-Fi, which moves frames across one link). The unit names stay the same: messages, segments, datagrams and frames. Each layer wraps what it gets from the layer above in its own header on the way out.
Who does what: kernel and user space
On Linux the split between layers lines up with the split you met in The kernel: processes, memory, drivers, and system calls. The application layer runs in user space: a browser, the ssh client or a web server is an ordinary process. The transport and internet layers, and most of the link layer, live in the kernel, with device drivers talking to the network card. A program reaches the kernel's network stack through socket system calls such as connect and send. So configuring the network mostly means telling the kernel what addresses, routes and rules to use.
A command for each layer
Modern Linux distributions use the ip command from the iproute2 package to view the lower layers. ip link shows the network interfaces and their hardware addresses, the link layer. ip address shows the IP addresses assigned to them, and ip route shows where datagrams are sent, the internet layer. The ss command lists TCP and UDP sockets, the transport layer. At the application layer you test with the programs themselves, such as curl for the web or getent hosts for name lookups. The older net-tools commands, ifconfig, route, netstat and arp, still appear in guides but are legacy tools.
Worked example: one web request on a Linux laptop
Follow a request from the laptop to a web server at the documentation address 203.0.113.80. 1. Application, user space: the browser builds an HTTPS request and calls connect on a socket. 2. Transport, kernel: TCP picks an unused local port, such as 51334, and opens a connection to port 443 on the server. 3. Internet, kernel: IP puts each segment in a datagram addressed to 203.0.113.80 and looks up the route, which leads to the router. 4. Link, kernel driver and hardware: the network card sends a frame to the router's hardware address. 5. The router passes the datagram on towards the server. Check: on the laptop, only step 1 ran in user space.
Worked example: naming the layer from the output
Here are four illustrative lines a Linux laptop might print. Name the layer and the command for each. 1. link/ether 02:00:00:00:00:14 is a hardware (MAC) address, so it is the link layer, from ip link. 2. inet 192.168.1.20/24 is an IPv4 address with its prefix length, the internet layer, from ip address. 3. default via 192.168.1.1 dev wlp2s0 is a route that sends everything off the LAN to the router, also the internet layer, from ip route. 4. ESTAB 0 0 192.168.1.20:51334 203.0.113.80:443 is an established TCP connection between two ports, the transport layer, from ss. Check: only line 4 mentions ports, which belong to the transport layer.
When layers blur
The layer model is a tool for thinking, not a law that every device obeys. A firewall on a Linux host reads transport-layer port numbers to decide whether to accept a packet, even though filtering happens inside the kernel's IP code. A router that performs address translation rewrites port numbers as well as addresses. Some names mislead too: TLS, Transport Layer Security, actually runs above TCP, inside the application. When something fails, though, the layers still give you an order for checking: is the link up, is there an address, is there a route, is the service listening?
A router is just a computer
Nothing magic makes a router. It is a machine with interfaces on two or more networks and the job of passing datagrams between them; the Networking course counts it as a packet switch, not a host. A dedicated home router is usually a small computer, often running Linux, with several network ports and a web page for settings. Any Linux machine with two interfaces can do the same job once forwarding is switched on, as the topic Linux as a router: private networks and NAT shows. For now, think of the router as the one machine on your LAN that knows the way out.
Common mistakes to avoid
First, thinking a program sends a whole file in one piece; the kernel splits data into segments and packets. Second, assuming that all network work happens in user programs; TCP, UDP and IP run inside the Linux kernel. Third, mixing up the tools: ip address shows addresses, ip route shows routes and ss shows sockets and ports. Fourth, following an old guide that uses ifconfig or netstat and assuming they are installed; many current distributions leave net-tools out. Fifth, assuming the four-layer and five-layer models disagree; the four-layer view simply merges link and physical.
Key takeaways
A LAN is a group of nearby hosts, and the router is the machine that links it to the internet over its uplink. Data travels in packets, each a header plus a payload. Linux texts often use four layers: application, transport, internet and link, the last merging the Networking course's link and physical layers. Applications run in user space; TCP, UDP, IP and drivers run in the kernel, reached through socket system calls. Use ip link, ip address and ip route for the lower layers and ss for the transport layer; ifconfig, route and netstat are legacy. Any Linux host with two interfaces can act as a router.
Flashcards
Flashcard
An end system that runs applications
Test your understanding
Question 1 of 5
On a Linux host, which of these runs in user space rather than in the kernel?
Question 2 of 5
Which command would you use to see the IP addresses assigned to a Linux machine's interfaces?
Question 3 of 5
A line of output reads: ESTAB 0 0 192.168.1.20:51334 203.0.113.80:443. Which layer does it describe?
Question 4 of 5
How does the four-layer model in many Linux texts relate to the five-layer internet stack?
Question 5 of 5
Which statement about routers is correct?
