List open ports
Using Netstat Command
The flag -l tells netstat to print all listening sockets, -t shows all TCP connections, -u displays all UDP connections and -p enables printing of application/program name listening on the port.
To print numeric values rather than service names, add the -n flag.
netstat -ltup
Using ss Command
ss -lntu
Using Nmap Command
Installation
apt install nmap [On Debian/Ubuntu]
yum install nmap [On CentOS/RHEL]
dnf install nmap [On Fedora 22+]
Usage
nmap -n -PN -sT -sU -p- localhost
Using lsof Command
To list all Internet and network files, use the -i option. Note that this command shows a mix of service names and numeric ports.
lsof -i