Network Debugging
Diagnose and fix network connectivity issues.
Quick Diagnostics
# Basic connectivity
ping -c 4 8.8.8.8
ping -c 4 google.com
# DNS resolution
nslookup google.com
dig google.com
# Network interfaces
ip addr
ip routeConnectivity Issues
Check Network Interface
# Interface status
ip link show
ip addr show eth0
# Bring interface up
sudo ip link set eth0 up
# Check for IP
ip addr show eth0 | grep inetCheck Gateway
# View routing table
ip route
route -n
# Test gateway
ping -c 4 $(ip route | grep default | awk '{print $3}')
# Traceroute
traceroute google.com
mtr google.comCheck Firewall
# UFW status
sudo ufw status verbose
# iptables rules
sudo iptables -L -n -v
sudo iptables -t nat -L -n
# Temporarily disable firewall (testing only!)
sudo ufw disableDNS Issues
Test Resolution
# Using specific DNS server
nslookup google.com 8.8.8.8
dig @8.8.8.8 google.com
# Check /etc/resolv.conf
cat /etc/resolv.conf
# Test local resolution
getent hosts hostnameFix DNS
# Temporary fix
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
# Permanent fix (systemd-resolved)
sudo nano /etc/systemd/resolved.conf
# Add: DNS=8.8.8.8 8.8.4.4
sudo systemctl restart systemd-resolvedPort Connectivity
Check Listening Ports
# All listening ports
ss -tuln
netstat -tuln
# Specific port
ss -tuln | grep :80
# What's using a port
sudo lsof -i :80
sudo fuser 80/tcpTest Remote Ports
# TCP port test
nc -zv host 80
telnet host 80
# Multiple ports
nmap -p 80,443,22 host
# Check if port is blocked
sudo tcpdump -i eth0 port 80Connection Issues
Check Established Connections
# All connections
ss -tn
# By state
ss -tn state established
ss -tn state time-wait
# Connection count
ss -sDebug Application Connections
# HTTP test
curl -v http://example.com
curl -I http://example.com
# With timing
curl -w "@curl-format.txt" -o /dev/null -s http://example.com
# SSL/TLS test
openssl s_client -connect host:443Common Issues & Fixes
| Issue | Diagnostic | Fix |
|---|---|---|
| No IP | ip addr |
sudo dhclient eth0 |
| DNS fail | nslookup |
Check /etc/resolv.conf |
| Port blocked | nc -zv |
Check firewall rules |
| High latency | mtr host |
Check for packet loss |
| Connection refused | ss -tuln |
Start the service |
Packet Capture
# Capture all traffic
sudo tcpdump -i eth0
# Specific host
sudo tcpdump -i eth0 host 192.168.1.1
# Specific port
sudo tcpdump -i eth0 port 80
# Save to file
sudo tcpdump -i eth0 -w capture.pcap - network
- troubleshooting
- dns
- connectivity
- firewall