Skip to content

TCP/IP Pseudo Files in Bash

TCP/IP pseudo-files are a special feature in Bash that allow you to open network connections using file-like syntax. They're not real files in the /dev directory — rather, Bash internally interprets paths like /dev/tcp/host/port and /dev/udp/host/port to create network sockets.

Syntax

bash
# Read from a TCP connection
</dev/tcp/hostname/port

# Write to a TCP connection
>/dev/tcp/hostname/port

When Bash encounters this syntax, it uses system calls under the hood (like connect()) to establish the connection.

Common Use Cases

  • Test if a remote host and port are reachable
  • Send raw text to a server (like HTTP requests)
  • Quickly write client-side networking scripts
  • Replace tools like telnet, nc, or curl for simple tasks

Examples

Check if a Port is Open

bash
if </dev/tcp/google.com/80; then
  echo "Port is open"
else
  echo "Port is closed"
fi

Send a Basic HTTP Request

bash
exec 3<>/dev/tcp/example.com/80
echo -e "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" >&3
cat <&3

Limitations

  • Only works in Bash, not in zsh, dash, or other shells
  • May be disabled in certain minimal or custom Bash builds
  • Doesn't support advanced features like timeouts or TLS

Summary

FeatureDescription
Syntax/dev/tcp/host/port or /dev/udp/host/port
TypeNot real files — interpreted internally by Bash
PurposeSimplified way to establish TCP/UDP connections
Useful ForScripting, connectivity checks, basic network I/O