Linux Networking L2 and L3

Linux networking spans two foundational OSI layers: Layer 2 handles Ethernet framing, MAC addressing, ARP, and bridging, while Layer 3 handles IP routing, policy rules, and the netfilter subsystem that powers iptables and container networking.

Overview

Overview Linux networking is built on a layered model where Layer 2 and Layer 3 each have distinct responsibilities but cooperate tightly inside the kernel. Layer 2, the data link layer, concerns itself with how bytes travel between two directly connected devices: it defines the Ethernet frame format (destination MAC, source MAC, EtherType, payload, FCS), address resolution via ARP, and logical grouping of interfaces using Linux bridges and 802.1Q VLAN tagging. Layer 3, the network layer, introduces the concept of logical addressing with IP, autonomous routing decisions based on destination prefix lookups, and policy-based routing that can forward packets based on source IP, firewall mark, or DSCP bits.

The netfilter framework is the kernel subsystem that ties these layers together with stateful packet inspection and manipulation. Every packet that enters, traverses, or leaves a Linux machine visits a sequence of netfilter hooks. Tables contain chains of rules, and iptables is the classical userspace tool for managing those rules. nftables is the modern replacement with a unified syntax, but iptables remains dominant in production environments, container runtimes, and Kubernetes data planes, so understanding both is essential for any DevOps or infrastructure engineer.

Linux network namespaces virtualize the network stack itself. A namespace owns a private view of interfaces, routing tables, iptables rules, ARP caches, and sockets. This is the kernel primitive that makes containers possible: each container runs inside its own namespace, isolated from every other container and from the host. Veth pairs are the wire between namespaces: they behave like a crossed Ethernet cable at the kernel level, delivering frames from one end to the other with essentially zero latency and no intermediate switching logic.

Docker and Kubernetes build their entire networking models on top of these primitives. Docker creates a Linux bridge (docker0), provisions veth pairs for each container, and installs iptables MASQUERADE rules so outbound traffic can reach the internet. Kubernetes delegates network setup entirely to CNI plugins, which are short-lived binaries invoked by the container runtime. The CNI specification defines a precise contract: the runtime passes configuration on stdin and reads a JSON result from stdout, allowing any conforming plugin to wire up pod networking without modifying the runtime.

Understanding this stack end-to-end is required for debugging packet drops (ip route, ip neigh, conntrack, iptables -L -n -v), for designing multi-tenant network isolation (namespaces, VLAN tags, policy routing tables), and for reasoning about the performance characteristics and failure modes of container networking overlays. A candidate who can trace a packet from a containerized application through every kernel layer to the physical wire, and back, demonstrates the depth needed for senior infrastructure, SRE, and platform engineering roles.

Key concepts

  • Ethernet Frame and ARP
  • Linux Bridge and 802.1Q VLAN Tagging
  • IP Routing Table and ECMP
  • Netfilter Tables and Chains
  • Linux Network Namespaces and Veth Pairs
  • CNI Plugin Contract

Interview questions

  • Trace a TCP SYN packet from a Docker container to the internet through every iptables chain it visits.
  • Explain veth pair mechanics at the kernel level. What happens when you write a byte to one end?
  • What is the difference between PREROUTING and POSTROUTING in iptables? When would you use each?
  • How does ARP work for pod-to-pod traffic across different Kubernetes nodes? Walk through the full resolution path.
  • Describe the CNI plugin contract precisely. What must a plugin do on ADD, and what guarantees must it make on DEL?

Sign up free to read the full topic

More Linux topics

Start free on Cariara · Coding problems · System design studio