laitimes

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

author:Pengdasheng operation and maintenance

Original link: Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

Hello, everyone! Today I will bring you a detailed article on using the netstat command on a domestic operating system. Netstat is an abbreviation for Network Statistics, which is a command-line tool that displays network connections, routing tables, interface statistics, spoofed connections, and multicast members. The netstat command is very useful and helps us to monitor and manage the network connection. This article will introduce the usage of the netstat command and its common options in detail. Welcome everyone to share and forward, click to follow and watch!

What is netstat?

The netstat command is used to display various network-related information, such as network connections, route tables, and interface statistics. It is very useful in network management and troubleshooting, and can help us understand the network status of the system.

Install netstat

On some domestic operating systems, netstat may not be installed by default. The netstat command can be obtained by installing the net-tools package.

On Debian/Ubuntu-based systems (e.g. UnionTech UOS, Kirin KOS)

sudo apt update

sudo apt install net-tools

On Red Hat/CentOS-based systems (e.g. Zhongke Fangde)

sudo yum install net-tools

1. Check the system information

pdsyw@pdsyw-PC:~/Desktop$ cat /etc/os-version

[Version]

SystemName=UOS Desktop

SystemName[zh_CN]=统信桌面操作系统

ProductType=Desktop

ProductType[zh_CN]=桌面

EditionName=Professional

EditionName[zh_CN]=专业版

MajorVersion=20

MinorVersion=1070

OsBuild=11013.100.100

pdsyw@pdsyw-PC:~/Desktop$ uname -a

Linux pdsyw-PC 4.19.0-loongson-3-desktop #7016 SMP Fri Apr 12 12:11:32 CST 2024 loongarch64 GNU/Linux

pdsyw@pdsyw-PC:~/Desktop$

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

2. Check the CPU information

pdsyw@pdsyw-PC:~/Desktop$ lscpu

Architecture: loongarch64

Byte Order: Little Endian

CPU(s): 8

On-line CPU(s) list: 0-7

Thread(s) per core: 2

Core(s) per socket: 4

Socket(s): 1

NUMA node(s): 1

CPU family: Loongson-64bit

Model name: Loongson-3A6000

BogoMIPS: 5000.00

L1d cache: 256 cubic

L1i cache: 256 KiB

L2 cache: 1 MiB

L3 cache: 16 MiB

NUMA node0 CPU(s): 0-7

Flags: cpucfg lam ual fpu lsx lasx crc32 lvz lbt_x86 lbt_arm lbt_mips

pdsyw@pdsyw-PC:~/Desktop$

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

3. Display the network connection

-a: Displays all connections, including listening and non-listening TCP and UDP connections.

-n: displays the address and port number in numeric form (hostnames and service names are not resolved).

pdsyw@pdsyw-PC:~/Desktop$ netstat -an

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 0.0.0.0:45683 0.0.0.0:* LISTEN

tcp 0 0 127.0.0.1:16308 0.0.0.0:* LISTEN

tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN

tcp 0 0 127.0.0.1:16090 0.0.0.0:* LISTEN

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

-t: Only TCP connections are displayed.

-u: Only UDP connections are displayed.

-n: displays the address and port number in numeric form (hostnames and service names are not resolved).

-p: Displays the process ID and process name to which each connection belongs (superuser privileges required).

pdsyw@pdsyw-PC:~/Desktop$ sudo netstat -tupn

Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 25 0 192.168.0.178:44806 120.131.13.116:443 CLOSE_WAIT 4093/wps

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

4. Display the routing table

-r: displays the kernel routing table.

pdsyw@pdsyw-PC:~/Desktop$ netstat -r

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

default _gateway 0.0.0.0 UG 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

pdsyw@pdsyw-PC:~/Desktop$

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

5. Display network interface information

-i: Displays a list of network interfaces and their status.

pdsyw@pdsyw-PC:~/Desktop$ netstat -i

Kernel Interface table

Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg

enp2s0 1500 0 0 0 0 0 0 0 0 BMU

eth0 1500 53397 0 0 0 34168 0 0 0 BMRU

in 65536 8 0 0 0 0 8 0 0 0 l

pdsyw@pdsyw-PC:~/Desktop$

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

-i: Displays a list of network interfaces and their status.

-e: Expands the display of interface information, including the number of bytes transferred and the number of errors.

pdsyw@pdsyw-PC:~/Desktop$ netstat -ie

Kernel Interface table

enp2s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500

ether 00:26:c8:90:33:e5 txqueuelen 1000 (Ethernet)

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

6. Display network statistics

-s: displays statistics about network protocols, such as TCP, UDP, ICMP, etc.

pdsyw@pdsyw-PC:~/Desktop$ netstat -s

Ip:

Forwarding: 2

53883 total packets received

3 with invalid addresses

0 forwarded

0 incoming packets discarded

53880 incoming packets delivered

34496 requests sent out

50 dropped because of missing route

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

7. Display multicast group member information

-g: displays all multicast groups and their members.

pdsyw@pdsyw-PC:~/Desktop$ netstat -g

IPv6/IPv4 Group Memberships

Interface RefCnt Group

--------------- ------ ---------------------

The 1st all-systems.mcast.net

ENP2S0 1 all-systems.mcast.net

eth0 1 all-systems.mcast.net

lo 1 ip6-allnodes

lo 1 ff01::1

enp2s0 1 ip6-allnodes

enp2s0 1 ff01::1

eth0 1 ff02::1:ff99:fb41

eth0 1 ip6-allnodes

eth0 1 ff01::1

pdsyw@pdsyw-PC:~/Desktop$

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

8. Show statistics for TCP and UDP protocols

-s: displays statistics about network protocols, such as TCP, UDP, ICMP, etc.

-t: displays statistics about the TCP protocol.

pdsyw@pdsyw-PC:~/Desktop$ netstat -st

IcmpMsg:

OutType3: 1

Tcp:

400 active connection openings

0 passive connection openings

4 failed connection attempts

4 connection resets received

3 connections established

54049 segments received

35810 segments sent out

108 segments retransmitted

0 bad segments received

99 resets sent

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

-s: displays statistics about network protocols, such as TCP, UDP, ICMP, etc.

-u: displays statistics about the UDP protocol.

pdsyw@pdsyw-PC:~/Desktop$ netstat -su

IcmpMsg:

OutType3: 1

Udp:

485 packets received

1 packets to unknown port received

0 packet receive errors

494 packets sent

0 receive buffer errors

0 send buffer errors

IgnoredMulti: 2

Detailed explanation of the netstat command on domestic operating systems | UnionTech | Kirin | Zhongke Fangde

Through the introduction of this article, you should have learned how to use the 'netstat' command to monitor and manage network connections on domestic operating systems. 'netstat' is a very powerful network tool that can help you understand the network status of your system, diagnose network problems, and improve the efficiency of network management. If you find this article useful, please share and retweet. At the same time, don't forget to follow and watch, so that you can get more practical technical information and solutions in the future. Thank you all for reading and we'll see you next time!

Read on