Show which programs are listening on TCP and UDP ports

netstat -plunt
-p Tell me the name of the program and it's PID -l that is listening -u on a UDP port. -n Give me numeric IP addresses (don't resolve them) -t oh, also TCP ports
Sample Output
james@thumpie:~/Work$ sudo netstat -plunt
Password or swipe finger: 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0*               LISTEN      5738/mysqld     
tcp        0      0    *               LISTEN      6373/apache2    
tcp        0      0 *               LISTEN      5839/cupsd      
tcp        0      0*               LISTEN      6760/gdl_indexer
tcp6       0      0 :::22                   :::*                    LISTEN      6989/sshd       
udp        0      0 *                           5644/avahi-daemon: 
udp        0      0    *                           29952/dhclient  
udp        0      0    *                           5986/xinetd     
udp        0      0  *                           5644/avahi-daemon:

2009-02-06 06:04:32

What Others Think

really nice, but in Ubuntu you must use 'sudo' before that command if you wish to see the pids. :)
eseven73 · 666 weeks and 6 days ago
You can see names and PIDs of the processes you own. From the man page... PID/Program name: Slash-separated pair of the process id (PID) and process name of the process that owns the socket.... You will also need superuser privileges to see this information on sockets you don?t own.
JamesGreenhalgh · 666 weeks and 6 days ago
seofox · 1 week and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: