How to tell if a port is open or not on Linux

I have a PHP script that acts as a server of a chat (websocket) that I have on a certain system. I notice that sometimes unexpectedly this service stops running. It is executed via the nohup command.

I'm using Linux.

I only notice that my websocket script stops working when I see the browser error:

WebSocket connection to 'wss: / / myserver:9001 / chat' failed: Error during WebSocket handshake: net:: ERR_CONNECTION_RESET

Well, I'd like to know if my websocket server script actually stopped running, as I don't know if the browser error always means that my server "crashed".

So how can I detect if a certain port is in use or not?

What command in Linux can I use to know if a port is open or not?

Author: brasofilo, 2016-01-11

1 answers

The simplest way to verify this would be by using the command:

nmap -sT -O localhost 

As added by the milestone can be tested from an external point:

telnet meudominio.com 443 (onde 443 é o número da sua porta)

There is an option also would be to use netstat:

# netstat -tl - lista as conexões abertas de tcp em modo de escuta
# netstat -t - lista as conexões tcp estabelecidas
# netstat -p - lista os programas que estão usando a conexão
# netstat --numeric-ports - não converte o número da porta para ser listado
# netstat --numeric-hosts - não converte o número de ip para nome do host 

# netstat -t -l -p --numeric-ports 

Or:

lsof -i tcp 
 11
Author: Otto, 2016-01-11 13:03:26