When I try to run the following command:

echo -e "GET / HTTP/1.1\n\n" | /dev/tcp/

I get the following error message:

bash: /dev/tcp/ No such file or directory

The following command works perfectly, so the problem involves how I'm using /dev/tcp:

echo -e "GET / HTTP/1.1\n\n" | nc 80

I'm in Ubuntu 13.04, so the capability should be on my system. What am I doing wrong? What are the rules for using /dev/tcp properly?


You have to use it in redirections:

Bash handles several filenames specially when they are used in redirections, as described in the following table:



If host is a valid hostname or Internet address, and port is an integer port number or service name, Bash attempts to open the corresponding TCP socket.


printf "GET / HTTP/1.1\n\n" > /dev/tcp/

is the right way to use it.

When you used /dev/tcp/ in a pipe, bash attempted to run a command named /dev/tcp/ and reported an error because that file didn't exist.

The ability to handle /dev/tcp/host/port and /dev/udp/host/port in redirection was added to bash in version 2.04.

You need to compiled bash with --enable-net-redirections option.

| improve this answer | |
  • 1
    I see, so /dev/tcp is treated as a "file" and not a script. – IQAndreas Dec 7 '15 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.