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

PHP中文网
Release: 2017-06-21 13:49:11
Original
3053 people have browsed it

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template