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 is the specific method for Linux to check the network status?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article analyzes "what is the specific method for Linux to check the status of the network?" The content is detailed and easy to understand. Friends who are interested in "what is the specific method for Linux to view the network status" can follow the editor's train of thought to read it slowly and deeply. I hope it will be helpful to everyone after reading. Let's follow the editor to learn more about "what is the specific method for Linux to view the status of the network".

When the equipment is in the computer room or the equipment does not have the conditions for the eyes to come to the scene at the far end, we can only check the network status through the terminal.

Netstat is a command to check the status of the network. You can see not only the ports opened on this machine, but also the client connections. The basic information of the netstat command is as follows.

Command name: netstat.

Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

Path: / bin/netstat.

Executive permissions: all users.

Function description: output network connections, routing tables, interface statistics, camouflage connections and multicast members.

The format of the command is as follows:

[root@localhost ~] # netstat [options]

Options:

-a: list all network status, including Socket programs

-c seconds: specify how often the network status is refreshed

-n: displayed with IP address and port number, not domain name and service name

-p: displays PID and program name

-t: displays the connection status using the TCP protocol port

-u: displays the connection status using the UDP protocol port

-I: only connections that show listening statu

-r: displays the routing table

[example 1] check the ports opened by this machine. This is the most commonly used way on this machine, using the option "- tuln". Because the "- I" option is used, you can only see the connection in the listening state, not the connection that has been connected. For example:

[root@localhost] # netstat-tulnActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 0.0.0.0 Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 0.0.0 0 Proto Recv-Q Send-Q Local Address Foreign Address Statetcp * LISTENtcp 0 0 0 .0 Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 11211 0 0 0 LISTENtcp 0 0 0 Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 22 0 0 0: * LISTENtcp 0 0 0: 80: * LISTENtcp 0 0 V: 22: :: * LISTENudp 0 0 0.0.0.0 0.0.0.0:*udp 0 0 0 0.0.0 IP address and port number of the local host IP address and port number of the remote host

This command has more output. 1) Proto: the protocol for network connection, usually TCP protocol or UDP protocol. 2) Recv-Q: indicates that the received data is already in the local buffer, but has not been taken away by the process. 3) Send-Q: data packets sent from this machine and not received by the other party are still in the local buffer and do not have the ACK flag. 4) Local Address: the local IP address and port number. 5) ForeignAddress: the IP address and port number of the remote host. 6) State: status. The common states are as follows.

-LISTEN: listening status. Only TCP protocol needs to listen, while UDP protocol does not.

-ESTABLISHED: the status of a connection that has been established. If you use the "- I" option, you will not see the state in which the connection has been established.

-SYN_SENT:SYN initiates a packet, which is a packet that initiates a connection.

-SYN_RECV: a packet that is actively connected is received.

-FIN_WAIT1: the connection that is being interrupted.

-FIN_WAIT2: the connection has been interrupted, but is waiting for confirmation from the host of the other party.

-TIME_WAIT: the connection has been broken, but the socket is still waiting in the network to finish.

-CLOSED: sockets are not used.

Among these states, we most commonly use LISTEN and ESTABLISHED states, one of which is listening and the other is connected.

[example 2] check which ports are opened by the programs on this machine. If you use the "- p" option, you can see which program occupies the port, and you can know the program's PID. For example:

[root@localhost] # netstat-tulnpActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 00.0.0.0tulnpActive Internet connections 3306 0.0.0.0tulnpActive Internet connections * LISTEN 2359/mysqldtcp 000.0.0.0tulnpActive Internet connections 11211 0.0.0.0tulnpActive Internet connections * LISTEN 1563/memcachedtcp 000.0.0.0tulnpActive Internet connections 22 0.0.0.0Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0: 11211:: * LISTEN 1563/memcachedtcp 0 0 0 : 80: * LISTEN 21025/httpdtcp 00 1563/memcachedudp 00 1563/memcached#: 22: * LISTEN 1490/sshdudp 0 0 0.0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. As a result, we can know which program occupies the port.

[example 3] View all connections. Use the option "- an" to view all connections, including listening state connections (LISTEN), established connection status connections (ESTABLISHED), Socke program connections, and so on. Because there are many connections, there is a lot of output. For example:

[root@localhost] # netstat-anActive Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 0 0.0 0 Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 0 LISTENtcp 0 0 0 11 0 0 0 LISTENtcp 0 0117.79 130.170 5 815 SYN_RECVtcp 0 0 0, 0 0 0, 0 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .130.170 ESTABLISHEDtcp 22 124.205.129.99 ESTABLISHEDtcp 0 0117.79.130.170 22 124.205.129.99 11811 Omit part of the content... Udp 0 0 0.0.0.0 udp 0 0 0.0.0.0 0.0.0.0:*udp 0 0 servers and established Proto RefCnt Flags Type State I-Node Pathunix 11211: * Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Pathunix 2 [ACC] Proto RefCnt Flags Type State I-Node Pathunix 9761 @ / var/run/hald/dbus-fr41WkQn1C.

Starting with "Active UNIX domain sockets", the content after that is the connection made by the Socke program, and the previous content is the connection made by the network service. We can see various network connection states in the output of the "- an" option, while the previous "- tuln" option can only see the listening status.

On the Linux to view the network status of what is the specific method to share here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

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

Development

Wechat

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

12
Report