The Wayback Machine - https://web.archive.org/web/20210128063139/https://www.geeksforgeeks.org/netstat-command-linux/
Related Articles

Related Articles

Netstat command in Linux
  • Difficulty Level : Hard
  • Last Updated : 24 May, 2019

Netstat command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.,

Examples of some practical netstat command :

  1. -a -all : Show both listening and non-listening sockets. With the –interfaces option, show interfaces that are not up
    # netstat -a | more : To show both listening and 
    non-listening sockets.

    Image
    Image

  2. List all tcp ports.
    # netstat -at : To list all tcp ports.
    

    Image

  3. List all udp ports.
    # netstat -au : To list all udp ports.
    

    Image

  4. List only listening ports.
    # netstat -l : To list only the listening ports.
    

    Image

  5. List only listening TCP ports.
    # netstat -lt : To list only the listening tcp ports.
    

    Image

  6. List only listening UDP ports.
    # netstat -lu : To list only the listening udp ports.
    

    Image

  7. List only the listening UNIX ports
    # netstat -lx : To list only the listening UNIX ports.
    

    Image

  8. List the statistics for all ports.
    # netstat -s : To list the statistics for all ports.
    

    Image

  9. List the statistics for TCP (or) UDP ports.
    # netstat -st(TCP) : To list the statistics for TCP ports.
    

    Image

    # netstat -su(UDP) : List the statistics for UDP ports.
    

    Image

  10. Display PID and program names in the output.
    # netstat -pt : To display the PID and program names.
    

    Image

  11. Print the netstat information continuously.

    netstat will print information continuously every few seconds.

    # netstat -c : To print the netstat information continuously.
    

    Image

  12. The non-supportive address families in the system.
    # netstat --verbose : To get the non-supportive
    address families in the system.
    

    Image



    At the end, we have something like this : 
    

    Image

  13. The kernel routing information.
    # netstat -r : To get the kernel routing information.
    

    Image

  14. The port on which a program is running.
    # netstat -ap | grep ssh : To get the port
    on which a program is running.
    

    Image

  15. Which process is using a particular port:
    # netstat -an | grep ':80' : To get the process
    which is using the given port.
    

    Image

  16. List of network interfaces.
    # netstat -i : To get the list of network interfaces.
    

    Image

    Display extended information on the interfaces 
    (similar to ifconfig) using netstat -ie:
    
    # netstat -ie : To display extended information 
    on the interfaces
    

    Image


  17. Reference :

    Linux Manual page for netstat

    This article is contributed by Kishlay Verma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

    Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

    My Personal Notes arrow_drop_up
Recommended Articles
Page :