天天看点

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 ,如需转载请自行联系原作者

继续阅读