netstat

netstat命令

netstat 命令用于顯示各種網絡相關信息,如網絡連接,路由表,接口狀態 (Interface Statistics),masquerade 連接,多播成員 (Multicast Memberships) 等等

1 常用選項:

-a :(all)顯示所有選項,默認不顯示LISTEN相關

-t :(tcp)僅顯示tcp相關選項

-u :(udp)僅顯示udp相關選項

-n :以數字顯示IP和端口,能顯示數字的全部轉化成數字。

-l :僅列出有在 Listen (監聽) 的服務狀態

-p: 顯示建立相關鏈接的程序名

-r :顯示路由信息,路由表

-e :顯示擴展信息,例如uid等

-s :按各個協議進行統計

-c :每隔一個固定時間,執行該netstat命令。

-w:raw socket相關

2 -tan 顯示所有tcp端口

[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 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::*

3 顯示所有udo端口 -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 顯示所有處于監聽的tcp端口    -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 顯示所有處于監聽狀態的udp端口 -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 顯示路由表 –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 顯示每個協議的統計信息

顯示所有端口的統計信息 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
[……]

顯示 TCP 或 UDP 端口的統計信息 netstat -st 或 -su

[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

[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

原創文章,作者:linux is not unix,如若轉載,請注明出處:http://www.www58058.com/74901

(0)
linux is not unixlinux is not unix
上一篇 2017-05-07 14:24
下一篇 2017-05-07 15:41

相關推薦

  • 博客作業網絡班22期+第5周(9.5-9.11)

    1、顯示當前系統上root、fedora或user1用戶的默認shell [root@MyCloudServer wjb]# egrep '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f7/bin/bash 2、找出/etc/rc.d/init.d/functions文件中某單詞后面…

    Linux干貨 2016-09-15
  • 重構-改善既有代碼的設計:重構原則(二)

    1.什么是重構 重構(Refactoring):在不改變軟件的功能和外部可見性的情況下,為了改善軟件的結構,提高清晰性、可擴展性和可重用性而對軟件進行的改造,對代碼內部的結構進行優化。 2.為何重構   1)改進軟件設計(整理代碼) 重構和設計是相輔相成的,它和設計彼此互補。有了重構,你仍然必須做預先的設計,但是不必是最優的設計,只需要一個合理的解…

    Linux干貨 2015-04-07
  • CentOS7 實現網卡綁定

    Bonding ;理念 將多塊網卡綁定同一IP地址對外提供服務,可以實現高可用 或者負載均衡。直接給兩塊網卡設置同一IP地址是不可以的 。通過bonding,虛擬一塊網卡對外提供連接,物理網卡的 被修改為相同的MAC地址 banding工作模式 Mode 0 (balance-rr) 輪轉(Round-robin)策略: 從頭到尾順序的在每一個slave 接…

    2017-12-19
  • 馬哥教育網絡班21期+第6周課程練習

    請詳細總結vim編輯器的使用并完成以下練習題 1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; [root@centos ~]# cp /etc/rc.d/rc.sysinit /tmp/ [root@centos&nbs…

    Linux干貨 2016-07-27
  • 馬哥教育網絡班21期+第19周課程練習

    1、描述Tomcat的架構; Tomcat組件,分為4類: 頂層類組件:包括<Server>元素和<Service>元素,它們位于整個配置文件的頂層; 連接器類組件:為<Connector>元素,代表介于客戶端與服務器端之間的通信接口,負責將客戶端的請求發送給服務器端,并將服務器的響應結果返回給客戶端; 容器類組件:代表處…

    Linux干貨 2016-12-05
  • find命令之德.摩根定律及perm條件詳解

    (1)德.摩根定律        !A -a !B=!( A -o B )        !A -o !B=!( A -a B )        使用條件:條件中存在“非”、“與”…

    Linux干貨 2016-08-18
欧美性久久久久