Command linemediumBash

Network Troubleshooting Commands

Essential network diagnostic tools for connectivity, DNS, and port checking.

01

The problem

You need to diagnose network connectivity, DNS issues, or check open ports.

02

The solution

Bash
# Basic connectivity test
ping google.com
ping -c 4 8.8.8.8      # Send 4 packets

# Trace route
traceroute google.com
tracepath google.com   # No root required

# DNS lookup
nslookup google.com
dig google.com
dig google.com A       # Specific record type
dig MX google.com      # MX records
host google.com

# Check DNS resolution speed
time nslookup google.com

# Network interface info
ip addr show
ifconfig              # Deprecated but still used

# Routing table
ip route show
route -n

# Open ports and connections
netstat -tulpn        # All listening ports
ss -tulpn             # Modern alternative
lsof -i :8080         # What's using port 8080

# Test specific port
nc -zv google.com 443
telnet google.com 443

# Download/upload test
curl -O https://example.com/file.zip
wget https://example.com/file.zip

# HTTP requests with headers
curl -I https://google.com
curl -v https://api.example.com

# Bandwidth testing (if installed)
speedtest-cli
iperf3 -c server.address

# Network speed between points
scp file.txt user@server:/tmp  # Time the transfer

# Check network configuration
cat /etc/resolv.conf
cat /etc/hosts

03

Put it to work

Example
# Full network diagnostic
ping -c 4 google.com
# If fails:
ping -c 4 8.8.8.8
# If works:
nslookup google.com
# Check specific service:
nc -zv api.github.com 443
# Check local server:
netstat -tulpn | grep :3000

Worth knowing

Use nc (netcat) for port testing. ss replaces netstat in modern systems. curl -I shows headers only.