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

4

I have a PHP script that acts as a chat server (websocket) that I have on a certain system. I realize that sometimes this service unexpectedly stops running. It runs through the nohup command.

I'm using Linux.

I just realize 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 would like to know if my websocket server script actually stopped running because I do not know if the browser error always means that my server "crashed."

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

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

    
asked by anonymous 11.01.2016 / 12:58

1 answer

11

The simplest way to check this would be to use the command:

nmap -sT -O localhost 

As added by Marco can be tested from an external point:

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

There is also an option 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.01.2016 / 13:40