Home Operation and Maintenance Linux Operation and Maintenance What is the netstat command? How to use netstat command?

What is the netstat command? How to use netstat command?

Jun 21, 2017 pm 01:49 PM
netstat Order

The netstat command is used to display various network-related information, such as network connections, routing tables, interface status (Interface Statistics), masquerade connections, and multicast memberships (Multicast Memberships) Wait

1 Commonly used options:

-a: (all) displays all options, and does not display LISTEN related ones by default

-t: (tcp) Only display tcp related options

-u: (udp) Only display udp related options

-n: Display IP and port in numbers, can display all numbers Convert to numbers.

-l: List only the service status in Listen (monitoring)

-p: Display the name of the program that establishes the relevant link

-r: Display routing information, Routing table

-e: Display extended information, such as uid, etc.

-s: Statistics based on each protocol

-c: Execute the netstat at regular intervals Order.

-w: raw socket related

2 -tan displays all tcp ports

[root@centos7 ~]# netstat -ant

Active Internet connections (servers and established)

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

tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN

tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:22 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:25 0.0.0.0:* LISTEN

tcp 0 52 192.168.29.3:22 192.168.29.1:51029 ESTABLISHED

TCP 0 0 192.168.29.3:22 192.168.29.1:51180 Established

##tcp6 0 0 :::22 :::* LISTEN

tcp6 0 0 ::1:631 :::* LISTEN

tcp6 0 0 ::1:25 :::*

3 show all udp ports -uan

##[root@centos7 ~]# netstat -anu

Active Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address State

udp 0 0 0.0.0.0:5353 0.0.0.0 :*

udp 0 0 0.0.0.0:47414 0.0.0.0:*

udp 0 0 192.168.122.1:53 0.0.0.0:*

udp 0 0 0.0 .0.0:67 0.0.0.0:*

4 Display all listening tcp ports -tnl

##[root@centos7 ~]# netstat -tnl

Active Internet connections (only servers)

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

tcp 0 0 0.0 .0.0:111 0.0.0.0:* LISTEN

tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:22 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:25 0.0.0.0:* LISTEN

tcp6 0 0 : ::111 :::* LISTEN

tcp6 0 0 :::22 :::* LISTEN

tcp6 0 0 ::1:631 :::* LISTEN

tcp6 0 0 ::1:25 :::* LISTEN

5 Display all listening udp ports-unl

[root@centos7 ~]# netstat -unl

Active Internet connections (only servers)

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

udp 0 0 0.0.0.0:5353 0.0.0.0:*

udp 0 0 0.0.0.0:47414 0.0.0.0:*

udp 0 0 0.0.0.0:20815 0.0. 0.0:*

udp 0 0 192.168.122.1:53 0.0.0.0:*

udp 0 0 0.0.0.0:67 0.0.0.0:*

udp 0 0 0.0.0.0:68 0.0.0.0:*

udp 0 0 0.0.0.0:68 0.0.0.0:*

udp 0 0 0.0.0.0:9804 0.0.0.0:*

udp6 0 0 :::12799 :::*

udp6 0 0 :::37953 :::*

6 show routing table –rn

[root@centos7 ~]# netstat -nr

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

0.0.0.0 192.168.29.1 0.0.0.0 UG 0 0 0 ens33

192.168.29.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33

192.168. 122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

[root@centos7 ~]# route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.29.1 0.0.0.0 UG 100 0 0 ens33

192.168.29.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33

192.168. 122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

7 Display statistics for each protocol

(1) Display all ports Statistics netstat -s[root@centos7 ~]# netstat -s

Ip:

3808 total packets received

0 forwarded

0 incoming packets discarded

2444 incoming packets delivered

2254 requests sent out

32 outgoing packets dropped

Icmp:

676 ICMP messages received

0 input ICMP message failed.

ICMP input histogram:

destination unreachable: 148

echo replies: 528

717 ICMP messages sent

0 ICMP messages failed

ICMP output histogram:

destination unreachable: 148

echo request: 569

[……]

(2)显示 TCP 端口的统计信息 netstat -st

[root@centos7 ~]# netstat -st

IcmpMsg:

InType0: 528

InType3: 148

OutType3: 148

OutType8: 569

Tcp:

0 active connections openings

2 passive connection openings

0 failed connection attempts

0 connection resets received

2 connections established

1637 segments received

1418 segments send out

0 segments retransmited

0 bad segments received.

0 resets sent

(3)显示 UDP 端口的统计信息 netstat -su

[root@centos7 ~]# netstat -su

IcmpMsg:

InType0: 528

InType3: 148

OutType3: 148

OutType8: 569

Udp:

0 packets received

140 packets to unknown port received.

0 packet receive errors

169 packets sent

0 receive buffer errors

0 send buffer errors

UdpLite:

IpExt:

InMcastPkts: 27

OutMcastPkts: 33

InBcastPkts: 766

InOctets: 410294

OutOctets: 432666

InMcastOctets: 4963

OutMcastOctets: 5444

InBcastOctets: 179503

InNoECTPkts: 3848

8 显示 PID 和进程名称 netstat -p

[root@centos7 ~]# netstat -p

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 52 centos7.3.local:ssh gateway:51029 ESTABLISHED 1552/sshd: root@pts

tcp 0 0 centos7.3.local:ssh gateway:51180 ESTABLISHED 1854/sshd: root@pts

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags Type State I-Node PID/Program name Path

unix 2 [ ] DGRAM 8520 1/systemd /run/systemd/notify

unix 2 [ ] DGRAM 8522 1/systemd /run/systemd/cgroups-agent

unix 5 [ ] DGRAM 8542 1/systemd /run/systemd/journal/socket

unix 28 [ ] DGRAM 8544 1/systemd /dev/log

unix 2 [ ] DGRAM 11419 1/systemd /run/systemd/shutdownd

unix 3 [ ] STREAM CONNECTED 23993 1276/ibus-x11

 

The above is the detailed content of What is the netstat command? How to use netstat command?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run SUDO commands in Windows 11/10 How to run SUDO commands in Windows 11/10 Mar 09, 2024 am 09:50 AM

The sudo command allows users to run commands in elevated privilege mode without switching to superuser mode. This article will introduce how to simulate functions similar to sudo commands in Windows systems. What is the Shudao Command? Sudo (short for "superuser do") is a command-line tool that allows users of Unix-based operating systems such as Linux and MacOS to execute commands with elevated privileges typically held by administrators. Running SUDO commands in Windows 11/10 However, with the launch of the latest Windows 11 Insider preview version, Windows users can now experience this feature. This new feature enables users to

How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 Feb 29, 2024 pm 04:34 PM

This article will introduce readers to how to use the command prompt (CommandPrompt) to find the physical address (MAC address) of the network adapter in Win11 system. A MAC address is a unique identifier for a network interface card (NIC), which plays an important role in network communications. Through the command prompt, users can easily obtain the MAC address information of all network adapters on the current computer, which is very helpful for network troubleshooting, configuring network settings and other tasks. Method 1: Use "Command Prompt" 1. Press the [Win+X] key combination, or [right-click] click the [Windows logo] on the taskbar, and in the menu item that opens, select [Run]; 2. Run the window , enter the [cmd] command, and then

cmdtelnet command is not recognized as an internal or external command cmdtelnet command is not recognized as an internal or external command Jan 03, 2024 am 08:05 AM

The cmd window prompts that telnet is not an internal or external command. This problem must have deeply troubled you. This problem does not appear because there is anything wrong with the user's operation. Users do not need to worry too much. All it takes is a few small steps. Operation settings can solve the problem of cmd window prompting telnet is not an internal or external command. Let’s take a look at the solution to the cmd window prompting telnet is not an internal or external command brought by the editor today. The cmd window prompts that telnet is not an internal or external command. Solution: 1. Open the computer's control panel. 2. Find programs and functions. 3. Find Turn Windows features on or off on the left. 4. Find “telnet client

Super practical! Sar commands that will make you a Linux master Super practical! Sar commands that will make you a Linux master Mar 01, 2024 am 08:01 AM

1. Overview The sar command displays system usage reports through data collected from system activities. These reports are made up of different sections, each containing the type of data and when the data was collected. The default mode of the sar command displays the CPU usage at different time increments for various resources accessing the CPU (such as users, systems, I/O schedulers, etc.). Additionally, it displays the percentage of idle CPU for a given time period. The average value for each data point is listed at the bottom of the report. sar reports collected data every 10 minutes by default, but you can use various options to filter and adjust these reports. Similar to the uptime command, the sar command can also help you monitor the CPU load. Through sar, you can understand the occurrence of excessive load

Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Feb 29, 2024 pm 05:52 PM

In Win11 system, you can enable or disable Hyper-V enhanced session mode through commands. This article will introduce how to use commands to operate and help users better manage and control Hyper-V functions in the system. Hyper-V is a virtualization technology provided by Microsoft. It is built into Windows Server and Windows 10 and 11 (except Home Edition), allowing users to run virtual operating systems in Windows systems. Although virtual machines are isolated from the host operating system, they can still use the host's resources, such as sound cards and storage devices, through settings. One of the key settings is to enable Enhanced Session Mode. Enhanced session mode is Hyper

What is the correct way to restart a service in Linux? What is the correct way to restart a service in Linux? Mar 15, 2024 am 09:09 AM

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

Install VMware Workstation on Windows 11 with just one simple command Install VMware Workstation on Windows 11 with just one simple command Sep 12, 2023 pm 08:33 PM

Step 1: Open PowerShell or Command Prompt on your Windows 11 or 10 system, go to the search box and type CMD or Powershell as per your choice. Here we use PowerShell. When it appears in the results, select "Run as administrator." This is because we need administrator user access to run commands to install any software on Windows. Step 2: Check Winget Availability Well, although all latest versions of Windows 10 and 11 come with Winget tool by default. But let's first check if it works. Type: winget In return you will see that it can be used with the command

Artifact in Linux: Principles and Applications of eventfd Artifact in Linux: Principles and Applications of eventfd Feb 13, 2024 pm 08:30 PM

Linux is a powerful operating system that provides many efficient inter-process communication mechanisms, such as pipes, signals, message queues, shared memory, etc. But is there a simpler, more flexible, and more efficient way to communicate? The answer is yes, that is eventfd. eventfd is a system call introduced in Linux version 2.6. It can be used to implement event notification, that is, to deliver events through a file descriptor. eventfd contains a 64-bit unsigned integer counter maintained by the kernel. The process can read/change the counter value by reading/writing this file descriptor to achieve inter-process communication. What are the advantages of eventfd? It has the following features

See all articles