Attempt communication to a specific host / port on Linux (/ dev / tcp / hostname / port)

echo > /dev/tcp/${HOSTNAME}/${PORT} You can check the communication with the TCP port of the target host. If communication is OK, nothing will be returned, so it may be better to define a response when it is OK, such as && echo "OK" as shown below.

sh-4.2$ echo > /dev/tcp/$DATABASE_SERVICE_NAME/3306 && echo "OK"
OK
sh-4.2$ echo > /dev/tcp/$DATABASE_SERVICE_NAME/3305 && echo "FAIL"
sh: connect: No route to host
sh: /dev/tcp/quotesdb/3305: No route to host

reference

For reference, if you have the following link, you don't need this article ... (laughs) https://qiita.com/oba23/items/e3038d8f388aa435b7d8

Recommended Posts

Attempt communication to a specific host / port on Linux (/ dev / tcp / hostname / port)
Try to create a new command on linux
How to install Linux on a 32bit UEFI PC
How to build a Python environment on amazon linux 2
A memo on how to easily prepare a Linux exercise environment
[PySerial] What to think when a "could not open port'/ dev / cu." Error appears during serial communication on the micro: bit
A super introduction to Linux
A note on how to check the connection to the license server port
A note I was addicted to when making a beep on Linux
Check if you can connect to a TCP port in Python
Host the network library Mirror for Unity on a Linux server