Linux Network Stack, iproute2 vs net-tools (ip vs ifconfig, ss vs netstat), Routing & Diagnostics
Linux powers more than 96% of the world's top web servers, public cloud hypervisors (AWS, Google Cloud, Azure), and container orchestration platforms (Kubernetes, Docker). At the heart of this dominance lies the high-performance Linux kernel networking subsystem. This masterclass examines how packets traverse the Linux kernel, why modern system administrators retired legacy tools like ifconfig in favor of iproute2, and how to diagnose production network issues using ip, ss, ping, traceroute, and nc.
When network data arrives on a physical Ethernet port or Wi-Fi card, it flows through a layered kernel pipeline:
Figure 41.1: Complete Linux Network Architecture: Application Layer down to Physical NIC
socket(), bind(), listen(), accept()) for user-space applications (Nginx, SSH, Apache, Node.js).For two decades, tutorials instructed users to type ifconfig, netstat, and route. Today, the net-tools suite is completely deprecated across all modern distributions in favor of iproute2:
| Legacy net-tools (Deprecated) | Modern iproute2 (Standard) | Operational Advantage & Why It Changed |
|---|---|---|
ifconfig |
ip addr / ip link |
ifconfig cannot properly handle multiple IPs on one interface without creating virtual sub-interfaces (eth0:1). ip addr supports secondary IPs natively and uses modern Netlink sockets. |
route -n |
ip route |
Supports advanced policy routing (multiple routing tables, source-based routing). |
netstat -tulpn |
ss -tulpn |
netstat crawls slow /proc/net text files, choking servers with thousands of sockets. ss queries kernel memory directly via tcp_diag. |
arp -a |
ip neigh |
Displays Neighbor Discovery Protocol (NDP) for IPv6 as well as IPv4 ARP cache. |
The ip command is an all-in-one network control tool broken into modular sub-objects:
# 1. View all network interfaces and assigned IP addresses (brief format)
ip -br a
# 2. View full interface and IP details
ip addr show
# 3. Bring a physical interface down or up
sudo ip link set eth0 down
sudo ip link set eth0 up
# 4. Assign a temporary static IPv4 address with subnet mask
sudo ip addr add 192.168.1.150/24 dev eth0
# 5. Remove an assigned IP address
sudo ip addr del 192.168.1.150/24 dev eth0
# 6. View the system routing table and default gateway
ip route show
# Example return: default via 192.168.1.1 dev eth0 proto dhcp metric 100
# 7. Add a static route for a private subnet
sudo ip route add 10.0.0.0/16 via 192.168.1.254 dev eth0
# 8. View ARP / Neighbor cache (IP-to-MAC address mappings)
ip neigh show
The ss command is the indispensable tool for inspecting open ports and network socket states:
| Flag | Option Meaning | Diagnostic Function |
|---|---|---|
-t |
TCP | Display TCP sockets. |
-u |
UDP | Display UDP sockets. |
-l |
Listening | Display only sockets actively listening for incoming client connections. |
-p |
Processes | Display process name and PID owning the open socket (requires sudo). |
-n |
Numeric | Show numeric port numbers (e.g. :80, :22) instead of resolving service names (:http, :ssh). |
# 1. Standard sysadmin command: View all listening TCP and UDP ports with process PIDs
sudo ss -tulpn
# 2. View all established active TCP connections
ss -tan state established
# 3. Filter sockets by specific port (e.g., port 443 HTTPS or 22 SSH)
ss -tulpn '( sport = :https or sport = :ssh )'
# 4. Display socket summary statistics (total sockets, TCP states)
ss -s
When debugging communication failures between services or cloud instances, administrators follow this diagnostic sequence:
# Send 4 ICMP echo request packets to verify network layer reachability
ping -c 4 8.8.8.8
# Trace path to destination host showing latency per router hop
traceroute google.com
# Real-time interactive path monitoring combining ping and traceroute:
mtr 1.1.1.1
The nc utility tests Layer 4 TCP/UDP connectivity without needing application clients:
# Check if a remote web server port 80 is reachable (with a 3-second timeout)
nc -zv -w 3 192.168.1.50 80
# Output: Connection to 192.168.1.50 80 port [tcp/http] succeeded!
Terminal Lab Exercise: Open your terminal and run this network discovery sequence:
# Step 1: Discover your network interfaces and IPs
ip -br a
# Step 2: Identify your default gateway router
ip route | grep default
# Step 3: Test local loopback and internet latency
ping -c 3 127.0.0.1
ping -c 3 8.8.8.8
# Step 4: Audit all open listening ports on your machine
sudo ss -tulpn
# Step 5: Check ARP neighbor cache
ip neigh show
ifconfig relies on legacy ioctl system calls that do not scale, cannot manage modern Linux kernel features (network namespaces, multiple IPs per interface without aliases, modern IPv6 address states, policy routing), and is unmaintained. iproute2 (the ip command) uses Netlink kernel sockets, providing unified, scalable control over interfaces, addresses, routes, and bridges.
netstat parses legacy /proc/net/tcp virtual files line-by-line, which causes heavy CPU bottlenecks on busy production servers. ss communicates directly with kernel Netlink sockets via the tcp_diag module, fetching socket tables directly from kernel memory with minimal performance overhead.
lo, assigned IP 127.0.0.1 / ::1) is a purely virtual network interface within the kernel. Packets sent to loopback never touch physical hardware; they loop directly from socket transmit queues into socket receive queues, enabling local inter-process network communication.
-t for TCP, -u for UDP, -l for Listening only, -p for Process name and PID, and -n for Numeric port resolution.
ip route show default or ip route | grep default.
ping operates on the ICMP (Internet Control Message Protocol) protocol (IP protocol number 1), sending ICMP Echo Request packets (Type 8) and listening for ICMP Echo Reply packets (Type 0). It does not use TCP or UDP ports.
traceroute exploits the IP packet header's TTL (Time To Live) field. It sends packets starting with TTL=1. The first router decrements TTL to 0, drops the packet, and returns an ICMP "Time Exceeded" message identifying itself. It then increments TTL to 2, 3, and so on, discovering each router hop along the path.
ip neigh inspects and manages the kernel's Neighbor table, displaying the mapping between Layer 3 IP addresses and Layer 2 hardware MAC addresses (replacing the legacy arp -a command).
nc can read and write data across raw TCP and UDP network connections, allowing administrators to test port connectivity, banner-grab daemon versions, transfer files, or spawn test listening sockets with a single command line.
curl ifconfig.me or curl icanhazip.com to query your public internet-facing IP address.
nc -zv portquiz.net 25 (replace 25 with the port you want to test). If the connection succeeds, outbound traffic on that port is open.
iptables, nftables, or ufw) is explicitly dropping outgoing ICMP packets.
net-tools is deprecated and no longer installed by default. You should use ip addr instead. If you strictly require legacy ifconfig, install it with sudo apt install net-tools.
ip -s link show eth0. The statistics section displays total received (RX) and transmitted (TX) packets, along with error, drop, and overrun counts.