This bash script provides a fast, zero-dependency snapshot of a Linux system’s network state using standard tools and /proc interfaces. It reports active interfaces and addresses, the default route, recent per-interface RX/TX activity, total established sockets, and a simple external connectivity check. Output is colorized for quick scanning and designed to be readable at a glance. The script is safe to run on any modern Linux system and is useful for quick diagnostics, troubleshooting, or verifying network health without installing additional utilities.
#!/bin/bash
# Network Diagnostic Script
# Uses standard tools and /proc interfaces
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}=== NETWORK DIAGNOSTIC SUMMARY ===${NC}"
echo -e "\n${YELLOW}ACTIVE INTERFACES:${NC}"
ip -br addr show up | while read -r iface state iprest; do
echo -e " ${GREEN}$iface${NC} ($state) → $iprest"
done
echo -e "\n${YELLOW}DEFAULT ROUTE:${NC}"
if ip route show default | grep -q '^default'; then
ip route show default | sed 's/^/ /'
else
echo -e " ${RED}No default route configured${NC}"
fi
echo -e "\n${YELLOW}RECENT BANDWIDTH (last 1s):${NC}"
echo " Interface RX (KB/s) TX (KB/s)"
prev_rx=()
prev_tx=()
mapfile -t interfaces < <(grep '^[a-z]' /proc/net/dev | cut -d: -f1 | tr -d ' ')
for iface in "${interfaces[@]}"; do
read rx tx < <(awk -F'[: ]+' "/^ *$iface:/ {print \$2, \$10}" /proc/net/dev)
prev_rx+=("$rx")
prev_tx+=("$tx")
done
sleep 1
i=0
for iface in "${interfaces[@]}"; do
read rx tx < <(awk -F'[: ]+' "/^ *$iface:/ {print \$2, \$10}" /proc/net/dev)
rx_rate=$(( (rx - prev_rx[i]) / 1024 ))
tx_rate=$(( (tx - prev_tx[i]) / 1024 ))
printf " %-10s %8d %10d\n" "$iface" "$rx_rate" "$tx_rate"
((i++))
done
echo -e "\n${YELLOW}ESTABLISHED CONNECTIONS:${NC}"
ss -tuln 2>/dev/null | tail -n +2 | wc -l | xargs -I {} echo " {} active sockets"
echo -e "\n${YELLOW}CONNECTIVITY TEST:${NC}"
if timeout 3 ping -c1 -q 1.1.1.1 >/dev/null 2>&1; then
echo -e " ${GREEN}✓ Internet reachable${NC}"
else
echo -e " ${RED}✗ No response from 1.1.1.1${NC}"
fi
echo -e "\n${BLUE}=== END NETWORK SUMMARY ===${NC}"
Bash Scripting Series - Ben Santora - January 2026
Top comments (2)
Nice script — the approach is very clear.
Thanks, glad you found it useful.