Here’s how to find if clients are connected to Apache or Nginx service.
netstat -tn src: 80 netstat -tn src: 443 |
cloud engineer
Here’s how to find if clients are connected to Apache or Nginx service.
netstat -tn src: 80 netstat -tn src: 443 |
netstat -tn src: 80 netstat -tn src: 443
My internet has been flaky lately. I wrote a script that logs my internet connection.
I’m running it in cron every minute.
#!/bin/bash log='/home/ulysses/Code/spectrum.log' if nc -zw1 google.com 443; then echo 'Spectrum is up' $(date) >> $log else echo 'Spectrum is down' $(date) >> $log fi |
#!/bin/bash log='/home/ulysses/Code/spectrum.log' if nc -zw1 google.com 443; then echo 'Spectrum is up' $(date) >> $log else echo 'Spectrum is down' $(date) >> $log fi
To view, just cat the log.
cat spectrum.log Spectrum is up Fri Jun 26 15:14:01 EDT 2020 Spectrum is up Fri Jun 26 15:15:01 EDT 2020 Spectrum is up Fri Jun 26 15:16:01 EDT 2020 Spectrum is up Fri Jun 26 15:17:01 EDT 2020 Spectrum is up Fri Jun 26 15:18:01 EDT 2020 |
cat spectrum.log Spectrum is up Fri Jun 26 15:14:01 EDT 2020 Spectrum is up Fri Jun 26 15:15:01 EDT 2020 Spectrum is up Fri Jun 26 15:16:01 EDT 2020 Spectrum is up Fri Jun 26 15:17:01 EDT 2020 Spectrum is up Fri Jun 26 15:18:01 EDT 2020
So, I now have a record when it was up or down.
You can test a network port connection using the “nc” command on Linux and “telnet” on Windows.
Format:
$ nc -zv domain.com port
C:\> telnet domain.com port
$ nc -zv domain.com 80 Connection to domain.com 80 port [tcp/http] succeeded! |
$ nc -zv domain.com 80 Connection to domain.com 80 port [tcp/http] succeeded!
C:\> telnet -zv domain.com 80 Connecting To domain.com...Could not open connection to the host, on port 80: Connect failed |
C:\> telnet -zv domain.com 80 Connecting To domain.com...Could not open connection to the host, on port 80: Connect failed
For Telnet, if a connection is successful, it returns no message.
When setting up your cloud infrastructure, you can check if your instances have access to the database by performing this command.
$ nc -zv 10.0.0.45 3306 $ nc -zv domain.com 3306 $ nc -zv endpoint.amazonaws.com 3306 |
$ nc -zv 10.0.0.45 3306 $ nc -zv domain.com 3306 $ nc -zv endpoint.amazonaws.com 3306
If connection has succeeded, you’ll get a message like this in Linux and MacOS …
Connection to endpoint.amazonaws.com 3306 port [tcp/mysql] succeeded! |
Connection to endpoint.amazonaws.com 3306 port [tcp/mysql] succeeded!
On Windows, you can use Telnet to test your DB connection.
C:\>telnet endpoint.amazonaws.com 3306 |
C:\>telnet endpoint.amazonaws.com 3306
If connection has succeeded, the result is “no message.” If there’s a problem, you’ll get this ….
Connecting To endpoint.amazonaws.com...Could not open
connection to the host, on port 3306: Connect failed |
Connecting To endpoint.amazonaws.com...Could not open connection to the host, on port 3306: Connect failed