As a developer / administrator, its important to know which ports are listening on the server's network interfaces. They are important for a variety of reasons. To name a few,
- To check if a port is already in use by a different application
- To troubleshoot any issues
- To detect any intrusion
To determine if a port is in use under an Unix-like system you can use lsof, netstat, nmap commands.
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
netstat -anp tcp | grep LISTEN # for mac
netstat -anp udp | grep LISTEN # for mac
sudo nmap -sTU -O IP-address-Here