Linux/OSX: find out what network ports are in use
January 5, 2010 – 12:21 pmTo get a quick idea of what ports you have open on your local box, you can use nmap.
~ jhaddad$ nmap localhost
Starting Nmap 5.00 ( http://nmap.org ) at 2010-01-05 11:06 PST
Interesting ports on localhost (127.0.0.1):
Not shown: 499 closed ports, 492 filtered ports
PORT STATE SERVICE
80/tcp open http
88/tcp open kerberos-sec
548/tcp open afp
631/tcp open ipp
3306/tcp open mysql
3325/tcp open unknown
5900/tcp open vnc
9000/tcp open cslistener
10000/tcp open snet-sensor-mgmt
For more detailed information, try netstat:
netstat -an
You’ll get a breakdown of every socket open on your machine – useful for figuring out who’s connected and from where.
The OSX version of netstat lacks a few options – such as the useful ‘-p’ option to display the process id (PID) – which can be useful combined with kill to get rid of unwanted connections – for instance,an SSH tunnel accidentally left open.



2 Responses to “Linux/OSX: find out what network ports are in use”
I’ve given up on netstat and now use lsof nearly all of the time. sudo lsof -itcp -a -p $mysql_pid a common use but you can also slice it up a number of different ways.
By jelder on Jan 5, 2010
“netstat -plan” is my preferred options. Ensures you don’t sit there waiting for netstat to resolve a bunch of IP addresses. Technically -a makes -l redundant but it’s easier to remember “plan” and type it on autopilot.
By Twirrim on Jan 5, 2010