Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic uses of netstat

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the basic uses of netstat". In daily operation, I believe many people have doubts about the basic usage of netstat. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions about "what are the basic uses of netstat?" Next, please follow the editor to study!

Introduction to Netstat

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, as well as sockets that are listening (that is, waiting for access requests). If you want to make sure that the Web service on the system is up, you can check if port 80 is open. The above functions make netstat a necessary tool for network managers and system administrators. In this tutorial, I will list a few examples of how to use netstat to find the network connection information and the port number that the system opens.

The following is a brief introduction to the man manual from netstat:

Netstat-prints network connections, routing tables, data statistics for connections, camouflage connections, and broadcast domain members.

1. List all connections

The first thing to introduce is the simplest command: list all current connections. Use the-an option.

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

two。 List only connections for TCP or UDP protocols

Use the-t option to list the connections for the TCP protocol

Use the-u option to list the connections for the UDP protocol

3. Disable reverse domain name resolution to speed up query

By default, netstat uses reverse domain name resolution technology to find the hostname for each IP address. This slows down the search. If you think the IP address is enough and you don't need to know the hostname, use the-n option to disable domain name resolution

The above command lists all connections to the TCP protocol without using domain name resolution technology

4. List only connections in monitoring

The background process of any network service opens a port to listen for access requests. These listening sockets, like connected sockets, can also be listed by netstat. Use the-l option to list the sockets you are listening to

Now we can see the TCP ports and connections in the listening state. If you look at all listening ports, remove the-t option. If you only want to view the UDP port, use the-u option instead of the-t option.

Note: do not use the-an option, otherwise netstat will list all connections, not just listening ports

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

When viewing information about ports and connections, it is very helpful for system administrators to see their corresponding process names and process numbers. For example, Apache's httpd service opens port 80. If you want to see if the http service has been started, or if the http service is started by apache or nginx, you can look at the process name.

Use the-p option to view process information

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

It is more useful to see the owner of the process than the process name and process number. Use the-ep option to view both the process name and the user name

The listening sockets under the TCP protocol are listed above, along with process information and some additional information.

This additional information includes the user name and the index node number of the process. This command is very useful for network managers.

Note-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

6. Print statistics

Netstat can print out network statistics, including the number of packets sent and received under a certain protocol.

If you want to print out only TCP or UDP protocol statistics, just add the corresponding options (- t and-u)

At this point, the study of "what are the basic uses of netstat" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report