Home  >  Article  >  Operation and Maintenance  >  Introduction to the basic usage of netstat

Introduction to the basic usage of netstat

巴扎黑
巴扎黑Original
2017-07-21 18:05:452221browse

5. Obtain the process name, process number and user ID

When viewing port and connection information, you can view their corresponding process names and process numbers. For system administrators is very helpful. For example, Apache's httpd service opens port 80. If you want to check whether the http service has been started, or whether the http service is started by apache or nginx, you can look at the process name.

Use the -p option to view process information.

  1. ##~$ sudo netstat - nlpt

  2. ##Active

    Internet connections (only servers)

  3. ##Proto
  4. Recv-Q Send-Q Local Address Foreign Address State PID/Program name

    #tcp
  5. 0
  6. 0 127.0.1.1:53 0.0 .0.0:* LISTEN 1144/dnsmasq #tcp

    0
  7. 0

    127.0.0.1:631 0.0. 0.0:* LISTEN 661/cupsd tcp6 0

  8. 0
  9. ::1:631 :::* LISTEN 661/cupsd#

    When using the -p option, netstat must run under root privileges, otherwise it cannot get the process name running under root privileges, and many services including http and ftp run under root privileges under.

    Compared with the process name and process number, it is more useful to view the owner of the process. Use the -ep option to view both the process name and the user name.

    Note
    1. ##$ sudo netstat -ltpe

    2. #Active

      Internet connections (only servers)

    3. ##Proto
    4. Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name

      #tcp
    5. 0
    6. 0 enlightened: domain *:* LISTEN root 11090 1144/dnsmasq ##tcp

      0
    7. 0

      localhost:ipp *:* LISTEN root 9755 661/cupsd #tcp6 0

    8. 0
    9. ip6

      -localhost:ipp [::]:* LISTEN root 9754 661/cupsd

      #The listening sockets under the TCP protocol are listed above and displayed at the same time Process information and some additional information.
    This additional information includes the user name and the inode number of the process. This command is very useful for network administrators.
    - If you use the

    -n

    and

    -e

    options together, the attribute of the User column is the user's ID number, not the user name.

    Netstat Introduction

    Netstat is a command line tool that can be used to list all network socket connections on the system, including tcp, udp and unix sockets. In addition, it can also list sockets in the listening state (that is, waiting for access requests). If you want to confirm whether the Web service on the system is up, you can check whether port 80 is open. The above functions make netstat an essential tool for network managers and system administrators. In this tutorial, I will list a few examples to teach you how to use netstat to find network connection information and port numbers opened by the system.

    1. List all connections

    The first one to introduce is the simplest command: list all current connections. Just use the -a option.

    The above command lists all connections for all sockets under tcp, udp and unix protocols. However, this information is not detailed enough, and administrators often need to check the specific connection status of a certain protocol or port.

    Compiled from:

    Original: LCTT

    Translator: bazz2

    This article address:


The above is the detailed content of Introduction to the basic usage of netstat. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn