How to Check for Open Ports in Linux

Source

  • Check Open Ports with nmap
1
$ nmap -sT -p- 192.168.167.1

The -sT tells nmap to scan for TCP ports and -p- to scan for all 65535 ports. If -p- is not used nmap will scan only 1000 ports.

  • Check Open Ports with netcat
1
$ nc -zv 192.167.168.1 20-80

The -z option tells nc to scan only for open ports, without sending any data and the -v is for more verbose information.

  • Check Open Ports using Bash Pseudo Device
1
2
3
for PORT in {20..80}; do
timeout 1 bash -c "</dev/tcp/localhost/$PORT &>/dev/null" && echo "port $PORT is open"
done