𝗛𝗧𝗧𝗣 𝗥𝗲𝗾𝘂𝗲𝘀𝘁𝘀 𝗪𝗶𝘁𝗵𝗼𝘂𝘁 𝗰𝘂𝗿𝗹: 𝗕𝗮𝘀𝗵 /𝗱𝗲𝘃/𝗧𝗖𝗣 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱
You are inside a stripped-down Docker container. You need to check an API endpoint. You type curl and get "command not found." You try wget and get the same error.
You do not need to panic. Bash has a hidden feature built into its core. It is called /dev/tcp.
This feature lets you open raw TCP connections without installing any tools. It works on almost any Linux system.
How it works: When you reference /dev/tcp/hostname/port, Bash opens a socket connection. This is a Bash-specific feature. It will not work in sh or zsh.
The magic command: exec 3<>/dev/tcp/hostname/port
This line opens a bidirectional file descriptor. You can write data to it and read responses back.
Example GET request: #!/bin/bash exec 3<>/dev/tcp/example.com/80 printf "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n" >&3 cat <&3 exec 3>&-
Why this is useful: • Debugging in minimal environments where you cannot install packages. • Running health checks in CI/CD pipelines with zero dependencies. • Testing connectivity on embedded systems. • Learning exactly how HTTP headers work.
Important limits to remember: • No HTTPS: Bash cannot handle TLS/SSL encryption. Use openssl s_client for encrypted traffic. • No Redirects: You must handle them manually. • No Complexity: Do not use this for production HTTP clients. Use curl for that.
Always include the Connection: close header. If you forget it, your script might hang while waiting for the server.
Next time you are stuck in a locked-down server, use this trick. It turns a dead end into a working tool.
Source: https://dev.to/onsen/http-requests-without-curl-bash-devtcp-explained-5852
Optional learning community: https://t.me/GyaanSetuAi