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 127.0.0.1:3306          0.0.0.0:*               LISTEN      5738/mysqld     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6373/apache2    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      5839/cupsd      
tcp        0      0 127.0.0.1:33500         0.0.0.0:*               LISTEN      6760/gdl_indexer
tcp6       0      0 :::22                   :::*                    LISTEN      6989/sshd       
udp        0      0 0.0.0.0:55951           0.0.0.0:*                           5644/avahi-daemon: 
udp        0      0 0.0.0.0:68              0.0.0.0:*                           29952/dhclient  
udp        0      0 0.0.0.0:69              0.0.0.0:*                           5986/xinetd     
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           5644/avahi-daemon:

15
2009-02-06 06:04:32

These Might Interest You

What Others Think

really nice, but in Ubuntu you must use 'sudo' before that command if you wish to see the pids. :)
eseven73 · 483 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 · 483 weeks and 5 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?

commandlinefu.com 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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: