Linux Networking - Wyatt's Notes
Network Interface Management (iproute2)
Section titled “Network Interface Management (iproute2)”The iproute2 suite has replaced the legacy net-tools (ifconfig``route``netstat) as the Standard Linux network management toolset. It provides a consistent interface for managing Interfaces, addresses, routes, tunnels, and policies.
graph TD A[iproute2 Suite] --> B[ip — interfaces, addresses, routes] A --> C[ss — socket statistics] A --> D[bridge — layer 2 bridging] A --> E[vlan — VLAN configuration] A --> F[tuntap — TUN/TAP devices] A --> G[rtmon — route monitoring] A --> H[tc — traffic control / qdiscs] A --> I[nstat — network statistics] A --> J[rdisc — router discovery (legacy)]Interface Configuration
Section titled “Interface Configuration”## List all network interfacesip link showip -br link show # brief output
## Bring interface up/downip link set eth0 upip link set eth0 down
# Set interface propertiesip link set eth0 mtu 9000 # jumbo framesip link set eth0 promisc on # promiscuous modeip link set eth0 txqueuelen 1000 # TX queue lengthip link set eth0 address 00:11:22:33:44:55 # change MAC
# Add IP addressesip addr add 192.168.1.10/24 dev eth0ip addr add 10.0.0.1/24 dev eth0
# Remove IP addressip addr del 192.168.1.10/24 dev eth0
# View IP addressesip addr showip -br addr show # brief output
# Show only specific interfaceip addr show eth0Alternative Names for Interfaces
Section titled “Alternative Names for Interfaces”Modern Linux uses predictable network interface names instead of eth0:
| Naming Scheme | Format | Example |
|---|---|---|
biosdevname | BIOS-provided names | em1``p1p1 |
systemd | Based on bus/slot/location | enp3s0``ens3 |
slot | Physical slot number | enp3s0 |
path | Physical topology path | enx78e7d1ea46da |
mac | MAC address (for USB/dock devices) | enx78e7d1ea46da |
To revert to classic names, add net.ifnames=0 biosdevname=0 to the kernel command line.
Link Types
Section titled “Link Types”# Dummy interface (always up, drops packets)ip link add dummy0 type dummy
# VLAN interfaceip link add link eth0 name eth0.100 type vlan id 100
# Bond interface (link aggregation)ip link add bond0 type bond mode 802.3ad miimon 100ip link set eth0 master bond0ip link set eth1 master bond0
# Bridge (layer 2 switch)ip link add name br0 type bridgeip link set eth0 master br0ip link set br0 up
# VETH pair (virtual ethernet — used by containers)ip link add veth0 type veth peer name veth1
# TUN/TAP (layer 3 / layer 2 tunnel)ip tuntap add dev tun0 mode tunip tuntap add dev tap0 mode tapRouting
Section titled “Routing”Routing Tables
Section titled “Routing Tables”# View routing tableip route showip route show table mainip route show table all # all routing tables
# Default routeip route add default via 192.168.1.1 dev eth0
# Static routeip route add 10.0.0.0/24 via 192.168.1.254 dev eth0
# Blackhole route (silently drop)ip route add blackhole 10.10.10.0/24
# Prohibit route (reject with ICMP prohibited)ip route add prohibit 10.10.10.0/24
# Throw route (delegate to another table)ip route add throw 10.10.10.0/24 table 100
# Delete routeip route del 10.0.0.0/24 via 192.168.1.254
# Flush routesip route flush table cache # flush routing cachePolicy Routing
Section titled “Policy Routing”Linux supports multiple routing tables and policy-based routing (PBR). The ip rule command selects Which routing table to use based on source address, destination address, TOS, firewall mark, etc.
# List routing rulesip rule show
# Add rule: traffic from 10.0.0.0/24 uses table 100ip rule add from 10.0.0.0/24 table 100
# Add rule: traffic marked with fwmark 0x1 uses table 200ip rule add fwmark 0x1 table 200
# Add to custom tableip route add 10.10.10.0/24 via 192.168.2.1 dev eth1 table 100ip route add default via 192.168.2.1 dev eth1 table 100
# Priority (lower = evaluated first)ip rule add priority 100 from 10.0.0.0/24 table 100ip rule add priority 200 from 172.16.0.0/16 table 200# View ARP tableip neigh showarp -an
# Add static ARP entryip neigh add 192.168.1.100 lladdr 00:11:22:33:44:55 dev eth0 nud permanent
# Delete ARP entryip neigh del 192.168.1.100 dev eth0
# Flush ARP cacheip neigh flush allDNS Resolution
Section titled “DNS Resolution”/etc/resolv.conf
Section titled “/etc/resolv.conf”# Traditional DNS configurationcat /etc/resolv.conf# nameserver 8.8.8.8# nameserver 8.8.4.4# search example.com internal.example.com# options timeout:2 attempts:3 rotate single-request-reopensystemd-resolved
Section titled “systemd-resolved”Modern distributions use systemd-resolved as a local DNS resolver and cache:
# Check if systemd-resolved is activesystemctl status systemd-resolved
# Statusresolvectl status
# Query specific serverresolvectl query example.com
# DNS-over-TLSresolvectl dns eth0 1.1.1.1#cloudflare-dns.com
# Per-link DNS configurationresolvectl dns eth0 8.8.8.8 8.8.4.4resolvectl domain eth0 ~example.com/etc/nsswitch.conf
Section titled “/etc/nsswitch.conf”Name Service Switch determines the order of lookup methods:
hosts: files dns mdns4_minimal [NOTFOUND=return] dnsThe lookup order: local files (/etc/hosts) first, then DNS. The mdns4_minimal entry handles Multicast DNS (.local domain) and returns NOTFOUND for non-.local names, which then falls Through to regular DNS.
dig and nslookup
Section titled “dig and nslookup”# Query A recorddig example.com
# Query specific record typedig MX example.comdig TXT example.comdig CNAME www.example.com
# Query from specific serverdig @8.8.8.8 example.com
# Reverse DNS lookupdig -x 8.8.8.8
# Short outputdig +short example.com
# Trace DNS resolution pathdig +trace example.com
# DNSSEC validationdig +dnssec example.comNetfilter Framework
Section titled “Netfilter Framework”Netfilter is the kernel-level packet filtering framework that provides hooks at five points in the Networking stack. It is the foundation for iptables``nftablesAnd connection tracking.
Netfilter Hooks
Section titled “Netfilter Hooks”graph LR A[Incoming Packet] --> B[PREROUTING] B --> C{Routing Decision} C -->|Local| D[INPUT] C -->|Forward| E[FORWARD] D --> F[Local Process] F --> G[OUTPUT] E --> H[POSTROUTING] G --> H H --> I[Outgoing Packet]| Hook | Chains (iptables) | Description |
|---|---|---|
| NF_INET_PRE_ROUTING | PREROUTING | Before routing decision — DNAT, mangling |
| NF_INET_LOCAL_IN | INPUT | Packets destined for local processes |
| NF_INET_FORWARD | FORWARD | Packets being forwarded (router) |
| NF_INET_LOCAL_OUT | OUTPUT | Packets originating from local processes |
| NF_INET_POST_ROUTING | POSTROUTING | After routing decision — SNAT, masquerading |
Connection Tracking (conntrack)
Section titled “Connection Tracking (conntrack)”The nf_conntrack module tracks the state of network connections. It classifies packets into Connection states:
| State | Description |
|---|---|
NEW | First packet of a connection (no matching entry yet) |
ESTABLISHED | Connection is established (both directions seen) |
RELATED | Packet related to an existing connection (e.g., FTP data, ICMP error) |
UNREPLIED | Connection entry exists but no response packet seen |
INVALID | Packet does not match any known connection |
# View connection tracking tableconntrack -Lconntrack -L -s 192.168.1.0/24 # source filterconntrack -L -d 10.0.0.1 # destination filter
# Count tracked connectionsconntrack -C
# Delete all tracked connectionsconntrack -F
# View connection tracking statisticscat /proc/net/nf_conntrackcat /proc/sys/net/netfilter/nf_conntrack_countcat /proc/sys/net/netfilter/nf_conntrack_max
# Increase conntrack table sizesysctl -w net.netfilter.nf_conntrack_max=262144Intuition
Section titled “Intuition”Processes are programs in execution, each with its own memory space and priority. Systemd manages the lifecycle of services, starting them at boot and restarting them if they fail. Understanding process states (running, sleeping, stopped, zombie) helps you diagnose why a service is not responding. Signals like SIGTERM and SIGKILL provide graceful and forceful ways to control processes.