Command to check open ports in Linux and port number list in Linux Ubuntu. Here is how to get list of all open ports in Linux Systems.
Port Number List In Linux
Ports are the endpoint of communication. The port number is from 0 to 65535 and is divided into different categories:
- 0 to 1023: These are the “System Ports” which are reserved for system processes and network services.
- 1024 to 49151: These are the “Registered Ports” or “User Ports” which ate designated for specific services.
- 49152 to 65535: These are the “Dynamic Ports” or “Private Ports” which are open to use for private or customized services.
Some common port numbers are:
- 20/21: FTP ( File Transfer Protocol )
- 53: DNS (Domain Name Service)
- 80: HTTP (Hyper Text Transfer Protocol)
- 443: HTTPS (Hyper Text Transfer Protocol Secure)
- 143: IMAP (Internet Messaging Application Protocol)
How To Get List Of All Open Ports In Linux
Here are the five commands to get the list of all open ports in Linux:
1. Using Netstat Command
The netstat command is used to print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
Netstat prints information about the Linux networking subsystem. By default, the netstat command displays the list of open sockets/ports.
You can use the following netstat commands:
netstat -lntu
Or
netstat -atu
- -l: Show only listening sockets. Note that these values are omitted by default.
- -a: Show both listening and non-listening sockets. With the –interfaces option, show interfaces that are not up.
- -n: It will display the port number. Shows the numerical addresses instead of trying to determine symbolic host, port or user names.
- -t: Enables the listing of TCP ports.
- -u: Enables the listing of UDP ports.
2. Using ss Command
You can display the running ports using ss command. Though the ss command is similar to netstat, it displays more TCP and state informations than the netstat.
When no option is used ss displays a list of open non-listening sockets that have established connection.
ss -lntu
3. Using lsof Command
The lsof command stands for list open files.
The lsof command runs in repeat mode and displays output, delay, then repeat the output operation until stopped with an interrupt or quit signal.
You can display the running ports using lsof command:
sudo lsof -i -P -n | grep LISTEN
- -i: Lists all the running process of specific ports
- -P: Converts the port numbers to port names for network files
- -n: Convert the network names to hostnames for network files
4. Using nmap Command
The nmap command can also be used to list open ports.
Foe example, the following command is used to list the open TCP ports of the host computer:
sudo nmap -sT -p- localhost
Note that the command option -p- tells the nmap command to scan for all 65535 ports. By default the nmap command will scan only 1000 ports by default.
4. Using netcat Command
You can use netcat command to list open ports. The netcat command is used by the system to read and write data across network connections over the TCP and UDP protocols.
Because it has all the necessary details, the command can also be used for listing open ports – a specific port or a range of ports.
For example, the following netcat command scans the port from 1 to 1000.
nc -z -v localhost 1-1000
You can change the scan value for the entire list of possible ports, which is from 1-65535.