You use networks every day. You connect to WiFi, you browse websites, you send emails. But do you actually understand what's happening? When something breaks - and it will - you need to know how to diagnose it.
The Basics: IP Addresses
Every device needs an address. IPv4 is running out, but it's what you're using:
# See your IP addresses
ip addr
ip a
# Check specific interface
ip addr show eth0
# Old command (still works)
ifconfig
ifconfig -a
Connectivity: Can You Reach It?
The first test for any network problem:
# Ping - can you reach it?
ping google.com
ping 8.8.8.8
# Continuous ping (Ctrl+C to stop)
ping -c 4 google.com
# Trace the path
traceroute google.com
tracert google.com # Windows
mtr google.com # Continuous traceroute
DNS: The Phonebook
Names to addresses. Addresses to names:
# Query DNS
nslookup google.com
dig google.com
host google.com
# Reverse DNS
dig -x 8.8.8.8
nslookup 8.8.8.8
# Check your DNS servers
cat /etc/resolv.conf
Ports and Connections
What's listening? What's connected?
# See listening ports
ss -tuln
netstat -tuln
# See established connections
ss -tunap
netstat -tunap
# Specific port
ss -tlnp | grep :80
lsof -i :80
HTTP: The Web Protocol
Talk to web servers directly:
# GET request
curl https://example.com
# GET with headers
curl -I https://example.com
curl -v https://example.com
# Download file
curl -O https://example.com/file.txt
# POST data
curl -X POST -d "name=value" https://example.com
Transfer Files
Move data between machines:
# Secure copy scp file.txt user@server:/path/ scp user@server:/path/file.txt ./ # rsync - better for syncing rsync -avz ./local/ user@server:/remote/ rsync -avz --delete ./local/ user@server:/remote/ # wget wget https://example.com/file.zipSSH: The Remote Shell
Your encrypted tunnel to any server:
# Connect ssh user@server # Specific port ssh -p 2222 user@server # Run command remotely ssh user@server "df -h" # Copy key for passwordless login ssh-copy-id user@server # SSH tunnel (proxy through server) ssh -D 8080 user@serverNetwork Troubleshooting Flow
When something doesn't work:
- Can you reach it? ping the IP
- Can you resolve it? nslookup the domain
- Is the port open? ss or netstat
- Can you talk to it? curl or telnet
- What's the route? traceroute
- Check the logs
The Point
Networking seems complex, but it's built on simple concepts. Packets flow from A to B. Addresses get them there. Ports identify the destination service. Protocols define the conversation.
Learn the commands. Practice them. When your site goes down and users complain, you'll be the one who can figure out why.
The network is the foundation of everything. Know it.