In questo articolo parleremo brevemente delle porte nelle reti di computer e passeremo a come elencare tutte le porte aperte in Linux.
Nelle reti di computer, e più sicuramente in termini software, una porta è un'entità logica che funge da punto finale di comunicazione per identificare una determinata applicazione o processo su un sistema operativo Linux. È un numero a 16 bit (0 a 65535 ) che differenzia un'applicazione da un'altra sui sistemi terminali.
I due protocolli di trasporto Internet più popolari, Transmission Control Protocol (TCP ) e il Protocollo Datagram Utente (UDP ) e altri protocolli meno conosciuti utilizzano i numeri di porta per le sessioni di comunicazione (numeri di porta di origine e di destinazione insieme agli indirizzi IP di origine e destinazione).
Inoltre, una combinazione di indirizzo IP, porta e protocollo come TCP/UDP è noto come socket e ogni servizio deve avere un socket univoco.
Di seguito sono elencate le diverse categorie di porte:
- 0-1023 – le porte conosciute, dette anche porte di sistema.
- 1024-49151 – le Porte Registrate, dette anche Porte Utente.
- 49152-65535 – le Porte Dinamiche, dette anche Porte Private.
Puoi visualizzare un elenco di diverse applicazioni e combinazioni di porte/protocollo in /etc/services
file in Linux usando il comando cat:
$ cat /etc/services OR $ cat /etc/services | lessPorte e servizi di rete
# /etc/services: # $Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $ # # Network services, Internet style # IANA services version: last updated 2009-11-10 # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports # are included, only the more common ones. # # The latest IANA port assignments can be gotten from # http://www.iana.org/assignments/port-numbers # The Well Known Ports are those from 0 through 1023. # The Registered Ports are those from 1024 through 49151 # The Dynamic and/or Private Ports are those from 49152 through 65535 # # Each line describes one service, and is of the form: # # service-name port/protocol [aliases ...] [# comment] tcpmux 1/tcp # TCP port service multiplexer tcpmux 1/udp # TCP port service multiplexer rje 5/tcp # Remote Job Entry rje 5/udp # Remote Job Entry echo 7/tcp echo 7/udp discard 9/tcp sink null discard 9/udp sink null systat 11/tcp users systat 11/udp users daytime 13/tcp daytime 13/udp qotd 17/tcp quote qotd 17/udp quote msp 18/tcp # message send protocol msp 18/udp # message send protocol chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp-data 20/udp # 21 is registered to ftp, but also used by fsp ftp 21/tcp ftp 21/udp fsp fspd ssh 22/tcp # The Secure Shell (SSH) Protocol ssh 22/udp # The Secure Shell (SSH) Protocol telnet 23/tcp telnet 23/udp
Per elencare tutte le porte aperte o attualmente in esecuzione, incluso TCP e UDP in Linux utilizzeremo netstat, un potente strumento per monitorare le connessioni di rete e le statistiche.
Elenca tutte le porte di rete utilizzando il comando Netstat$ netstat -lntu Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 :::80 :::* LISTEN tcp 0 0 :::25 :::* LISTEN udp 0 0 0.0.0.0:68 0.0.0.0:*
Dove,
-l
– stampa solo le prese di ascolto-n
– mostra il numero di porta-t
– abilita l'elenco delle porte TCP-u
– abilita l'elenco delle porte udp
Puoi anche usare ss command, una ben nota utility utile per esaminare i socket in un sistema Linux. Esegui il comando seguente per elencare tutte le porte TCP e UCP aperte:
Elenca tutte le porte di rete usando il comando ss$ ss -lntu Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port udp UNCONN 0 0 *:68 *:* tcp LISTEN 0 128 :::22 :::* tcp LISTEN 0 128 *:22 *:* tcp LISTEN 0 50 *:3306 *:* tcp LISTEN 0 128 :::80 ::* tcp LISTEN 0 100 :::25 :::* tcp LISTEN 0 100 *:25
Assicurati di leggere le pagine man dei comandi sopra per ulteriori informazioni sull'utilizzo.
In sintesi, la comprensione del concetto di porte nelle reti di computer è molto vitale per gli amministratori di sistema e di rete. Puoi anche consultare questa guida di netstat con esempi semplici, precisi e ben spiegati.
Ultimo ma non meno importante, mettiti in contatto con noi condividendo altri metodi per elencare le porte aperte in Linux o facendo una domanda tramite il modulo di risposta qui sotto.