Troubleshooting with ip, ss, dig, curl: Essential Network Tools Every Engineer Should Know
Picture this: Your application stops responding, users can’t connect to your service, or API calls are timing out. Before diving into application logs or restarting services, smart engineers reach for fundamental network troubleshooting tools that can quickly pinpoint the real issue.
Whether you’re a system administrator, developer, or DevOps engineer, network problems will find you. The difference between a quick resolution and hours of frustration often comes down to knowing the right diagnostic tools. Today, we’ll master four essential command-line utilities that belong in every engineer’s toolkit: ip
, ss
, dig
, and curl
.
These aren’t obscure system administration tools – they’re practical utilities that help you understand what’s actually happening with network connectivity, DNS resolution, and service communication.
The ip Command: Understanding Your Network Foundation
The ip
command is your window into the Linux networking stack. It shows network interfaces, IP addresses, routing tables, and network namespaces. Think of it as your network configuration detective.
Examining Network Interfaces
When connectivity fails, start by checking whether your network interfaces are properly configured and active.
The output tells you everything about your network setup:
Look for key indicators: UP
means the interface is active, the inet
line shows your IPv4 address, and state UP
confirms everything is working. If you see state DOWN
or missing IP addresses, you’ve found your first clue.
Understanding Routing
Network routing determines how traffic flows between different networks. When you can reach local services but not external ones (or vice versa), routing is often the culprit.
A typical routing table looks like this:
The default
route handles traffic to external networks, while specific subnet routes handle local traffic. Missing or incorrect routes explain why certain destinations are unreachable.
In containerized environments, you might see additional routes for container networks, but the principles remain the same. Understanding these basics helps whether you’re troubleshooting a simple server or a complex Kubernetes cluster.
The ss Command: Socket and Connection Analysis
The ss
(socket statistics) command reveals which services are listening on which ports and shows active network connections. It’s faster and more detailed than the older netstat
command.
Discovering Listening Services
When services aren’t accessible, verify they’re actually listening on the expected ports and interfaces.
The output format is straightforward:
Pay attention to the local address. 0.0.0.0:22
means SSH accepts connections from any interface, while 127.0.0.1:8080
means your application only accepts local connections. This distinction often explains why services work locally but not remotely.
Analyzing Connection States
Network connections go through various states. Understanding these states helps diagnose performance issues and connection problems.
|
|
Common states include:
- ESTABLISHED: Active connections
- LISTEN: Services waiting for connections
- TIME_WAIT: Recently closed connections
- SYN_SENT: Connection attempts in progress
Too many connections in TIME_WAIT might indicate connection handling issues, while many SYN_SENT connections suggest network connectivity problems or unresponsive services.
Advanced Filtering
The ss
command supports powerful filtering to focus on specific connection patterns:
The dig Command: DNS Resolution Mastery
DNS problems cause a surprising number of connectivity issues. The dig
command is your primary tool for investigating DNS resolution, understanding different record types, and debugging name resolution failures.
Basic DNS Queries
Start with simple queries to verify that hostnames resolve correctly:
The standard output provides comprehensive information:
Key details include the resolved IP address, TTL (time to live), and which DNS server provided the answer. Query time helps identify slow DNS resolution.
DNS Troubleshooting Methodology
When DNS resolution fails, use a systematic approach to identify where the problem occurs:
|
|
If external DNS servers work but your local ones don’t, the problem is with your DNS configuration. If even public DNS servers fail, you might have network connectivity issues.
Service Discovery and Internal DNS
Modern applications often rely on internal DNS for service discovery. Understanding how to test these lookups is crucial:
In containerized environments, you might see special DNS zones for service discovery, but the debugging principles remain consistent across different platforms.
The curl Command: HTTP and API Testing
The curl
command tests HTTP connectivity, debugs API issues, and validates service responses. It’s essential for troubleshooting web services and APIs.
Basic HTTP Testing
Start with simple connectivity tests to verify that HTTP services are reachable and responding correctly:
|
|
The verbose output (-v
) shows the complete HTTP conversation:
This reveals connection establishment, HTTP headers sent and received, and response codes. Look for connection failures, SSL certificate issues, or unexpected HTTP status codes.
Advanced HTTP Operations
Real-world testing often requires sending specific headers, authentication, or request bodies:
|
|
Performance Analysis
Understanding request timing helps identify performance bottlenecks:
|
|
This breakdown shows where time is spent:
- High DNS lookup time suggests DNS issues
- Long connect time indicates network problems
- Slow start transfer suggests server processing delays
Practical Troubleshooting Workflow
These tools work best when used systematically. Here’s a step-by-step approach for diagnosing connectivity issues:
Step 1: Verify Basic Network Configuration
Step 2: Confirm Service Availability
Step 3: Test Name Resolution
Step 4: Test Network Connectivity
Step 5: Test Application Layer
This systematic approach helps isolate problems to specific network layers, making solutions more targeted and effective.
Let’s see this in action: Suppose you can’t reach a web API. Running through this checklist might reveal that your network interface is fine, the remote service is listening, DNS resolves correctly, but SSL certificate validation is failing. Now you know exactly what to fix.
Beyond the Basics: Advanced Techniques
As you become comfortable with these tools, you can combine them for more sophisticated troubleshooting:
Bash script to test all DNS-resolved IPs:
Real-time monitoring commands:
Best Practices for Network Troubleshooting
Start simple: Always begin with basic connectivity before investigating complex scenarios. A missing route or down interface explains many problems.
Use verbose output: The -v
flag in curl and detailed options in other commands provide valuable diagnostic information.
Test incrementally: Verify each layer of network communication separately rather than testing everything at once.
Document your findings: Keep notes about what you discover. Network problems often have patterns that become clear over time.
Understand your environment: Different networking setups (cloud, containers, VPNs) have unique characteristics that affect troubleshooting approaches.
Conclusion: Building Network Debugging Skills
Mastering ip
, ss
, dig
, and curl
gives you a solid foundation for network troubleshooting in any environment. These tools help you understand how network traffic flows, identify configuration problems, and verify service connectivity.
The key to becoming effective with these tools is regular practice. Use them proactively to understand your systems when they’re working correctly, so you’ll know what normal looks like when problems arise.
Network troubleshooting is part science, part art. The science comes from systematic methodology and understanding how networks function. The art comes from experience, intuition, and knowing which tool to reach for when symptoms appear.
With these four essential commands in your toolkit, you’re equipped to diagnose and resolve the network issues that inevitably arise in modern computing environments. The investment in learning these tools pays dividends every time you quickly identify and fix a connectivity problem that might otherwise take hours to resolve.
Now go forth and may your connections be stable, your DNS queries swift, and your troubleshooting sessions short. Happy debugging! 🔧