HTTP requests using Bash /dev/TCP without curl
Original: TIL: You can make HTTP requests without curl using Bash /dev/TCP
Why This Matters
Provides practical workaround for testing container connectivity in minimal Linux environments without installing additional tools.
Bash can make HTTP requests directly using /dev/TCP socket redirection without curl or wget. The technique uses exec and printf to send raw HTTP requests to a service, useful in minimal container environments without external tools.
A developer working with stripped-down Docker containers discovered that Bash can establish TCP connections and send HTTP requests without curl or wget. The method uses Bash's /dev/TCP redirection feature, which is not a real device file but an internal redirection handled by Bash itself. The basic syntax is: exec 3<>/dev/tcp/service/8642 followed by printf to send HTTP headers and body. The Connection: close header is important to prevent hanging, as HTTP/1.1 defaults to keeping connections open. Headers like Authorization can be added with additional \r\n-terminated lines. This technique works only for plaintext HTTP, not HTTPS, and requires Bash with the --enable-net-redirections compile-time option enabled. The author notes this is not a replacement for curl as it lacks proper HTTP parsing, redirect handling, compression, TLS support, and retries. However, it serves as a quick debugging and connectivity check in minimal container environments where installing packages is undesirable. The feature is Bash-specific and not POSIX-compliant, so it won't work with dash or zsh.