• Matheus Lozano

Part01 - TCP/UDP request with a native Bash feature and without curl/wget/*

Updated: Jan 21

Sending HTTP / TCP / UDP requests via Bash without using any other tool


Send HTTP / TCP or UDP requests using Bash

Replica: https://medium.com/bash-tips-and-tricks/part01-tcp-udp-request-with-a-native-bash-feature-and-without-curl-wget-9dcef59c30aa

bash: wget: command not found bash: curl: command not found

Explaining how it works

How many times you tried to test an application or service and you couldn't because you don't have curl/wget/telnet/* installed and the user doesn't have permission to install? Well, the good news is: You can do it with Bash, by native.

One of the optional features (also a default one) for Bash is the --{enable,disable}-net-redirections. With this feature, you can send TCP or UDP requests in many ways.


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/UDP socket.

It's possible to do it because of the pseudo devices under the /dev/. They're /dev/tcp and /dev/udp.

The structure for this feature/pseudo devices are: /dev/PROTOCOL/HOST/PORT

For example: /dev/tcp/google.com/443 /dev/udp/192.168.0.10/123

So, base on that, you can send many times of requests using this Bash feature, from HTTP to NTP. Also, you can get the result back, if you want.

By default, the feature net-redirections is enabled on Bash.

A simple example

To send this request, I create the examples below. These examples are sending a true value to localhost and also google.com.


A possible error

No such file or directory => If you're getting this error during the execution, it's because your Bash don't have the feature net-redirections enabled.

For example:

:> /dev/tcp/google.com/443
bash: /dev/tcp/google.com/443: No such file or directory
: Is the short version of true. Could also be: true > /dev/tcp/google.com/443

To fix this error, you can use this script. It will install Bash with net-redirections. This script can be used on Ubuntu, CentOS and Alpine.


Read more

Bash - Optional Features Bash - Redirections Bash - Cookbook Bash - How to open TCP/UDP sockets Tech Tip: TCP/IP Access Using bash

0 comments

Recent Posts

See All