Linux server ports are communication endpoints that allow different services to run on a Linux system. They are identified by a number from 0 to 65535 and a protocol such as TCP or UDP. Some ports are reserved for well-known services, such as port 22 for SSH and port 80 for HTTP. Other ports are available for user-defined services or applications.
To review which ports the server is listening to, use the following methods.
Netstat
Netstat is a command-line tool that displays network statistics for all active connections on a computer. It can help troubleshoot network problems by showing the protocol, local and foreign address, and state of each connection. Netstat can also show the network adapter and protocol statistics, as well as the IP routing table.
Use the following command to view which ports are being used:
netstat –listen
You can also use sudo netstat -tulpn | grep LISTEN for specific results for listening activities.
lsof Command
The lsof command is a useful tool for Linux system administrators. It stands for list open files and it can show information about files that are opened by processes on the system. Everything in Linux is treated as a file, so lsof can also display information about devices, sockets, pipes, directories, and more. You can use various options with lsof to filter the output by user, process, file system, network connection, port number, etc.
Use the following command to view ports being used.
lsof -i
You can also use sudo lsof -i -P -n | grep LISTEN for specific results for listening activities.
ss Command
The ss command is a Linux utility that displays information related to network connections. It can show more details than the classic netstat command, such as TCP and UDP sockets, Unix sockets, ICMP sockets, and raw sockets. You can use ss to monitor and troubleshoot your network connections with various options and filters.
Use the following command to view ports being used.
sudo ss -tulpn
You can also use sudo ss -tulpn | grep LISTEN for specific results for listening activities.