Linux Network Troubleshooting: Master the One-Liner Diagnostic
Description
How to Troubleshoot Linux Network Issues Quickly?
Quick Answer: Use ip -c -br addr show && ip route && ip neigh
to instantly check interfaces, routing, and ARP tables. The modern ip
command replaces outdated tools like ifconfig and netstat for comprehensive network diagnostics.
Essential Network Troubleshooting Commands
# Complete network status in one command
ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show
# Check interface status quickly
ip -c -br link show
# Show only active interfaces
ip link show up
# Display routing table
ip route show
# Check default gateway
ip route show default
# View ARP table
ip neigh show
# Test connectivity to specific IP
ping -c 4 8.8.8.8
# Check DNS resolution
nslookup google.com
# Show interface statistics
ip -s link show eth0
# Monitor network changes in real-time
ip monitor
Frequently Asked Questions
Q: What command replaces ifconfig in modern Linux? A: The ip
command replaces ifconfig. Use ip addr show
instead of ifconfig -a
to display network interfaces and IP addresses with better formatting and features.
Q: How do I check if my network interface is up? A: Use ip link show up
to see only active interfaces, or ip -br link show
for a brief overview of all interfaces with their status (UP/DOWN).
Q: What’s the fastest way to check network connectivity? A: Use ping -c 4 8.8.8.8
to test internet connectivity, then ip route show default
to verify your default gateway configuration.
Q: How do I view the routing table in Linux? A: Use ip route show
to display the complete routing table, or ip route show default
to see only the default gateway information.
Q: How can I see all network information at once? A: Use the one-liner: ip -c -br addr show && ip route && ip neigh
to display interfaces, routing, and ARP information in a single command.
Essential Steps to Diagnose Network Issues
- Check interface status: Use
ip -br link show
to verify network interfaces are UP and configured - Verify IP configuration: Use
ip addr show
to confirm IP addresses are assigned correctly - Test local connectivity: Use
ping gateway_ip
to verify connection to your router/gateway - Check routing table: Use
ip route show
to ensure proper routing configuration - Test external connectivity: Use
ping 8.8.8.8
to verify internet connectivity - Verify DNS resolution: Use
nslookup domain.com
to check domain name resolution
Most Important Network Diagnostic Commands
Command | Purpose | Use Case |
---|---|---|
ip -br addr show | Show all interfaces and IPs | Quick interface overview |
ip route show default | Display default gateway | Check internet routing |
ping -c 4 8.8.8.8 | Test internet connectivity | Verify external access |
ip neigh show | Display ARP table | Check local network devices |
ss -tuln | Show listening ports | Check running services |
What Are the Most Important ip Command Options?
Essential Interface Commands
# Brief interface overview
ip -br addr show
# Detailed interface information
ip addr show eth0
# Show only active interfaces
ip link show up
# Interface statistics and errors
ip -s link show eth0
Critical Routing Commands
# Complete routing table
ip route show
# Default gateway only
ip route show default
# Route to specific destination
ip route get 8.8.8.8
# Add temporary route
sudo ip route add 192.168.1.0/24 via 10.0.0.1
How Do You Check Network Connectivity Step-by-Step?
1. Verify Physical and Link Layer
# Check if interfaces exist and are UP
ip link show
# Check cable connection (for Ethernet)
ethtool eth0 | grep "Link detected"
# View interface statistics for errors
ip -s link show eth0
2. Verify Network Layer Configuration
# Check IP address assignment
ip addr show
# Verify subnet configuration
ip route show | grep "scope link"
# Check for IP conflicts
ping -c 1 $(ip route show default | awk '{print $3}')
3. Test Network Connectivity
# Test local gateway connectivity
ping -c 4 $(ip route show default | awk '{print $3}')
# Test external connectivity
ping -c 4 8.8.8.8
# Test DNS connectivity
ping -c 4 google.com
What Network Information Does ip Command Provide?
Interface Information
# Show all network interfaces
ip addr show
# Brief format for quick overview
ip -br addr show
# Color output for better readability
ip -c addr show
# Show specific interface details
ip addr show dev eth0
Routing Information
# Complete routing table
ip route show
# IPv6 routing table
ip -6 route show
# Routing cache information
ip route show cache
# Policy routing rules
ip rule show
Neighbor Discovery (ARP)
# Show ARP table entries
ip neigh show
# Show only reachable neighbors
ip neigh show nud reachable
# IPv6 neighbor discovery
ip -6 neigh show
# Neighbors on specific interface
ip neigh show dev eth0
What Are Advanced Network Troubleshooting Techniques?
Performance Analysis
# Monitor interface bandwidth
ip -s link show eth0 | grep bytes
# Check for packet drops
ip -s link show | grep -E "(RX|TX).*dropped"
# Real-time network monitoring
watch -n 1 'ip -s link show eth0'
# Check interface errors
ethtool -S eth0 | grep error
DNS Troubleshooting
# Test DNS resolution
nslookup google.com
# Use different DNS server
nslookup google.com 8.8.8.8
# Check DNS configuration
cat /etc/resolv.conf
# Test reverse DNS lookup
nslookup 8.8.8.8
Port and Service Diagnostics
# Show listening ports (replaces netstat)
ss -tuln
# Show specific port
ss -tuln | grep :80
# Show processes using ports
ss -tulnp
# Check if specific port is open
nc -zv google.com 80
When Should You Use Different Diagnostic Commands?
Basic Connectivity Issues
# No internet connection
ping -c 4 8.8.8.8 # Test external connectivity
ip route show default # Check default gateway
ip addr show # Verify IP configuration
# Can't reach local devices
ip neigh show # Check ARP table
ping -c 4 192.168.1.1 # Test gateway
ip route show | grep "scope link" # Check local routes
Application Connectivity Problems
# Web server not responding
ss -tuln | grep :80 # Check if service is listening
curl -I http://server.com # Test HTTP connectivity
telnet server.com 80 # Test raw TCP connection
# Database connection issues
ss -tuln | grep :3306 # Check MySQL port
ping -c 4 db-server.com # Test basic connectivity
nslookup db-server.com # Verify DNS resolution
Performance Investigation
# Slow network performance
ip -s link show # Check for packet drops/errors
ethtool eth0 | grep Speed # Verify link speed
mtr google.com # Traceroute with statistics
# Intermittent connectivity
ping -i 0.2 gateway_ip # Rapid ping test
watch -n 1 'ip neigh show' # Monitor ARP changes
What Are All ip Command Options?
Option | Description | Example |
---|---|---|
-br | Brief output format | ip -br addr show |
-c | Colorized output | ip -c route show |
-s | Show statistics | ip -s link show |
-4 | IPv4 only | ip -4 addr show |
-6 | IPv6 only | ip -6 addr show |
-j | JSON output | ip -j addr show |
-p | Pretty JSON output | ip -jp addr show |
-d | Detailed output | ip -d link show |
What Are Essential Network Troubleshooting Practices?
Systematic Approach
# Always start with the one-liner overview
ip -c -br addr show && echo "--- ROUTES ---" && ip route show && echo "--- ARP ---" && ip neigh show
# Document baseline configurations
ip addr show > network_baseline_$(date +%Y%m%d).txt
ip route show >> network_baseline_$(date +%Y%m%d).txt
# Test in layers (OSI model approach)
# 1. Physical: Check cables and interface status
# 2. Network: Test IP connectivity
# 3. Transport: Check ports and services
# 4. Application: Test specific applications
Performance Monitoring
# Create monitoring aliases
alias netstat='ss -tuln'
alias netmon='watch -n 2 "ip -s link show"'
alias routecheck='ip route show && ip neigh show'
# Regular network health checks
#!/bin/bash
echo "=== Network Health Check $(date) ==="
ip -br link show
ping -c 1 $(ip route show default | awk '{print $3}') >/dev/null && echo "Gateway: OK" || echo "Gateway: FAIL"
ping -c 1 8.8.8.8 >/dev/null && echo "Internet: OK" || echo "Internet: FAIL"
How Can You Create Useful Network Aliases?
Essential Network Aliases
# Add to ~/.bashrc
alias netinfo='ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show'
alias netstat='ss -tuln'
alias ports='ss -tulnp'
alias gateway='ip route show default'
alias myip='curl -s ifconfig.me'
Advanced Network Functions
# Network troubleshooting function
netcheck() {
echo "=== Interface Status ==="
ip -br link show
echo -e "\n=== IP Configuration ==="
ip -br addr show
echo -e "\n=== Default Gateway ==="
ip route show default
echo -e "\n=== DNS Test ==="
nslookup google.com | head -5
}
# Quick connectivity test
conntest() {
local target=${1:-8.8.8.8}
echo "Testing connectivity to $target..."
if ping -c 3 "$target" >/dev/null 2>&1; then
echo "✓ Connectivity to $target: OK"
else
echo "✗ Connectivity to $target: FAILED"
fi
}
What Commands Are Related to Network Troubleshooting?
ss
– Socket statistics (replaces netstat)ping
– Test network connectivitytraceroute
– Trace network path to destinationmtr
– Continuous traceroute with statisticsnslookup/dig
– DNS lookup and troubleshootingnc
(netcat) – Network connection testingethtool
– Ethernet interface configurationtcpdump
– Network packet capture and analysis
Common Network Troubleshooting Problems and Solutions
“Network is unreachable” Errors
Problem: Cannot connect to any external networks
# Error: Network is unreachable
Diagnosis:
# Check interface status
ip link show
# Check IP configuration
ip addr show
# Check routing table
ip route show
# Check default gateway
ip route show default
Solutions:
# Bring interface up if down
sudo ip link set eth0 up
# Add default route if missing
sudo ip route add default via 192.168.1.1
# Restart networking service
sudo systemctl restart networking
# Check DHCP configuration
sudo dhclient eth0
DNS Resolution Failures
Problem: Can ping IP addresses but not domain names
Diagnosis:
# Test basic connectivity
ping -c 4 8.8.8.8
# Test DNS resolution
nslookup google.com
# Check DNS configuration
cat /etc/resolv.conf
# Test different DNS server
nslookup google.com 8.8.8.8
Solutions:
# Fix DNS configuration
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
# Restart DNS service
sudo systemctl restart systemd-resolved
# Flush DNS cache
sudo systemctl flush-dns
# Use public DNS temporarily
dig @8.8.8.8 google.com
Interface Not Coming Up
Problem: Network interface remains DOWN
Diagnosis:
# Check interface status
ip link show eth0
# Check for hardware issues
dmesg | grep eth0
# Check interface configuration
cat /etc/network/interfaces
# Check NetworkManager status
systemctl status NetworkManager
Solutions:
# Manually bring interface up
sudo ip link set eth0 up
# Restart NetworkManager
sudo systemctl restart NetworkManager
# Check cable connection
ethtool eth0 | grep "Link detected"
# Reset interface configuration
sudo ifdown eth0 && sudo ifup eth0
No Default Gateway
Problem: No route to external networks
Diagnosis:
# Check current routes
ip route show
# Check for default gateway
ip route show default
# Check gateway connectivity
ping -c 4 192.168.1.1 # Replace with your gateway
Solutions:
# Add default gateway manually
sudo ip route add default via 192.168.1.1
# Request DHCP configuration
sudo dhclient eth0
# Check DHCP lease
cat /var/lib/dhcp/dhclient.leases
# Restart networking
sudo systemctl restart networking
ARP Table Issues
Problem: Cannot reach devices on local network
Diagnosis:
# Check ARP table
ip neigh show
# Look for failed entries
ip neigh show | grep FAILED
# Check interface on same subnet
ip route show | grep "scope link"
Solutions:
# Clear ARP cache
sudo ip neigh flush all
# Add static ARP entry
sudo ip neigh add 192.168.1.100 lladdr 00:11:22:33:44:55 dev eth0
# Delete problematic entry
sudo ip neigh del 192.168.1.100 dev eth0
# Force ARP refresh
ping -c 1 192.168.1.100 && ip neigh show 192.168.1.100
Slow Network Performance
Problem: Network connections are slow or dropping packets
Diagnosis:
# Check interface statistics
ip -s link show eth0
# Look for errors and drops
ip -s link show | grep -E "(errors|dropped)"
# Check link speed
ethtool eth0 | grep Speed
# Monitor real-time statistics
watch -n 1 'ip -s link show eth0'
Solutions:
# Check for duplex mismatch
ethtool eth0 | grep -E "(Speed|Duplex)"
# Reset interface statistics
sudo ethtool -S eth0 --reset
# Check MTU size
ip link show eth0 | grep mtu
# Test with different MTU
sudo ip link set eth0 mtu 1500
Port Connection Issues
Problem: Cannot connect to specific services/ports
Diagnosis:
# Check if service is listening
ss -tuln | grep :80
# Test port connectivity
nc -zv server.com 80
# Check firewall rules
sudo iptables -L
# Test local vs remote connectivity
telnet localhost 80
telnet server.com 80
Solutions:
# Start service if not running
sudo systemctl start apache2
# Check service status
sudo systemctl status apache2
# Open firewall port
sudo ufw allow 80
# Test with curl
curl -I http://server.com
# Check SELinux if applicable
sudo setsebool -P httpd_can_network_connect 1
IPv6 Connectivity Issues
Problem: IPv4 works but IPv6 doesn’t
Diagnosis:
# Check IPv6 configuration
ip -6 addr show
# Test IPv6 connectivity
ping6 google.com
# Check IPv6 routing
ip -6 route show
# Check IPv6 neighbors
ip -6 neigh show
Solutions:
# Enable IPv6 if disabled
echo 0 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6
# Request IPv6 from DHCP
sudo dhclient -6 eth0
# Check router advertisements
sudo radvdump
# Add IPv6 route manually
sudo ip -6 route add default via fe80::1 dev eth0
Network Namespace Issues
Problem: Connectivity works in one namespace but not another
Diagnosis:
# List network namespaces
ip netns list
# Check interface in namespace
sudo ip netns exec namespace1 ip addr show
# Check routing in namespace
sudo ip netns exec namespace1 ip route show
Solutions:
# Move interface to namespace
sudo ip link set eth1 netns namespace1
# Add route in namespace
sudo ip netns exec namespace1 ip route add default via 192.168.1.1
# Test connectivity in namespace
sudo ip netns exec namespace1 ping 8.8.8.8
# Create veth pair for namespace communication
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth1 netns namespace1
Mastering modern Linux network troubleshooting with the ip
command and systematic diagnostic approaches enables rapid problem resolution and efficient network management in professional environments.
Detailed Explanation
Detailed Explanation: The Ultimate Network Diagnostic One-Liner
🔍 Command Anatomy
ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ └── Show neighbor/ARP table
│ │ │ │ │ │ │ │ │ │ │ │ │ └────── Neigh command (ARP table)
│ │ │ │ │ │ │ │ │ │ │ │ └───────── Colorized output
│ │ │ │ │ │ │ │ │ │ │ └──────────── IP command
│ │ │ │ │ │ │ │ │ │ └─────────────────────────────── Section separator
│ │ │ │ │ │ │ │ │ └────────────────────────────────────── Show routing table
│ │ │ │ │ │ │ │ └──────────────────────────────────────────── Route command
│ │ │ │ │ │ │ └─────────────────────────────────────────────── Colorized output
│ │ │ │ │ │ └────────────────────────────────────────────────── IP command
│ │ │ │ │ └──────────────────────────────────────────────────────────────────────── Section separator
│ │ │ │ └─────────────────────────────────────────────────────────────────────────────── Show addresses
│ │ │ └───────────────────────────────────────────────────────────────────────────────────── Addr command (interfaces)
│ │ └───────────────────────────────────────────────────────────────────────────────────────── Brief format
│ └──────────────────────────────────────────────────────────────────────────────────────────── Colorized output
└─────────────────────────────────────────────────────────────────────────────────────────────── IP command
📋 Component Breakdown
Part 1: ip -c -br addr show
Purpose: Display network interfaces and IP addresses in brief, colorized format
Flag Explanations:
-c
= Colorized output (interfaces, IPs, status in different colors)-br
= Brief format (compact, one-line per interface)addr
= Address command (shows IP assignments)show
= Display current configuration
Part 2: echo "--- ROUTES ---"
Purpose: Visual separator to organize output sections clearly
Part 3: ip -c route show
Purpose: Display routing table with colorized output
What it shows:
- Default gateway configuration
- Network routes and destinations
- Route metrics and preferences
- Interface associations
Part 4: echo "--- ARP ---"
Purpose: Another visual separator for ARP table section
Part 5: ip -c neigh show
Purpose: Display neighbor discovery table (ARP for IPv4, NDP for IPv6)
What it shows:
- MAC address to IP mappings
- Neighbor reachability status
- Interface associations
- Cache timeouts
💻 Real-World Output Example
Complete Command Execution:
$ ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show
Sample Output:
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 192.168.1.100/24 fe80::a00:27ff:fe4e:66a1/64
wlan0 UP 10.0.0.25/24 fe80::b827:ebff:fef0:123a/64
--- ROUTES ---
default via 192.168.1.1 dev eth0 proto dhcp metric 100
10.0.0.0/24 dev wlan0 proto kernel scope link src 10.0.0.25 metric 600
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 100
169.254.0.0/16 dev eth0 scope link metric 1000
--- ARP ---
192.168.1.1 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE
192.168.1.10 dev eth0 lladdr 11:22:33:44:55:66 STALE
10.0.0.1 dev wlan0 lladdr 77:88:99:aa:bb:cc REACHABLE
🎯 Information Provided by Each Section
Interface Information (addr show):
- Interface Names: eth0, wlan0, lo (loopback)
- Status: UP, DOWN, UNKNOWN
- IP Addresses: IPv4 and IPv6 assignments
- Subnet Masks: CIDR notation (/24, /8)
- Link-local Addresses: IPv6 fe80:: addresses
Routing Information (route show):
- Default Gateway: Where traffic goes by default (192.168.1.1)
- Network Routes: Direct connections to local subnets
- Metrics: Route preferences (lower = preferred)
- Protocols: How routes were learned (dhcp, kernel, static)
- Scope: Route applicability (link, global)
ARP/Neighbor Information (neigh show):
- IP to MAC Mapping: Which MAC address has which IP
- Interface Assignment: Which interface learned each entry
- Reachability Status:
- REACHABLE = Recently confirmed active
- STALE = Needs verification
- DELAY = Attempting to verify
- FAILED = Unreachable
🔧 Why This Command is Incredibly Powerful
1. Complete Network State Snapshot
# Instead of running these separately:
ip addr show # Check interfaces
ip route show # Check routing
ip neigh show # Check ARP table
arp -a # Old way for ARP
netstat -rn # Old way for routes
ifconfig # Old way for interfaces
# You get everything in one command with consistent formatting
2. Instant Problem Identification
# Common issues immediately visible:
# No IP address = Interface down or DHCP failure
# No default route = Gateway configuration issue
# Empty ARP table = Network isolation problem
# FAILED neighbors = Connectivity problems
3. Colorized Output Benefits
- Green: Active interfaces and reachable neighbors
- Red: Problem states and unreachable entries
- Yellow: Warning states and stale entries
- Immediate visual feedback without reading details
4. Professional Troubleshooting Workflow
# Step 1: Run diagnostic one-liner
ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show
# Step 2: Analyze output systematically
# - Are interfaces UP?
# - Are IP addresses assigned?
# - Is default route present?
# - Are neighbors reachable?
# Step 3: Target specific issues based on findings
🚀 Practical Usage Scenarios
Scenario 1: Server Cannot Connect to Internet
$ ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show
# Analysis:
# ✅ Interface UP with IP: 192.168.1.100/24
# ❌ No default route shown
# ✅ ARP entry for local gateway exists
# Diagnosis: Missing default route - gateway configuration issue
Scenario 2: Intermittent Connectivity Issues
$ ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show
# Analysis:
# ✅ Interface UP with correct IP
# ✅ Default route present
# ❌ Gateway shows STALE or FAILED in ARP table
# Diagnosis: Gateway connectivity problem - network hardware issue
Scenario 3: Application Cannot Reach Database
$ ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show
# Analysis:
# ✅ Local interface configuration correct
# ❌ No route to database subnet (10.0.1.0/24)
# ❌ No ARP entries for database IP range
# Diagnosis: Missing route to database network
💡 Pro Tips for Maximum Effectiveness
1. Create an Alias
# Add to ~/.bashrc
alias netstat='ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show'
# Usage: just type 'netstat'
2. Save Output for Analysis
# Capture network state for documentation
ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show > network_state_$(date +%Y%m%d_%H%M).txt
3. Combine with Connectivity Testing
# Complete network diagnostic
network_check() {
echo "=== NETWORK STATUS ==="
ip -c -br addr show && echo "--- ROUTES ---" && ip -c route show && echo "--- ARP ---" && ip -c neigh show
echo -e "\n=== CONNECTIVITY TEST ==="
ping -c 1 $(ip route show default | awk '{print $3}') && echo "✅ Gateway reachable" || echo "❌ Gateway unreachable"
}
4. Remote Troubleshooting
# For remote servers via SSH
ssh server "ip -c -br addr show && echo '--- ROUTES ---' && ip -c route show && echo '--- ARP ---' && ip -c neigh show"