Overview and What You Will Learn
Linux networking tools are small command-line programs that each inspect one layer of the network path: interfaces and routes (ip), sockets and ports (ss), name resolution (dig), HTTP (curl), the path between hosts (ping, mtr), and raw packets (tcpdump). Picking the right one first is what turns a 20-minute guessing session into a 2-minute diagnosis.
By the end of this lab you will:
- Inspect interfaces, addresses, and routes with
ip - Find listening services and connection states with
ss - Diagnose DNS failures with
digandresolvectl - Test HTTP endpoints and break latency into DNS, connect, TLS, and first byte with
curl - Test ports with
ncand trace the path withping,traceroute, andmtr - Capture and read packets with
tcpdump - Follow a layered checklist from "service unreachable" to root cause
Why This Matters in Production
Network incidents are stressful because the same symptom, "timeout", can come from DNS, routing, a firewall, a stopped service, or an overloaded dependency. An engineer who knows one tool per layer isolates the cause quickly. An engineer who only knows ping often escalates an hour too early.
Teams running large request volumes, such as Cloudflare and Netflix, rely on this same layered approach: confirm the name resolves, confirm the port answers, confirm the path is clean, and only then capture packets.
Core Principles
Work from the bottom of the problem upward, and test each layer separately. Each question below has one tool that answers it.
resolve?} B -->|No| C[dig, resolvectl
DNS layer] B -->|Yes| D{Is the port
open?} D -->|No| E[ss, nc, curl -v
service or firewall] D -->|Yes| F{Is the path
clean?} F -->|No| G[mtr, ip route get
routing layer] F -->|Yes| H[tcpdump
inspect packets] classDef start fill:#475569,color:#ffffff classDef decide fill:#DBEAFE,color:#1E293B classDef tool fill:#326CE5,color:#ffffff classDef deep fill:#8B5CF6,color:#ffffff class A start class B,D,F decide class C,E,G tool class H deep
| Layer | Question | Tool |
|---|---|---|
| Interface | Is the NIC up with the right address? | ip addr, ip -s link |
| Routing | Where does traffic to this IP go? | ip route get, mtr |
| DNS | Does the name resolve to the right IP? | dig, resolvectl |
| Transport | Is anything listening, is the port reachable? | ss, nc |
| Application | Does the HTTP request succeed, and how fast? | curl -v |
| Packets | What is actually on the wire? | tcpdump |
Remember
ifconfig,netstat, androuteare legacy tools. The modern replacements areipandss, which ship on every current distribution.
Detailed Step-by-Step Practical Lab
Milestone 1: How to Inspect Interfaces and Routes with ip
ip -br addr # Full view of one interfaceip addr show eth0# 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP# inet 10.0.1.50/24 brd 10.0.1.255 scope global eth0 # Routing table and default gatewayip route show# default via 10.0.1.1 dev eth0# 10.0.1.0/24 dev eth0 proto kernel scope link src 10.0.1.50 # Which route and source address will this destination use?ip route get 10.0.2.100 # Interface counters: non-zero errors or drops point to link problemsip -s link show eth0 # Temporary changes (lost on reboot)sudo ip addr add 10.0.1.100/24 dev eth0sudo ip addr del 10.0.1.100/24 dev eth0sudo ip route add 192.168.10.0/24 via 10.0.1.1Tip
ip route get DESTanswers "which interface and gateway will this packet use?" directly, which is faster than reading the whole routing table.
Changes made with ip do not survive a reboot. Make permanent ones in netplan, NetworkManager, or your cloud's network configuration.
Milestone 2: How to Find Listening Ports and Connections with ss
# Listening TCP and UDP sockets with owning processessudo ss -tulpn# Netid State Local Address:Port Process# tcp LISTEN 0.0.0.0:22 sshd# tcp LISTEN 0.0.0.0:443 nginx# tcp LISTEN 127.0.0.1:5432 postgres # Is anything listening on port 4000?sudo ss -tlpn | grep ':4000' # Established connections to PostgreSQLss -tn state established '( dport = :5432 or sport = :5432 )' # Count TCP connections by statess -tan | awk 'NR>1 {print $1}' | sort | uniq -c | sort -rn# 2450 ESTAB# 342 CLOSE-WAIT# 12 TIME-WAITThe address matters as much as the port. 127.0.0.1:5432 accepts only local connections, while 0.0.0.0:5432 accepts connections from any interface. A service "listening" on loopback is unreachable from other hosts.
A large and growing number of CLOSE-WAIT sockets usually means the application is not closing connections it received.
Milestone 3: How to Diagnose DNS with dig
# Full answer, then just the addressdig payments-api.mumbai-prod.devops.indig +short payments-api.mumbai-prod.devops.in # Other record typesdig MX devops.indig NS devops.indig TXT devops.indig AAAA payments-api.mumbai-prod.devops.in # Ask a specific resolver, bypassing the local onedig @8.8.8.8 payments-api.mumbai-prod.devops.indig @1.1.1.1 payments-api.mumbai-prod.devops.in # Follow resolution from the root serversdig +trace payments-api.mumbai-prod.devops.in # Reverse lookupdig -x 10.0.2.100 # What resolver is this host actually using?resolvectl statuscat /etc/resolv.confOn many systems /etc/resolv.conf points to a local stub such as 127.0.0.53. In that case resolvectl status shows the real upstream DNS servers.
RememberIf
dig @8.8.8.8 NAMEworks but the application still fails, the problem is the local resolver configuration, search domains, or a cached answer, not the name itself.
Milestone 4: How to Test HTTP Endpoints and Latency with curl
# Verbose request: shows DNS, TLS handshake, request and response headerscurl -v https://payments-api.mumbai-prod.devops.in/health # Response headers onlycurl -I https://payments-api.mumbai-prod.devops.in/health # POST with a JSON body (store tokens in an environment variable)curl -X POST https://payments-api.mumbai-prod.devops.in/v1/orders \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $API_TOKEN" \ -d '{"amount": 1000, "currency": "INR"}' # Follow redirects and fail on HTTP errorscurl -fsSL https://devops.in/ # Test a new IP before DNS changes propagatecurl --resolve payments-api.mumbai-prod.devops.in:443:10.0.2.100 \ https://payments-api.mumbai-prod.devops.in/health # Retry, with a hard timeout, for health-check scriptscurl --retry 3 --retry-delay 2 --max-time 10 -fsS https://payments-api.mumbai-prod.devops.in/healthTo see where time goes, save a timing format and reuse it:
cat > ~/curl-timing.txt << 'EOF' dns: %{time_namelookup}s connect: %{time_connect}s tls: %{time_appconnect}s ttfb: %{time_starttransfer}s total: %{time_total}s code: %{http_code}EOF curl -o /dev/null -s -w "@$HOME/curl-timing.txt" https://payments-api.mumbai-prod.devops.in/healthA slow dns value points at the resolver, a slow connect at the network or a full accept queue, a slow tls at the handshake, and a slow ttfb at the application.
Milestone 5: How to Check Connectivity with ping, nc, and mtr
# Reachability and round-trip timeping -c 5 10.0.2.100 # Is the TCP port open? (this tests the service, ping does not)nc -zv -w 2 10.0.2.100 5432# Connection to 10.0.2.100 5432 port [tcp/postgresql] succeeded! # Check several portsfor port in 80 443 5432 6379; do if nc -z -w 2 10.0.2.100 "$port"; then echo "port $port: open"; else echo "port $port: closed or filtered"; fidone # Hop-by-hop path, one passtraceroute 10.0.2.100 # Continuous path analysis with loss and latency per hopsudo apt install mtr-tinymtr --report --report-cycles 10 10.0.2.100Read mtr from the destination backward. Loss that appears at one hop and continues to the end is real. Loss at a single middle hop that disappears afterward is usually a router rate-limiting its own replies and is harmless.
Common MistakeUsing
pingto decide whether a service is reachable. ICMP and TCP are independent, so a firewall can allow ping while blocking port 443, or the reverse. Test the actual port withnc -zv HOST PORTorcurl -v.
Milestone 6: How to Capture Packets with tcpdump
sudo apt install tcpdump # Capture on one interface, numeric output (no DNS or port-name lookups)sudo tcpdump -i eth0 -nn # Filter by port, host, or bothsudo tcpdump -i eth0 -nn port 5432sudo tcpdump -i eth0 -nn 'host 10.0.2.100 and port 5432' # Stop after 100 packetssudo tcpdump -i eth0 -nn -c 100 port 443 # Watch DNS queriessudo tcpdump -i eth0 -nn port 53 # Save for Wireshark, rotating into 100 MB files and keeping fivesudo tcpdump -i eth0 -nn -w /var/tmp/capture.pcap -C 100 -W 5 'host 10.0.2.100' # Read a saved capturesudo tcpdump -nn -r /var/tmp/capture.pcap # Only TCP SYN packets, useful for spotting connection attemptssudo tcpdump -i eth0 -nn 'tcp[tcpflags] & (tcp-syn) != 0 and port 5432'Read the TCP flags to understand what happened. Repeated [S] packets with no [S.] reply mean the SYN is being dropped or the host is not answering. An immediate [R.] means the host is reachable but nothing listens on that port.
Security
tcpdumpcan capture credentials and personal data from unencrypted traffic. Capture only what you need with a narrow filter, store files in a restricted directory with mode 600, delete them after analysis, and follow your change-management rules in regulated environments such as PCI-DSS or SOC 2.
Production Best Practices & Common Pitfalls
Diagnose layer by layer, change one thing at a time, and write down what each command showed.
- Start with DNS and port tests before capturing packets, because they are faster and safer.
- Compare from two vantage points: the failing host and a healthy host.
- Use
ss -tulpnto confirm the service listens on the right address, not only the right port. - Use
mtr --reportfor intermittent problems instead of a singleping. - Keep captures short, filtered, and deleted promptly.
| Problem | Wrong first move | Better first move |
|---|---|---|
| Name not resolving | ping NAME |
dig NAME, then dig @8.8.8.8 NAME |
| Port not reachable | Restart the service | ss -tulpn to see if it listens |
| HTTP errors | Read logs only | curl -v to see the full exchange |
| Intermittent loss | One ping |
mtr --report |
| Unknown traffic source | Guess | tcpdump -nn with a narrow filter |
Quick Reference & Troubleshooting Commands
| Task | Command |
|---|---|
| Show addresses | ip -br addr |
| Route for a destination | ip route get IP |
| Listening ports | sudo ss -tulpn |
| DNS lookup | dig +short NAME |
| Test another resolver | dig @8.8.8.8 NAME |
| HTTP with details | curl -v URL |
| Port check | nc -zv HOST PORT |
| Path with loss stats | mtr --report HOST |
| Capture on a port | sudo tcpdump -i eth0 -nn port PORT |
| Symptom | First command | What to look for |
|---|---|---|
| Host cannot reach anything | ip -br addr && ip route show |
Missing address or default route |
| Name fails to resolve | resolvectl status |
Wrong or unreachable DNS server |
| Connection refused | sudo ss -tlpn | grep PORT |
Nothing listening, or loopback only |
| Connection times out | nc -zv -w 2 HOST PORT |
Filtered port, firewall drop |
| Slow responses | curl -w "@$HOME/curl-timing.txt" -o /dev/null -s URL |
Which phase is slow |
| Intermittent failures | mtr --report HOST |
Loss that persists to the destination |
Tip
mtrcombinespingandtracerouteand updates continuously. If loss starts at one hop and continues through every hop after it, that hop or the link just after it is the problem.
RememberRefused and timed out are different answers. Refused means the host replied that nothing listens there. A timeout means the packets were dropped or never answered, which usually points to a firewall or a routing problem.