If you've ever found yourself inside a minimal container without tools like nc, curl, dig, or ip, don't worry! You can still troubleshoot using some Bash-native commands without installing any new packages. Here are some alternatives:
1. **Test TCP Port:** Use `timeout 1 bash -c "echo > /dev/tcp/google.com/80" && echo "Open" || echo "Closed"` to check if a port is open.
2. **Get IP Address:** The command `hostname -I` can quickly give you the IP address.
3. **DNS Lookup:** You can perform a DNS lookup with `getent ahostsv4 example.com`.
4. **List Connections:** Check active connections using `cat /proc/net/tcp | awk 'NR>1 {print $2, $3, $4}'`.
5. **Manual HTTP GET (without curl):** Set up a TCP connection with `exec 3/dev/tcp/example.com/80`, then send a GET request with `echo -e "GET / HTTP/1.1nHost: example.comnConnection: closenn" >&3` and retrieve the response with `cat <&3`.
I'd love to hear what Bash hacks you use when you're in a stripped-down environment!
5 Answers
I wasn’t aware of the `getent ahostsv4` command! That's a neat trick. Also, if you dig deeper, gawk has a `/dev/inet/...` interface that can be pretty handy too.
You might also want to consider using `nsenter` for accessing namespaces, though keep in mind it can be tough in a Kubernetes setup or if you're connecting via a bastion host. Privileged access is typically required.
Only the first and last options really stick to being 'bash-native'; the fourth one could technically be done with input redirection and the `read` built-in instead.
Seems like we have different interpretations of what 'Bash-native' means. Could you clarify your viewpoint?

Related Questions
How To Get Your Domain Unblocked From Facebook
How To Find A String In a Directory of Files Using Linux