COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nmbd 1381 root 10u IPv4 37683465 0t0 UDP *:137 nmbd 1381 root 13u IPv4 37683466 0t0 UDP *:138 nmbd 1381 root 14u IPv4 37683468 0t0 UDP 192.168.1.66:137 nmbd 1381 root 15u IPv4 37683469 0t0 UDP 192.168.1.66:138 nmbd 1381 root 16u IPv4 37683470 0t0 UDP 192.168.1.6:137 nmbd 1381 root 17u IPv4 37683471 0t0 UDP 192.168.1.6:138 smbd 1384 root 25u IPv6 37683528 0t0 TCP *:445 (LISTEN) smbd 1384 root 26u IPv6 37683530 0t0 TCP *:139 (LISTEN) smbd 1384 root 27u IPv4 37683532 0t0 TCP *:445 (LISTEN) smbd 1384 root 28u IPv4 37683534 0t0 TCP *:139 (LISTEN) portmap 1642 daemon 4u IPv4 4146 0t0 UDP *:111 portmap 1642 daemon 5u IPv4 4161 0t0 TCP *:111 (LISTEN) rpc.statd 1658 statd 4u IPv4 4186 0t0 UDP *:986 rpc.statd 1658 statd 6u IPv4 4195 0t0 UDP *:50215 rpc.statd 1658 statd 7u IPv4 4198 0t0 TCP *:37962 (LISTEN) cupsd 1689 root 5u IPv4 51957733 0t0 TCP *:631 (LISTEN) cupsd 1689 root 16u IPv6 51957734 0t0 TCP *:631 (LISTEN) cupsd 1689 root 18u IPv4 51957737 0t0 UDP *:631 dhclient 2031 root 5u IPv4 5307 0t0 UDP *:68 apache2 2093 root 4u IPv6 5480 0t0 TCP *:80 (LISTEN) avahi-dae 2281 avahi 13u IPv4 5670 0t0 UDP *:5353 avahi-dae 2281 avahi 14u IPv6 5671 0t0 UDP *:5353 avahi-dae 2281 avahi 15u IPv4 5672 0t0 UDP *:60574 avahi-dae 2281 avahi 16u IPv6 5673 0t0 UDP *:37378 hddtemp 2705 root 0u IPv4 6851 0t0 TCP 127.0.0.1:7634 (LISTEN) dhclient 3115 root 5u IPv4 10765 0t0 UDP *:68 exim4 13674 Debian-exim 4u IPv4 45844908 0t0 TCP 127.0.0.1:25 (LISTEN) sshd 26220 root 3u IPv4 16151998 0t0 TCP *:22 (LISTEN) sshd 26220 root 4u IPv6 16152000 0t0 TCP *:22 (LISTEN) apache2 30313 www-data 4u IPv6 5480 0t0 TCP *:80 (LISTEN) apache2 30316 www-data 4u IPv6 5480 0t0 TCP *:80 (LISTEN)
While `lsof` will work, why not use the tool designed explicitly for this job? (If not run as root, you will only see the names of PID you own) Show Sample Output
Alternative of OJM snippet : This one show the IP too, where ports bind. It's very important, because if there's only 127.0.0.1 instead of 0.0.0.0, connections from internet are rejected.
Lists all opened sockets (not only listeners), no DNS resolution (so it's fast), the process id and the user holding the socket. Previous samples were limiting to TCP too, this also lists UDP listeners. Show Sample Output
Shows you all listening tcp/udp ports, and what program has them open(depending on rights)
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.
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.
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
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: