Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 24

Network Troubleshooting with Ping, Traceroute, Dig, and cURL

Recommended resources

Hello! Welcome to your fifth lesson in the "Networking for DevOps Engineers" module.

In our last lesson, we took a deep dive into how connections are made, covering the TCP three-way handshake for reliability and the TLS handshake for security. We now understand the complex dance that happens just to open a secure channel to a server.

But as a DevOps engineer, you know that things don't always go as planned. Services become unreachable, APIs become slow, and DNS records point to the wrong place. Your most critical skill in these moments is not just knowing how things should work, but having a systematic process for figuring out why they aren't.

This lesson directly addresses that need and fulfills the learning outcome: Troubleshoot network connectivity and name resolution using ping, traceroute, dig, and curl.

We'll equip you with a core set of command-line tools that form the foundation of network troubleshooting. We will approach this like a real-world incident, following a logical flow:

  1. Connectivity: Is the host even reachable? (ping)
  2. Path Analysis: If not, where is the communication breaking down? (traceroute)
  3. Name Resolution: Can we resolve the hostname to an IP address? (dig)
  4. Application Layer: Is the service itself responding correctly over HTTP/S? (curl)

Let's begin building your troubleshooting toolkit.

1. The First Question: Is the Host Reachable?

When a service is down, the first and simplest question to ask is, "Can my machine even reach the target server?" The tool for this job is ping.

ping operates at the Network Layer (Layer 3) and sends an ICMP (Internet Control Message Protocol) "Echo Request" packet to the target host. If the host is reachable and configured to respond, it sends back an "Echo Reply".

This simple exchange tells you two crucial things:

  • Connectivity: A successful reply confirms that a network path exists between your machine and the target.
  • Latency: The "round-trip time" (RTT) gives you a baseline for how long it takes packets to travel to the host and back.

PING and TRACERT (traceroute) networking commands

This short animated video provides a great overview of ping and how to interpret its most common responses.

Watch the first part of the video from 00:00 to 02:25. Pay close attention to the meaning of different outcomes: a successful reply, 'Request timed out', and 'Destination host unreachable'.

On Linux (and macOS), ping will run continuously until you stop it with Ctrl+C. In a script or for a quick check, it's better to specify a limited number of pings using the -c (count) flag:




# Ping google.com 4 times
ping -c 4 google.com

If ping google.com fails but ping 8.8.8.8 succeeds, you've immediately isolated the problem to DNS name resolution, which we'll cover shortly. If both fail, you have a more fundamental connectivity problem.


2. The Follow-up: Where is the Connection Failing?

If ping fails with timeouts, it means your packets aren't reaching the destination or the replies aren't making it back. The next logical question is, "Where along the path are they getting lost?" For this, we use traceroute.

traceroute sends packets with progressively increasing Time-To-Live (TTL) values. Each router (or "hop") along the path decrements the TTL. When the TTL reaches zero, the router drops the packet and sends an ICMP "Time Exceeded" message back. By analyzing these responses, traceroute maps the entire route your packets take to the destination.

PING and TRACERT (traceroute) networking commands

The second half of the previous video explains traceroute (shown as tracert, its Windows equivalent) and how it helps you visualize the network path.

Watch from 02:46 to 04:20. The key takeaway is how traceroute can isolate a problem to a specific segment of the network, for example, between two routers.

A common issue you'll face is that many firewalls block the ICMP packets that traceroute uses by default. A powerful technique for a DevOps engineer is to use TCP packets instead, as these are less likely to be blocked, especially on common ports like 80 or 443.

To learn more about this and other traceroute options, have a look at the following resource.

Essential Linux Networking Tools for DevOps Engineers

This article, 'Essential Linux Networking Tools for DevOps Engineers', provides excellent, concise examples. We'll be using it throughout the lesson. For now, focus on its traceroute section.

Read the section titled 'traceroute / mtr - Path Analysis'. Note the command for using TCP instead of ICMP. Also, take note of mtr, a powerful tool that combines ping and traceroute for continuous monitoring, which can be very useful for spotting intermittent packet loss.

If you see * * * in the output, it means that hop did not respond. This could mean the router is configured not to send ICMP replies (stealthy) or that there's a genuine issue like high latency or packet loss at that point in the network.


3. The Name Game: Is DNS Working Correctly?

If you can ping an IP address but not a hostname, you have a name resolution problem. The tool for diagnosing this is dig (Domain Information Groper). It is far more detailed than its predecessor, nslookup, and is the standard for DNS troubleshooting on Linux.

dig allows you to query DNS servers for any type of record (A, CNAME, MX, etc.) and provides verbose output about the transaction.

How To Lookup DNS Records With The dig Command

This video is a comprehensive tutorial on using dig. It will walk you through everything from basic lookups to advanced tracing.

Watch the entire video (about 8.5 minutes). It's packed with practical examples: Basic Lookups (00:02 - 02:30): How to get an A record for a domain. Querying Specifics (02:30 - 04:54): How to look up MX records and query a specific DNS server like Google's 8.8.8.8. Advanced Queries (04:54 - 07:28): How to perform a reverse DNS lookup with -x. Tracing Resolution (07:28 - 08:40): The powerful +trace option, which shows the full resolution path from the root servers down. This is invaluable for diagnosing complex DNS issues.

The output of dig can be dense. Let's break down a typical response.

Dig Command Output for linux.org
A standard `dig` output. Notice the distinct sections: `QUESTION` shows what you asked for (an A record for linux.org). `ANSWER` provides the result (the IP address). `AUTHORITY` lists the name servers responsible for this domain. Understanding these sections is key to interpreting the results.

For scripting or quick checks, the +short option is your best friend:




# Get just the IP address
dig +short google.com



# 172.217.16.14

The OneUptime article we looked at earlier also has a fantastic cheat sheet for dig commands that you'll use frequently.

Essential Linux Networking Tools for DevOps Engineers

Revisit the 'Essential Linux Networking Tools' article for more dig examples that are particularly useful in DevOps automation.

Review the 'dig - DNS Lookups' section. The for loop example for checking DNS propagation is a great script to keep in your back pocket when you've made a DNS change. Also, look at the 'DNS Resolution Flow' diagram to visualize the process that dig +trace shows you.


4. The Final Hurdle: Is the Application Itself Okay?

You've confirmed the host is reachable (ping) and DNS is resolving (dig). Yet, users still report the service is down. The problem likely lies at the application layer (Layer 7). Your tool for this is curl (client for URL).

While curl is often used to download files, it's an incredibly powerful tool for interacting with web services and APIs.

A simple curl https://api.example.com/health might tell you if the endpoint is up, but the real power for troubleshooting comes from its flags.

Essential Linux Networking Tools for DevOps Engineers

The curl section of the 'Essential Linux Networking Tools' article is a masterclass in advanced troubleshooting.

Read the 'curl - HTTP Client' section carefully. Focus on these key flags: -I (or --head): Fetches only the HTTP headers. A quick way to check the status code (200 OK, 503 Service Unavailable, etc.). -v (or --verbose): This is extremely useful. It shows the DNS resolution, the TCP connection attempt, and the full TLS handshake, connecting directly to our previous lesson! If a TLS handshake is failing, you will see it here. -w (or --write-out): Allows you to extract detailed timing information. This is a game-changer for diagnosing latency. Is the problem slow DNS? A slow TCP connection? A slow TLS negotiation? Or is the server just slow to respond (time_starttransfer)? This flag tells you exactly where the time is being spent. --resolve: Lets you manually specify an IP for a hostname, bypassing DNS. This is perfect for testing a new server before pointing DNS to it.

Using curl with these flags moves you from "is it working?" to "how and why is it failing?". For example, if you see a long time_connect, you might have a firewall issue or network congestion. If you see a long time_appconnect, there could be a problem with the TLS handshake. If both are fast but time_starttransfer is long, the problem is on the server itself—it's slow to process the request.


5. Putting It All Together: A Troubleshooting Workflow

The real skill is combining these tools into a systematic workflow. Let's walk through two common scenarios.

Essential Linux Networking Tools for DevOps Engineers

Finally, let's look at how to apply these tools in a real-world troubleshooting flow.

Read the 'Practical Troubleshooting Scenarios' section. Work through the logic for both the 'Application cannot connect to database' and 'Slow API responses' scenarios. These patterns are templates you can use for almost any network-related issue.

Let's summarize the workflow for a "service down" alert:

  1. Can I resolve the hostname?

    dig service.example.com
    
    • No? It's a DNS issue. Use dig +trace to debug.
  2. Can I reach the host?

    ping -c 4 <IP_from_dig>
    
    • No? It's a network path or firewall issue. Use traceroute -T -p 443 <IP> to find the breaking point.
  3. Is the application port open and listening? (nc is great for this)

    nc -zv <IP_from_dig> 443
    
    
    
    # nc: connect to <IP> port 443 (tcp) failed: Connection refused
    # vs.
    # Connection to <IP> 443 port [tcp/https] succeeded!
    
    • Connection refused means the server is reachable, but nothing is listening on that port. The application is likely crashed or misconfigured.
  4. Is the application responding correctly?

    curl -v https://service.example.com/health
    
    • Check the HTTP status code. Look for TLS handshake errors. See if you get a valid response body. This tells you if the application logic is working.

Conclusion

You now have a powerful and logical framework for tackling network issues. Guesswork is replaced by a systematic process of elimination, which is the hallmark of an effective DevOps engineer.

Key Takeaways:

  • Troubleshooting is a flow: Start broad (is it reachable?) and progressively narrow your focus (is it DNS? is it the app?).
  • ping tests basic L3 reachability and latency.
  • traceroute maps the network path to find where packets are being dropped. Using TCP probes (-T) is often more reliable.
  • dig is your go-to tool for all DNS diagnostics. dig +trace is your power tool for complex issues.
  • curl tests the application at L7. Use -v to see connection/TLS details and -w to diagnose latency bottlenecks.
Linux Network Troubleshooting Commands Quick Reference
A summary of the core tools and their primary functions. Master these, and you'll be able to diagnose the vast majority of network problems you encounter.

Preview of the Next Lesson:
We've traced paths and inspected traffic, and in doing so, we've implicitly interacted with devices like routers and firewalls. Our next lesson will focus on some of the most important components in a modern cloud network: Layer 4 and Layer 7 load balancers, reverse proxies, and Network Address Translation (NAT). Understanding these will add another critical layer to your networking expertise.