Speaking of network communication check to DB, dedicated commands such as mysql-client for MySQL and redis-cli for Redis are common, but if you just want to check network communication, you can just use curl. I will.
Command image
$ curl -v telnet://hogehoge.com:3306
Speaking of general commands to check communication
$ curl -v https://hogehoge.com
Connect using the http or https protocol as in.
What happens if you don't attach a protocol?
When I did $ man curl
on ubuntu, I found the following description.
If you specify URL without protocol:// prefix, curl will attempt to guess what protocol you might
want. It will then default to HTTP but try other protocols based on often-used host name prefixes.
For example, for host names starting with "ftp." curl will assume you want to speak FTP.
Without the protocol, it seems that commonly used schemas are tried appropriately.
For example, if you hit localhost without specifying the protocol for the server standing locally, it will be interpreted as http and executed.
$ curl -I localhost
HTTP/1.1 404 Not Found
Server: nginx
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/7.2.0RC6
Cache-Control: no-cache, private
date: Tue, 30 Jun 2020 09:27:28 GMT
The case where you want to check the connection from a certain server (ubuntu) to a certain DB server is as follows. Specify the port using the telnet protocol. I thought telnet was the command name, but it seemed that there was actually a telnet protocol. Reference: https://ja.wikipedia.org/wiki/Telnet
$ curl -v telnet://hogehoge.com:3306
* Rebuilt URL to: telnet://hogehoge.com:3306/
* Trying xx.xx.xx.xx...
* TCP_NODELAY set
* Connected to hogehoge.com (xx.xx.xx.xx) port 3306 (#0)
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
* Failed writing body (0 != 29)
* Closing connection 0
The above output is a bit confusing, but it looks like the connection itself was successful (at Connected to hogehoge.com) and the output was failing to be written.
I didn't use it because it was a little hard to see, but it may be good to specify --output / dev / null
etc. using the output option as output.
Recommended Posts