The ports in your Ubuntu Linux system are mostly used for networking when you wish to connect a host with a client. The ports should be in the listening state whenever they intend to accept the connection requests.
Here at LinuxAPT , we shall look into the ways of listing down the ports that are in use or in the listening mode in Linux.
To use the Netstat command in Ubuntu Linux tp check the listening ports, simply run the below command:
$ sudo netstat –ltup
This command will list both the TCP and UDP ports that are currently in use on the terminal.
Also, you can use the SS command for listing the ports in use on the terminal by running the below command:
$ sudo ss –lntu
This command will display the listening ports of our Linux system.
This article covers the methods of finding out the ports that are in use in your Ubuntu Linux machine. In fact, if you are intending to close any unused port, you will easily be able to do that after knowing that it is still in the listening state.
1. Open a terminal application i.e. shell prompt. Run any one of the following command on Linux to see open ports:
$ sudo lsof -i -P -n | grep LISTEN
$ sudo netstat -tulpn | grep LISTEN
$ sudo ss -tulpn | grep LISTEN
$ sudo lsof -i:22 ## see a specific port such as 22 ##
$ sudo nmap -sTU -O IP-address-Here
2. For the latest version of Linux use the ss command. For example:
$ ss -tulw