In this HakTip we're covering nifty network monitoring tricks using lsof in Linux

Download HD Download MP4

You're probably familiar with ls, or "list directory contents". Similarly lsof lists Open Files and the process that opened them. Since most things in Linux are files it's capable looking at files on the disk as well as pipes, sockets and devices. This can be really useful for tracking down what process is using a resource.

For example if you run into a disk that won't unmount because it's in use lsof can help figure out what's using it.

Another example is figuring out what ports a process is using. Since I have dropbox on this machine sync'ing files I can issue lsof -i -n -P | grep dropbox

The -i tells lsof to list IP sockets. The -n keeps it from trying to resolve DNS and -P says to give us the port number.

Matt's tip is to use the options -Pnl -i4, or -i6 if you're looking for IPv6 info.

As I just mentioned the capital P gives us the port number while the lowercase n keeps lsof from converting the network numbers into host names, which speeds things up a bit. Likewise the lowercase l keeps lsof from converting the user ID number into the actual login name, which again speeds things up.

And finally the -i4 option selects internet addresses, in this case IPv4. In addition to simply IPv4 or IPv6 you can specify protocol like TCP or UDP, host names and addresses, services and ports.

Another option that you might find useful is +M which enables the reporting of portmapper registrations for local TCP or UDP ports. It just puts 'em in backets after the port number.

From the list here I can see that both Chrome and Dropbox are chatting on various ports to various places. I can see the user ID that started the process and of course the process ID. So now if I wanted to quiet things I could use the kill command to shut 'em down

So what programs, commands or scripts are rocking your world? Hit us up --, or simply leave a comment below.

And be sure to check out our sister show, Hak5 for more great stuff just like this.

Leave a Reply

Your email address will not be published. Required fields are marked *



  • Wrong video? =[

  • wrong video dear….put the proper one…..

  • I’m really impressed with your writing skills as well as with the layout on your weblog.

    Is this a paid theme or did you customize it yourself?
    Anyway keep up the excellent quality writing, it is rare to see a great blog like
    this one these days.

  • Greetings! Very useful advice in this particular article!
    It is the little changes which will make the largest changes.

    Thanks a lot for sharing!

  • Hola! I’ve been reading your weblog for a while now and finally
    got the courage to go ahead and give you a shout out from
    Huffman Texas! Just wanted to tell you keep up the
    excellent work!

  • BenekL 7 months ago

    I see is outranked by many competitors in google’s search results. You need more hi authority backlinks. If your are not seo guru you should outsource it, i know the solution for you, just search in google – Cerny’s Tips Outsource The Work

  • But, the more money you already have, the greater easily
    you are able to take credit without notice PHOTOGENE log many homeowners are actually surprised to understand that their credit history dropped significantly
    after signing up for your government’s mortgage modification program.

  • This article is genuinely a nice one it assists new net viewers, who are
    wishing for blogging.

  • With havin so much written content do you ever
    run into any issues of plagorism or copyright infringement?
    My blog has a lot of unique content I’ve either authored myself or outsourced but it looks like a lot of it is popping it up all over the web without my permission. Do you know any solutions to help stop content from being ripped off?
    I’d truly appreciate it.

  • Make sure the bad credit plastic card you are looking for frequently
    reports towards the major credit bureaus Oxford dating what other reasons
    exist getting arefinance car loans.