check free port in linux code example
Example 1: free port in linux
netstat -tulnap // list all ports and processes
netstat -anp|grep "port_number" // show port details
sudo fuser -k Port_Number/tcp // free the port needed
lsof -n -i :'port-number' | grep LISTEN // get port details
kill -9 PID // free port
Example 2: how to check list of open ports in linux
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo lsof -i:22
sudo nmap -sTU -O IP-address-Here
Example 3: linux see used ports
netstat -tulpn