
Photo by Kevin Horvat on Unsplash
When a server or workstation loses connectivity, the first instinct is often “restart the machine.” In a production environment that’s not an option – downtime costs money and erodes trust. Instead of guessing, use the tools built into Linux to diagnose before you fix.
This guide walks through a practical workflow that starts with quick sanity checks and ends with packet‑level visibility using ss, iptables, and tcpdump. It assumes you’re comfortable with the terminal and have root or sudo access.
Why now?
Modern cloud stacks, container orchestration, and hybrid deployments rely on Linux networking as a backbone. A mis‑configured firewall rule, an unexpected socket state, or a dropped packet can bring down services that once ran flawlessly. Mastering these tools turns a frustrating outage into a systematic investigation.
1. Quick sanity checks
| Tool | What it tells you | Typical command |
|---|---|---|
ip a / ifconfig |
Interface state, IP addresses, MTU, link speed | ip a |
ping <host> |
Reachability & round‑trip time | ping -c 4 google.com |
traceroute <host> |
Path taken, hops that drop packets | traceroute -n 8.8.8.8 |
systemctl status network.service |
Whether the networking stack is up | sudo systemctl status NetworkManager |
If any of these fail (e.g., ping times out, interfaces show DOWN), the problem lies at the OS or driver level and you should look into kernel logs (journalctl -k) or hardware diagnostics before moving on.
2. Inspecting sockets with ss
ss (socket statistics) replaces older tools like netstat. It’s fast, supports filtering, and shows more details about TCP/UDP state transitions.
2.1 Basic usage
# List all listening sockets
sudo ss -tuln
# Show established connections only
sudo ss -tn state established
Key columns:
– State – LISTEN, ESTAB, CLOSE_WAIT, etc.
– Recv-Q / Send-Q – pending bytes, useful for backlog issues.
– Local/Peer – IP:port pairs.
2.2 Common socket problems
| Symptom | What to look for in ss |
|---|---|
Service is “half‑open” or stuck in TIME_WAIT |
Excessive TIME_WAIT entries can exhaust file descriptors on high‑traffic services. |
| Unexpected connections from unknown IPs | sudo ss -tanp | grep <port> to see which process owns the socket. |
| No listening sockets for a service that should be up | Verify the daemon’s config; sometimes it binds only to IPv6 or localhost. |
2.3 Advanced filtering
# Show all connections to port 80 from remote IP 10.0.0.5
sudo ss -tn src 10.0.0.5 dport :80
# Count sockets per process
sudo ss -o state established '( dport = :ssh )' | grep -c 'users:'
These filters let you pinpoint whether a firewall rule is blocking traffic or if a mis‑configured application is dropping connections.
3. Checking the firewall with iptables
Most Linux distributions still ship iptables (or its newer replacement, nftables). A single missing rule can silently drop packets, which makes socket checks look normal but services unreachable.
3.1 List rules
# IPv4
sudo iptables -L -n -v --line-numbers
# IPv6
sudo ip6tables -L -n -v --line-numbers
Look for:
– Chain order – INPUT, FORWARD, OUTPUT.
– Policy – ACCEPT or DROP by default.
– Target – ACCEPT, DROP, REJECT, LOG.
3.2 Detect “default drop” traps
If the policy is DROP, you must explicitly allow needed traffic:
# Allow SSH (port 22)
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow established/related traffic
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
3.3 Temporarily flush rules for testing
sudo iptables -F # Flush all chains
sudo iptables -X # Delete user-defined chains
sudo iptables -Z # Zero packet counters
Use with caution: Flushing removes all firewall protection. Re‑apply your policies after the test.
3.4 Logging dropped packets
Add a rule to log drops before the final DROP policy:
sudo iptables -A INPUT -j LOG --log-prefix "IPTables-Drop: "
Check /var/log/kern.log or journalctl -k for entries. This helps confirm that traffic is indeed being blocked.
4. Packet‑level visibility with tcpdump
When socket stats and firewall rules look fine but the problem persists, inspect raw packets. tcpdump is a lightweight packet sniffer that can capture and filter traffic on any interface.
4.1 Basic capture
sudo tcpdump -i eth0 port 80 -c 100
-i eth0– interface to listen on.port 80– filter for HTTP.-c 100– stop after 100 packets.
4.2 Filtering by host
# Traffic to/from a specific IP
sudo tcpdump -i any host 192.168.1.10
4.3 Writing to a file for later analysis
sudo tcpdump -i eth0 port 22 -w ssh_capture.pcap
Open the .pcap in Wireshark or tshark:
tshark -r ssh_capture.pcap -Y "tcp.port==22"
4.4 Common packet‑level clues
| Symptom | What to look for |
|---|---|
| No packets arriving | Interface down, wrong MAC/IP, or upstream issue. |
| Packets arriving but no ACKs | Possible firewall dropping responses; check iptables -L. |
| SYN retransmits | TCP handshake failure – could be a dropped SYN or NAT timeout. |
5. Putting it all together: A step‑by‑step workflow
-
Verify the interface
ip a→ is the NIC up? Is the IP correct? -
Test reachability
ping,traceroute→ where does the packet stop? -
Check sockets
ss -tuln→ is your service listening on the expected port and address?
If you see manyTIME_WAITs, consider tuningnet.ipv4.tcp_tw_reuse. -
Inspect firewall
iptables -L -nv --line-numbers→ confirm that INPUT policy allows traffic to your service’s port. -
Capture packets
Usetcpdumpon the interface and target port; look for SYN, ACK, or RST frames. -
Cross‑reference logs
journalctl -u <service>and/var/log/kern.logfor errors that match packet observations. -
Apply a fix
Add missing rules, adjust socket backlog (/proc/sys/net/core/somaxconn), or reconfigure the application. -
Validate
Re‑runping,ss, and capture again to confirm traffic flows normally.
6. Common pitfalls and how to avoid them
| Pitfall | Quick fix |
|---|---|
| Wrong interface in tcpdump – listening on a bridge instead of the physical NIC | Use ip link show to identify the correct name (eth0, enp3s0f1, etc.) |
| IPv6 traffic hidden behind IPv4 rules – you’re only inspecting IPv4 | Run tcpdump -i any ip6 or add -n6 filters. |
| Over‑aggressive logging in iptables – flooding logs and slowing the kernel | Use rate limiting: -m limit --limit 5/s -j LOG. |
| Relying on default policies – many distros ship with ACCEPT by default; you might forget to set DROP later | Always document your firewall policy changes. |
Conclusion
Linux networking is a layered beast, but the right set of commands turns mystery into data. Start broad (ping, traceroute), drill down with socket statistics (ss), validate the gatekeeper (iptables), and finally inspect the raw traffic (tcpdump). By following this structured approach you’ll reduce guesswork, isolate problems faster, and restore services with confidence.
Happy troubleshooting!
Frequently Asked Questions (FAQ)
1. How can I quickly determine if the network interface is up?
Run ip a or ifconfig. If the interface shows DOWN, check driver status with dmesg | grep <interface> and review kernel logs (journalctl -k). A downed interface usually indicates an OS or hardware issue before moving to higher‑level diagnostics.
2. What does a high number of TIME_WAIT sockets in ss mean, and how can I mitigate it?
A large TIME_WAIT count often reflects bursty traffic that exhausts file descriptors. Mitigation includes increasing the tcp_fin_timeout sysctl (sysctl -w net.ipv4.tcp_fin_timeout=30) or using connection‑sharing options such as SO_REUSEADDR in your application, and ensuring the firewall allows established connections.
3. How can I confirm that a specific port is actually open to external traffic?
Use ss -tuln | grep :<port> to see listening sockets. Then test reachability from an outside host with telnet <host> <port> or nc -vz <host> <port>. If the connection fails but ss shows LISTEN, check the firewall (iptables -L -n) for any DROP/REJECT rules that might block inbound traffic.
4. What steps should I take if I suspect a firewall rule is silently dropping packets?
List all rules with sudo iptables -L -n -v --line-numbers. Look for default policies set to DROP and missing allow entries for required ports. Temporarily flush the tables (iptables -F) to test connectivity; if it works, re‑add necessary ACCEPT rules one by one while monitoring packet counters (-v).