Skip to main content

Network Diagnostics Script

Build a network troubleshooting script that tests connectivity, DNS, latency, TCP ports, and firewall rules from a Linux host.

Füllen Sie die Platzhalter aus

Edit the values, then copy your finished prompt.

Ihr Prompt
prompt.txt

                                

What this prompt does

This prompt makes the AI write a network diagnostics script that walks connectivity problems in a fixed, sensible order instead of guessing. You set the context with [server_role] and [network_topology], then the script tests basic reachability by pinging [gateway_ip], public DNS, and your [critical_endpoints] with configurable timeout and packet count, reporting latency and packet loss.

The structure works because it isolates failures layer by layer. After ping it verifies DNS for [dns_test_domains] against local and public resolvers, tests raw TCP to [service_endpoints] to tell open from filtered ports, runs traceroute to [trace_targets] to find the slow or dropping hop, and inspects local firewall rules and interface state. Each check feeds a traffic-light summary, so a vague "it's down" becomes a specific finding: the host, the route, or a security group. Because the targets are all variables, the script is tailored to the exact box you're debugging rather than a generic ping test.

When to use it

  • A server suddenly can't reach a dependency and you need to localize the fault fast.
  • You want a repeatable diagnostic instead of typing ad-hoc ping, dig, and nc commands each time.
  • You're debugging in a cloud VPC where security groups or routes are the likely culprit.
  • DNS is suspect and you need to compare local resolver answers against public ones.
  • You need to know whether a port is open, closed, or filtered without installing extra tooling.
  • You want a shareable report with a clear per-category status to hand to a teammate or client.

Example output

Expect a single shell script that, when run, produces a structured diagnostic report: a section per check (connectivity, DNS, TCP, traceroute, firewall, interfaces/routes) each tagged green, yellow, or red, with the raw measurements (latency, packet loss, connection time, the offending hop) and a suggested next step per failure. The traffic-light summary sits at the top for a quick read.

Pro tips

  • Fill [critical_endpoints] with host:port pairs you actually depend on (database, cache, payment API) so the TCP checks test real failure paths, not just generic internet access.
  • For [dns_test_domains], include both internal and external names — split-horizon DNS issues only show up when you compare the two resolvers.
  • Set realistic [gateway_ip] and [trace_targets]; a traceroute to the wrong target tells you nothing about the actual outage.
  • The firewall check is most useful when you point it at the specific problem destinations — scope it to [service_endpoints] rather than dumping every rule.
  • Run the script from the affected host itself; the same checks from your laptop won't reveal host-local routing or firewall problems.
  • Treat yellow results as worth investigating, not safe — partial packet loss or slow DNS often precedes the hard red failure.

Frequently Asked Questions

Does this script tell the difference between a closed and a filtered port?
Yes, the TCP checks use nc or bash /dev/tcp against your service endpoints and report whether each port is open, closed, or filtered. That distinction matters because a filtered port usually points at a firewall or security group rather than a stopped service.
Will it work without installing extra tools?
It leans on common utilities like ping, dig or nslookup, traceroute, and nc, and can fall back to bash /dev/tcp for port checks. On a minimal host you may still need to install dig or traceroute if they aren't present, but the script is designed to use standard tooling.
Can it check cloud firewall rules like AWS security groups?
The script inspects local firewall rules via iptables, nftables, or ufw on the host itself. It cannot read AWS security groups directly, but by combining the local rule check with filtered-port results it helps you infer when an upstream security group is the cause.
What does the traffic-light summary actually report?
Each check category gets a green, yellow, or red status plus the underlying measurements and a suggested next step for any failure. This turns a long stream of command output into a quick top-level read so you can see at a glance which layer is failing.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Mehr in Linux & Shell Scripting Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support