There are multiple ways to check for open ports in Ubuntu or in general – any Linux based operating system. Let me describe two of the most commonly used methods (at least by myself) in this article.
Method 1: Using the ‘netstat’ command
We can utilize the ‘netstat’ command as illustrated below to check for open ports in Ubuntu or in general any Linux based operating system.
netstat –lp --inet
For example:
When I executed the above mentioned command on my machine, it displayed the below list of open ports.
user@ubuntu:~/Desktop$ sudo netstat -lp --inet Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 localhost.localdo:50001 *:* LISTEN 3738/firefox-bin tcp 0 0 localhost.localdoma:ipp *:* LISTEN 1243/cupsd udp 0 0 192.168.1.2:ntp *:* 2655/ntpd udp 0 0 localhost.localdoma:ntp *:* 2655/ntpd udp 0 0 *:ntp *:* 2655/ntpd
Method 2: Using ‘nmap’
Nmap is an abbreviated name for ‘Network Mapper’. It supports both CLI and GUI front end. In this article, I will show you how to check for open ports utilizing the nmap CLI and will allow you to research further on other possibilities of this beautiful multi-purpose utility.
sudo apt-get install nmap
The command listed above allows you to install ‘nmap’ in a Ubuntu based operating system. Let us start with a simple scan option of ‘nmap’.
nmap -v <hostname>
Be sure to substitute the right host name of the machine against the <hostname> attribute above. The above command scans all the reserved TCP ports on the machine pointed by the <hostname> value and displays verbose output (due to the usage of the ‘-v’ option).
nmap -sS -O myhost.com/24
The above command launches a stealth SYN scan (due to the usage of ‘-sS’ option) against 256 IP’s (Class C network) where myhost.com resides. The usage of ‘-O’ option enables operating system detection on each of those machines.
nmap -sS -O -p 2000-3000 myhost.com
The above command scans ports from 2000 to 3000 on the machine that hosts myhost.com. The ‘-p’ option used above allows us to specify either a single port or a range of ports or distinct individual ports separated by commas.
Note: You can always consider specifying the ‘-v’ option for verbose output.
References: