天天看點

linux的網絡監測工具

linux的性能網絡監測工具(iostat/sar/mpstat)需要安裝sysstat這個包。

網絡狀态可以使用netstat、nmap等工具。

工具一、iftop(檢視網絡帶寬情,(必須從epel源安裝)

1) 基礎知識了解:

用戶端向68端口(bootps)廣播請求配置, 2、伺服器向67端口(bootpc)廣播回應請求。 這種回應使用廣播是因為用戶端還不知道可以發送的IP位址。...

2) 下面是維基百科上的描述:

By default, iftop will look up hostnames associated with addresses and counts all IP packets that pass through the filter. Hostname look-up can add substantial traffic, in and of itself(主機名查詢能夠添加大量的流量), and may result in an inaccurate display of network traffic(或許會導緻網絡流量顯示不準确). You may wish to suppress display of DNS traffic by using filter code such as "not port domain"(你或許希望通過像not port domain這樣的過濾代碼抑制DNS流量顯示), or switch it off entirely, by using the -n option or by pressing 'n' when the program is running(或者通過-n選項整個關閉掉). Using the -F option makes it possible to show packets entering and leaving a given network(-F選項可以顯示進入和離開給定網絡的包).

3) 選項:

iftop -h  |   [-nNpblBP]   [-i interface]    [-f filter code]    [-F net/mask]    [-G net6/mask6]

-h

Print a summary of usage.幫助資訊

-n

Don't do hostname lookups.不使用主機查詢功能,過濾掉DNS解析,直接顯示ip。

-N

Do not resolve port number to service names不解析服務名的端口号,意思是直接顯示端口号

-p

Run in promiscuous mode, so that traffic which does not pass directly through the specified interface is also counted.

-P

Turn on port display.

-l

Display and count datagrams addressed to or from link-local IPv6 addresses. The default is not to display that address category.

-b

Don't display bar graphs of traffic.

-B

Display bandwidth rates in bytes/sec rather than bits/sec.

-i interface

Listen to packets on interface.

-f filter code 過濾器代碼

Use filter code to select the packets to count. Only IP packets are ever counted, so the specified code is evaluated as (filter code) and ip.

-F net/mask

Specifies an IPv4 network for traffic analysis. If specified, iftop will only include packets flowing in to or out of the given network, and packet direction is determined relative to the network boundary, rather than to the interface. You may specify mask as a dotted quad, such as /255.255.255.0, or as a single number specifying the number of bits set in the netmask, such as /24.

-G net6/mask6

Specifies an IPv6 network for traffic analysis. The value of mask6 can be given as a prefix length or as a numerical address string for more compound bitmasking.

-c config file

Specifies an alternate config file. If not specified, iftop will use ~/.iftoprc if it exists. See below for a description of config files

By pressing s(小寫) or d while iftop is running, all traffic for each source or destination will be aggregated together.(通過按s或者d,我們可以彙集每一個源或者目的的流量) This is most useful when iftop is run in promiscuous mode(混合模式), or is run on a gateway machine.

S(大寫) or D toggle the display of source and destination ports respectively. p will toggle port display on/off.

顯示類型:

t cycles through the four line display modes; the default 2-line display, with sent and received traffic on separate lines, and 3 1-line displays, with sent, received, or total traffic shown.

顯示順序:

By default, the display is ordered according to the 10s average (2nd column). By pressing 1, 2 or 3 it is possible to sort by the 1st, 2nd or 3rd column. By pressing < or > the display will be sorted by source or destination hostname respectively.

P(大寫) will pause the current display.

o(小寫) will freeze the current screen order. This has the side effect that traffic between hosts not shown on the screen at the time will not be shown at all, although it will be included in the totals at the bottom of the screen.

滾動顯示

j and k will scroll the display of hosts. This feature is most useful when the display order is frozen (see above).

-m設定界面最上邊的刻度的最大值,刻度分五個大段顯示,例:# iftop -m 100M

進入iftop畫面後的一些操作:

按t切換顯示格式為2行/1行/隻顯示發送流量/隻顯示接收流量;

按h切換是否顯示幫助;

按n切換顯示本機的IP或主機名;

按s切換是否顯示本機的host資訊;

按d切換是否顯示遠端目标主機的host資訊;

按N切換顯示端口号或端口服務名稱;

按S切換是否顯示本機的端口資訊;

按D切換是否顯示遠端目标主機的端口資訊;

按p切換是否顯示端口資訊;

按P切換暫停/繼續顯示;

按b切換是否顯示平均流量圖形條;

按B切換計算2秒或10秒或40秒内的平均流量;

按T切換是否顯示每個連接配接的總流量;

按l打開螢幕過濾功能,輸入要過濾的字元,比如ip,按回車後,螢幕就隻顯示這個IP相關的流量資訊;

按L切換顯示畫面上邊的刻度;刻度不同,流量圖形條會有變化;

按j或按k可以向上或向下滾動螢幕顯示的連接配接記錄;

按1或2或3可以根據右側顯示的三列流量資料進行排序;

按<根據左邊的本機名或IP排序;

按>根據遠端目标主機的主機名或IP排序;

按o切換是否固定隻顯示目前的連接配接;

4) 關于iftop的配置檔案:

配置檔案:~/.iftoprc

interface: if

Sets the network interface to if.

dns-resolution: (yes|no)

Controls reverse lookup of IP addresses.

port-resolution: (yes|no)

Controls conversion of port numbers to service names.

filter-code: bpf

Sets the filter code to bpf.

show-bars: (yes|no)

Controls display of bar graphs.

promiscuous: (yes|no)

Puts the interface into promiscuous mode.

port-display: (off|source-only|destination-only|on)

Controls display of port numbers.

link-local: (yes|no)

Determines displaying of link-local IPv6 addresses.

hide-source: (yes|no)

Hides source host names.

hide-destination: (yes|no)

Hides destination host names.

use-bytes: (yes|no)

Use bytes for bandwidth display, rather than bits.

sort: (2s|10s|40s|source|destination)

Sets which column is used to sort the display.

line-display: (two-line|one-line-both|one-line-sent|one-line-received)

Controls the appearance of each item in the display.

show-totals: (yes|no)

Shows cumulative total for each item.

log-scale: (yes|no)

Use a logarithmic scale for bar graphs.

max-bandwidth: bw

Fixes the maximum for the bar graph scale to bw, e.g. "10M". Note that the value has to always be in bits, regardless if the option to display in bytes has been chosen.

net-filter: net/mask

Defines an IP network boundary for determining packet direction.

net-filter6: net6/mask6

Defines an IPv6 network boundary for determining packet direction.

screen-filter: regexp

Sets a regular expression to filter screen output.

5) 說明:

顯示的時間間隔是: 2, 10 and 40 second intervals

6) 安裝iftop:

<a href="http://www.ex-parrot.com/~pdw/iftop/" target="_blank"></a>

make、gcc、autoconf

flex 

byacc 

libpcap  libpcap-devel 

ncurses ncurses-devel 

本文轉自chenzudao51CTO部落格,原文連結:http://blog.51cto.com/victor2016/1878622 ,如需轉載請自行聯系原作者

繼續閱讀