2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linuxで、特定ホスト・特定ポートへの通信を試みる (/dev/tcp/hostname/port編)

Last updated at Posted at 2020-02-03

echo > /dev/tcp/${HOSTNAME}/${PORT}
で、対象ホストのTCPポートとの疎通確認が行える。
疎通OKの場合、何も返ってこないので、以下のように && echo "OK" のように、OKだった場合の応答を定義してあげるのがよいかもしれない。

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

参考

参考というか、以下のリンクがあればこの記事要らない・・・(笑)
https://qiita.com/_oba23_/items/e3038d8f388aa435b7d8

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?