Linux Networking Commands — Why Ping Works But TCP Fails
Ping responses normal but TCP SYN packets vanished due to a stale ARP cache.
20+ years shipping production infrastructure and CI/CD at scale. Written from production experience, not tutorials.
- ✓Solid grasp of DevOps fundamentals
- ✓Comfortable with command-line tools
- ✓Basic Linux administration knowledge
- The ip command replaces ifconfig for interface and route management
- ss replaces netstat for socket statistics and is dramatically faster on busy servers
- dig tests DNS layer; curl -w gives exact timing for each TLS/TCP phase
- tcpdump requires filters: always specify port or host to avoid flooding disk
- ping and traceroute can mislead when ICMP is blocked — verify with TCP probes
Imagine your computer is a post office. Networking commands are the tools the postmaster uses to check which delivery routes are open, which packages are stuck, and whether the roads between buildings are working. Just like a postmaster can trace a lost parcel or see which trucks are currently on the road, Linux networking commands let you trace packets, spot blocked ports, and see exactly which processes are talking to the outside world.
Every production outage has a moment — usually at 2am — where someone types a networking command into a terminal and either finds the problem in 30 seconds or spends three hours guessing. Linux networking tools are what separates a DevOps engineer who can diagnose a flaky microservice from one who just restarts containers and hopes for the best. These commands are your stethoscope for the network layer.
Why Ping Works But TCP Fails
Linux networking commands are the tools that expose the OSI stack's raw behavior — they let you probe, diagnose, and manipulate network state from user space. Ping uses ICMP echo requests, which operate at the network layer (L3) and require no port or connection state. TCP, on the other hand, requires a three-way handshake, kernel socket buffers, and firewall rules that inspect L4 headers. This fundamental difference means ping can succeed while TCP connections hang or reset.
In practice, ICMP packets bypass iptables rules that filter TCP ports, and they don't consume ephemeral ports or socket file descriptors. A server can respond to ping even when its TCP listen backlog is full, or when the application process has crashed but the kernel network stack still handles ICMP. This is why ping is a poor proxy for application health — it tests L3 reachability, not service availability.
Use ping first to rule out L1-L3 issues (cable, ARP, routing). When ping succeeds but TCP fails, focus on firewall rules (iptables, nftables), socket limits (net.core.somaxconn, net.ipv4.tcp_max_syn_backlog), and application process state. In production, always pair ping with a TCP-specific probe like nc -zv or curl to get the full picture.
ip vs ifconfig — Why the Old Tool Is Dead and What Replaced It
For years, ifconfig was the go-to command for inspecting network interfaces. It still works on many systems, but it's been deprecated and is no longer installed by default on modern Linux distributions like Ubuntu 20.04+ and RHEL 8+. The replacement is the ip command, which is part of the iproute2 package and talks directly to the kernel's netlink socket instead of parsing /proc files.
The key difference isn't just syntax — it's capability. ip can manage routing tables, network namespaces, tunnels, and ARP/NDP caches all through one unified tool. ifconfig could only touch interfaces and basic IP configuration.
When you're debugging a container networking issue in Kubernetes, you'll often drop into a pod's network namespace and run ip addr to see what the container thinks its IP is. That's impossible with ifconfig, which has no namespace awareness. Know ip deeply and you'll be comfortable anywhere from a bare-metal server to a Docker container.
ss and netstat — Seeing Every Open Door on Your Server
Think of your server as a building with thousands of numbered doors (ports). ss and netstat let you see exactly which doors are open, who's standing at each one, and which processes are responsible. This is critical when deploying a new service — you need to know whether port 8080 is already taken before your app fails to bind to it.
netstat is the old tool, ss (Socket Statistics) is the modern replacement. ss talks directly to the kernel via netlink, which makes it dramatically faster on systems with thousands of connections. On a busy web server, netstat can take 10+ seconds while ss returns instantly.
The real power of ss is in its filtering. You can filter by state (ESTABLISHED, LISTEN, TIME_WAIT), by port, by process, or by remote address. In a microservices environment, you might want to see all connections from this service to the database on port 5432 — ss makes that a one-liner.
Understanding TCP connection states matters here. TIME_WAIT is normal and means your server is waiting for late packets before closing a connection. A flood of TIME_WAIT entries is usually fine. CLOSE_WAIT means the remote side closed but your application hasn't — that often points to a bug in connection handling code.
curl, wget and dig — Testing Connectivity Layer by Layer
When a service is unreachable, you need to narrow down the layer where things break. Is it DNS? TCP connectivity? HTTP routing? TLS? curl is exceptional here because it can test each layer independently and gives you precise timing data. dig is your dedicated DNS debugging tool, and together they let you methodically eliminate suspects.
curl's --verbose flag is one of the most useful things in networking debugging. It shows you the DNS resolution, the TCP handshake, the TLS negotiation, and the HTTP headers — all in sequence. When your HTTPS endpoint is slow, curl -w timing reveals whether the slowness is in DNS, in TCP, in TLS, or in the actual server response time.
dig is purpose-built for DNS and goes far beyond what you can learn from ping or curl. You can query specific record types, target specific nameservers, and trace the full delegation chain from root to authoritative server. This matters when you're investigating DNS propagation issues after a domain change, or debugging split-horizon DNS in a VPN setup.
wget is simpler and better for quick file downloads or when you need recursive mirroring. For API testing and network diagnosis, curl is almost always the right choice.
ping, traceroute and tcpdump — Tracing the Path and Catching Packets
Once you've confirmed DNS resolves correctly and the service is listening, the next question is whether packets are actually reaching their destination. ping tells you if a host is reachable and measures round-trip time. traceroute shows you every hop between you and the destination. tcpdump lets you actually capture and inspect raw packets on the wire.
ping is often misused as a binary 'is it up?' test, but it's more nuanced than that. ICMP packets (what ping uses) can be blocked by firewalls while TCP traffic flows fine. A failed ping doesn't mean a service is down — it might just mean ICMP is blocked. Always follow up a failed ping with a TCP-level check.
traceroute reveals the routing path and where latency is introduced. Each hop shows you a router, and timing spikes between hops show you where delays occur. When a cloud VM can't reach an external API, traceroute often reveals the packet dying at a NAT gateway or security group that's silently dropping traffic.
tcpdump is the most powerful of the three but also the most complex. It captures actual packet data, which is essential for diagnosing issues that higher-level tools can't see — like retransmissions, RST floods, or malformed HTTP headers. Always combine it with Wireshark for complex analysis.
Network Performance Monitoring — Bandwidth, Throughput and Bottlenecks
Production servers don't just need connectivity — they need performance. When a service becomes slow, you need to know whether the bottleneck is your server's network interface, the application itself, or somewhere in between. Tools like nload, iftop, iptraf-ng, and nethogs give you real-time bandwidth and per-process traffic data.
nload shows total incoming and outgoing traffic on each interface with a live graph. iftop shows traffic per connection — which remote IPs are consuming the most bandwidth. iptraf-ng adds detailed statistics per protocol and interface. nethogs breaks down traffic per process, so you can see which application is saturating the link.
A common production scenario: a misconfigured backup job or a rogue cron script starts transferring gigabytes of data and saturates the NIC. nethogs reveals 'python3' as the culprit. iftop shows the destination IP is an internal backup server. You then find the backup script is running on the wrong schedule.
For throughput testing, iperf3 is essential. It measures actual TCP/UDP throughput between two hosts, revealing issues like buffer bloat or misconfigured flow control that won't appear in ping.
DNS Debugging — Why Your App Connects but Resolves to Nothing
DNS looks simple. It isn't. The worst outages I've seen weren't packet loss or firewall rules — they were DNS caching a dead record for 24 hours. Before you blame the network, prove the name resolution is working in isolation.
Start with dig. It bypasses your system resolver and queries the authoritative nameserver directly. If dig google.com returns an IP but ping google.com fails, your local resolver is poisoning the cache. Flush it with resolvectl flush-caches on systemd systems or restart systemd-resolved.
nslookup is the old standby but lies about retries. Use dig +short for scripting. Check TTL values carefully — high TTLs hide failures until clients expire. The host command is great for quick reverse lookups.
For production: always test with dig @1.1.1.1 first. That bypasses your corporate DNS server and tells you if the problem is upstream or local.
nslookup returns cached results from the resolver. Always use dig @<server> with an explicit resolver to see the raw DNS response.dig @1.1.1.1 first, then blame the cable.Firewall Forensics — iptables Is Dead, nftables Is What You Debug at 3 AM
The old iptables tool is deprecated. Every modern RHEL 9, Debian 12, and Ubuntu 24+ ship with nftables as the default firewall engine. If you still run iptables -L, you're looking at a compatibility layer that lies about actual rules.
Why this matters: I once spent four hours debugging why a Kubernetes node couldn't reach itself on port 8443. The culprit was an nftables set with a typo in the service CIDR. iptables -L showed nothing. nft list ruleset showed the exact broken line.
Learn nft list ruleset to dump all rules. Use nft add rule for temporary fixes during incidents. For persistent changes, edit /etc/nftables.conf and run nft -f.
Key difference: nftables uses tables, chains, and sets. Think of sets as efficient IP address groups. Debug with nft monitor to see packets hitting rules in real time — game changer for chasing phantom drops.
iptables wrapper is still installed for compatibility. Check if you're using real nftables with iptables --version — if it says 'nf_tables', you're on the new engine.iptables for debug. Run nft list ruleset — that's the source of truth.The Silent Blackhole: When a New Server Stops Responding After a Router Reboot
- Always verify both arp and route tables after server provisioning or network changes.
- A single ping reply does not mean the server is reachable on all protocols — ARP is link-layer.
- After moving IPs between physical hosts, flush the ARP cache on the local subnet's gateway.
ip route show defaultdig @8.8.8.8 google.com| File | Command / Code | Purpose |
|---|---|---|
| network_interface_inspection.sh | ip addr show | ip vs ifconfig |
| socket_inspection.sh | ss -tlnp | ss and netstat |
| connectivity_layer_testing.sh | dig api.example.com A | curl, wget and dig |
| packet_path_tracing.sh | ping -c 5 8.8.8.8 | ping, traceroute and tcpdump |
| performance_monitoring.sh | nload eth0 | Network Performance Monitoring |
| dns_debug.sh | dig +short google.com @1.1.1.1 | DNS Debugging |
| nftables_debug.sh | nft list ruleset | Firewall Forensics |
Key takeaways
Interview Questions on This Topic
A user reports that a web service is intermittently unreachable but your monitoring shows the server is up. Walk me through exactly how you would diagnose this — which commands would you run and in what order?
Frequently Asked Questions
20+ years shipping production infrastructure and CI/CD at scale. Written from production experience, not tutorials.
That's Linux. Mark it forged?
6 min read · try the examples if you haven't