How to find ports which are in use on linux server

netstat -na | grep ‘tcp\|udp’ | awk ‘{print $4}’ | cut -d: -f2 | sort | uniq -c | awk ‘{print $2}’

Please find below the description of commands used in above string — netstat command is used to check all incoming and outgoing connections from the server. We used grep command to find out the type of connection i.e. tcp or udp. We used cut command to find out the port number from IP:port string .Sort and uniq used in combination to find out ┬áthe unique port only and at last we use awk to print the unique port in use.