Skip to content

Debug scripts: Network & HTTP

2 paste-and-run bash scripts that collect what you need to find the error.

Index
2 items
  1. Paste the container ID, pod, service or URL into the box.
  2. Copy the script and paste it into a terminal on the machine (or where kubectl works).
  3. Read the report. It is also saved as debug-*.txt in the current folder to share.

Port check: who listens, can I connect, is it blocked?

Read-only

Paste a port number. Shows the process listening on it, connections by state, a local connection test, firewall rules mentioning it and Docker containers publishing it.

(
PORT="<port>"
h() { printf '\n=== %s ===\n' "$*"; }

h "What listens on port $PORT"
sudo ss -tulpn "sport = :$PORT" 2>/dev/null

h "That process"
for pid in $(sudo ss -tulpnH "sport = :$PORT" 2>/dev/null | grep -o 'pid=[0-9]*' | cut -d= -f2 | sort -u); do
  ps -o pid,user,etime,cmd -p "$pid" | cut -c1-160
  systemctl status "$pid" --no-pager 2>/dev/null | head -1
done

h "Connections by state"
ss -tanH "( sport = :$PORT or dport = :$PORT )" | awk '{print $1}' | sort | uniq -c

h "Local connection test"
timeout 3 bash -c "echo > /dev/tcp/127.0.0.1/$PORT" 2>/dev/null && echo "127.0.0.1:$PORT accepts connections" || echo "127.0.0.1:$PORT refused or timed out"
curl -sS -m 5 -o /dev/null -w "HTTP %{http_code} in %{time_total}s\n" "http://127.0.0.1:$PORT/" 2>&1 | head -1

h "Firewall rules mentioning $PORT"
sudo ufw status 2>/dev/null | grep -w "$PORT"
sudo firewall-cmd --list-ports 2>/dev/null | tr ' ' '\n' | grep -w "$PORT"
sudo iptables -S 2>/dev/null | grep -w "$PORT"
sudo nft list ruleset 2>/dev/null | grep -w "dport $PORT"

h "Docker containers publishing $PORT"
command -v docker >/dev/null && docker ps --filter publish="$PORT" --format 'table {{.Names}}\t{{.Ports}}' 2>/dev/null
) 2>&1 | tee "debug-port-$(date +%Y%m%d-%H%M%S).txt"
What it checks
  1. What listensTCP/UDP sockets on the port and the owning process (0.0.0.0 = all interfaces, 127.0.0.1 = local only)
  2. That processcommand line, user, how long it runs, and its systemd unit
  3. Connections by stateESTAB, TIME-WAIT, CLOSE-WAIT counts (lots of CLOSE-WAIT = app not closing connections)
  4. Local testraw TCP connect plus an HTTP request to localhost
  5. Firewallufw, firewalld, iptables and nftables rules for the port
  6. Dockercontainers that publish this port on the host

URL / API not working: DNS, TLS, status and timing

Read-only

Paste a URL. Resolves the name, times each phase of the request (DNS, connect, TLS, first byte), shows the status and headers, checks the certificate's names and expiry, and repeats 5 times to spot slow or flaky responses.

(
URL="<url>"
h() { printf '\n=== %s ===\n' "$*"; }
HOST=$(printf '%s' "$URL" | sed -E 's#^[a-zA-Z]+://##; s#[/:?].*##')

h "DNS for $HOST"
getent hosts "$HOST" 2>/dev/null || nslookup "$HOST" 2>/dev/null | tail -n +3 || echo "does not resolve"

h "Request timing"
curl -sS -o /dev/null -m 20 -L -w 'status=%{http_code} ip=%{remote_ip}:%{remote_port} redirects=%{num_redirects}\ndns=%{time_namelookup}s connect=%{time_connect}s tls=%{time_appconnect}s first-byte=%{time_starttransfer}s total=%{time_total}s\nfinal-url=%{url_effective}\n' "$URL"

h "Response headers"
curl -sSI -m 20 "$URL" 2>&1 | head -25

case "$URL" in https://*)
  h "TLS certificate"
  PORT=$(printf '%s' "$URL" | sed -nE 's#^https://[^/:]+:([0-9]+).*#\1#p'); PORT=${PORT:-443}
  echo | openssl s_client -connect "$HOST:$PORT" -servername "$HOST" 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName 2>&1
  ;;
esac

h "5 requests in a row"
for i in 1 2 3 4 5; do
  curl -sS -o /dev/null -m 20 -w "  #$i status=%{http_code} total=%{time_total}s\n" "$URL" 2>&1
done
) 2>&1 | tee "debug-url-$(date +%Y%m%d-%H%M%S).txt"
What it checks
  1. DNSwhich IPs the name resolves to (none = DNS problem, wrong IP = stale record)
  2. Request timingstatus code, server IP and time for DNS, TCP connect, TLS handshake, first byte and total, following redirects
  3. Response headersserver, cache, redirect location and error headers
  4. TLS certificatewho it is for (subject and SANs), who issued it, and notBefore / notAfter (expired certificate)
  5. 5 requestsconsistent vs flaky status codes and response times (load balancer with one bad backend)

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…