Network_config
Chapter 22: Network Configuration - Deep Dive
Section titled “Chapter 22: Network Configuration - Deep Dive”Mastering Linux Network Configuration for Production Systems
Section titled “Mastering Linux Network Configuration for Production Systems”22.1 The ip Command Suite
Section titled “22.1 The ip Command Suite”Understanding ip command
Section titled “Understanding ip command”The ip command is the modern replacement for older commands like ifconfig, route, and netstat. It’s part of the iproute2 package and provides more functionality.
Network Configuration Tools+------------------------------------------------------------------+| || Legacy Tools (Deprecated) Modern Tools (iproute2) || +---------------------------+ +---------------------------+ || | ifconfig | | ip addr | || | route | | ip route | || | netstat | | ip link, ip neigh | || | arp | | ip addr | || | iwconfig | | iw, iwlist | || +---------------------------+ +---------------------------+ || || Why use ip: || +----------------------------------------------------------+ || | - More features and flexibility | || | - Supports IPv6 natively | || | - Better network namespace support | || | - Active development | || +----------------------------------------------------------+ || |+------------------------------------------------------------------+Interface Management
Section titled “Interface Management”# =============================================================================# SHOW INTERFACES# =============================================================================
# Show all interfaces with detailsip addr showip a
# Show specific interfaceip addr show eth0
# Brief outputip -brief addr showip -brief link show
# Show interface statisticsip -s link show eth0
# Show interface propertiesip link show
# =============================================================================# INTERFACE UP/DOWN# =============================================================================
# Bring interface upsudo ip link set eth0 up
# Bring interface downsudo ip link set eth0 down
# Bring up with descriptionsudo ip link set eth0 up description "WAN Interface"
# =============================================================================# MTU CONFIGURATION# =============================================================================
# Set MTUsudo ip link set eth0 mtu 9000
# Set MTU for jumbo framessudo ip link set eth0 mtu 9000
# Check MTUip link show eth0 | grep mtuIP Address Management
Section titled “IP Address Management”# =============================================================================# ADD IP ADDRESS# =============================================================================
# Add IPv4 addresssudo ip addr add 192.168.1.100/24 dev eth0
# Add IPv6 addresssudo ip addr add fd00::1/64 dev eth0
# Add with labelsudo ip addr add 192.168.1.100/24 dev eth0 label eth0:1
# Add broadcast addresssudo ip addr add 192.168.1.100/24 broadcast 192.168.1.255 dev eth0
# =============================================================================# REMOVE IP ADDRESS# =============================================================================
# Remove specific addresssudo ip addr del 192.168.1.100/24 dev eth0
# Flush all addresses (IPv4)sudo ip -4 addr flush dev eth0
# Flush all addresses (IPv6)sudo ip -6 addr flush dev eth0
# Flush all addressessudo ip addr flush dev eth0
# =============================================================================# SHOW ADDRESSES# =============================================================================
# Show IPv4 addresses onlyip -4 addr show
# Show IPv6 addresses onlyip -6 addr show
# Show addresses with colorip addr show | grep -w inet22.2 Routing
Section titled “22.2 Routing”Route Management
Section titled “Route Management”# =============================================================================# VIEW ROUTES# =============================================================================
# Show all routesip route showip route
# Show routes for specific interfaceip route show dev eth0
# Show routes in tableip route show table all
# Show main tableip route show table main
# Show local tableip route show table local
# Verbose outputip -r route show
# =============================================================================# ADD ROUTES# =============================================================================
# Add default gatewaysudo ip route add default via 192.168.1.1 dev eth0
# Short form for defaultsudo ip route add via 192.168.1.1 dev eth0
# Add specific routesudo ip route add 192.168.2.0/24 via 192.168.1.1
# Add route with metricsudo ip route add 192.168.2.0/24 via 192.168.1.1 metric 100
# Add route to specific interfacesudo ip route add 192.168.2.0/24 dev eth1
# Add blackhole route (drops traffic)sudo ip route add blackhole 10.0.0.0/8
# Add unreachable routesudo ip route add unreachable 10.0.0.0/8
# =============================================================================# REMOVE ROUTES# =============================================================================
# Remove specific routesudo ip route del 192.168.2.0/24
# Remove default gatewaysudo ip route del default
# Flush all routessudo ip route flush
# Flush cachesudo ip route flush cacheAdvanced Routing
Section titled “Advanced Routing”# =============================================================================# ROUTE TABLES# =============================================================================
# List all tablesip route show table all
# Custom table in /etc/iproute2/rt_tables# Add to file: 100 mytable
# Add route to custom tablesudo ip route add 192.168.100.0/24 via 192.168.1.1 table mytable
# Add default via custom tablesudo ip route add default via 192.168.1.1 table mytable
# Rules for routingip rule showsudo ip rule add from 192.168.1.0/24 table mytablesudo ip rule del from 192.168.1.0/24 table mytable
# =============================================================================# POLICY ROUTING# =============================================================================
# View rulesip rule show
# Add rule (from specific source)sudo ip rule add from 10.0.0.0/8 table internal
# Add rule (to specific destination)sudo ip rule add to 192.168.0.0/16 table dmz
# Add rule with prioritysudo ip rule add pref 100 from 192.168.1.0/24 table admin
# Delete rulesudo ip rule del from 10.0.0.0/822.3 NetworkManager
Section titled “22.3 NetworkManager”nmcli Commands
Section titled “nmcli Commands”# =============================================================================# DEVICE MANAGEMENT# =============================================================================
# List devicesnmcli devicenmcli device status
# Show device detailsnmcli device show eth0
# Connect/disconnectnmcli device connect eth0nmcli device disconnect eth0
# =============================================================================# CONNECTION MANAGEMENT# =============================================================================
# List connectionsnmcli connection shownmcli connection show --active
# Show connection detailsnmcli connection show "Wired connection 1"
# Activate connectionnmcli connection up "Wired connection 1"
# Deactivate connectionnmcli connection down "Wired connection 1"
# =============================================================================# CREATE CONNECTION# =============================================================================
# Static IPnmcli connection add type ethernet con-name "static-eth0" \ ifname eth0 \ ipv4.addresses 192.168.1.100/24 \ ipv4.gateway 192.168.1.1 \ ipv4.dns "8.8.8.8,8.8.4.4" \ ipv4.method manual
# DHCPnmcli connection add type ethernet con-name "dhcp-eth0" \ ifname eth0 \ ipv4.method auto
# =============================================================================# MODIFY CONNECTION# =============================================================================
# Change IP addressnmcli connection modify "static-eth0" \ ipv4.addresses 192.168.1.200/24
# Change gatewaynmcli connection modify "static-eth0" \ ipv4.gateway 192.168.1.254
# Add DNSnmcli connection modify "static-eth0" \ +ipv4.dns "8.8.8.8"
# Remove DNSnmcli connection modify "static-eth0" \ -ipv4.dns "8.8.8.8"
# Enable/disable IPv6nmcli connection modify "static-eth0" ipv6.method disabled22.4 DNS Configuration
Section titled “22.4 DNS Configuration”/etc/resolv.conf
Section titled “/etc/resolv.conf”# DNS configuration filenameserver 8.8.8.8nameserver 8.8.4.4nameserver 1.1.1.1
# Search domainssearch example.com corp.example.com
# Optionsoptions timeout:2options attempts:3options rotateoptions edns0systemd-resolved
Section titled “systemd-resolved”# =============================================================================# SYSTEMD-RESOLVED# =============================================================================
# Statusresolvectl statussystemd-resolve --status
# Query DNSresolvectl query google.com
# Set DNS serversudo resolvectl dns eth0 8.8.8.8
# Add DNS serversudo resolvectl --interface eth0 dns 8.8.8.8
# Flush cachesudo resolvectl flush-caches
# =============================================================================# STATIC DNS# =============================================================================
# /etc/systemd/resolved.conf[Resolve]DNS=8.8.8.8 8.8.4.4Domains=example.comDNSSEC=noCache=yes22.5 Troubleshooting
Section titled “22.5 Troubleshooting”Network Diagnostics
Section titled “Network Diagnostics”# =============================================================================# BASIC TESTS# =============================================================================
# Check interface statusip link showip addr show
# Test connectivityping -c 4 8.8.8.8
# Trace routetraceroute 8.8.8.8mtr 8.8.8.8
# DNS lookupnslookup google.comdig google.comhost google.com
# =============================================================================# PORT SCANNING# =============================================================================
# Check open portsss -tulnnetstat -tuln
# Check specific portss -tuln | grep :80
# Test port connectivitync -zv 192.168.1.1 80telnet 192.168.1.1 80
# =============================================================================# DETAILED DIAGNOSTICS# =============================================================================
# Interface statisticsip -s link show eth0
# ARP tableip neigh showarp -a
# Routing table cacheip route get 8.8.8.8
# Kernel parameterssysctl net.ipv4.ip_forwardsysctl net.ipv4.conf.all.rp_filter22.6 Exam Tips
Section titled “22.6 Exam Tips”- ip addr: Primary command for IP management
- ip route: For routing table management
- NetworkManager: For persistent configurations
- DNS: /etc/resolv.conf or systemd-resolved
- Troubleshoot: Use ss, ping, traceroute
- Interfaces: Know eth0, ens*,eno* naming
- MTU: 1500 default, 9000 for jumbo frames
- Gateway: Default route via ip route add default
Summary
Section titled “Summary”In this chapter, you learned:
- ✅ ip command fundamentals
- ✅ Interface management (ip link)
- ✅ IP address management (ip addr)
- ✅ Routing (ip route)
- ✅ NetworkManager (nmcli)
- ✅ DNS configuration
- ✅ Network troubleshooting
Next Chapter
Section titled “Next Chapter”Chapter 23: Firewalls - iptables, nftables, firewalld
Last Updated: February 2026