【网络】linux 常用知识集合

监控网络设备用(交换机、路由器) mrtg

服务器访问记录     ntop+rrd

apche或IIS网站访问信息管理   awstats

 

 

 

 

 

 

如果在Linux操作系统中无法访问外部,例如ping公网的IP地址不通,而ping自己机器的地址可以通,一般原因是网关信息没有配置正确。GATEWAY

 

 

 

 

# route -n 显示路由表,然后得到网关地址

 

ip route show 显示当前的Linux路由配置。

 

 

 

 

host

作用:查出某个主机名称的IP,利用/etc/resolv.conf文件里的DNS主机查询主机的IP地址

# host yahoo.com.cn

 

 

 

显示系统引导时的提示信息:

# dmesg | grep eth
eth0: RTL-8139C+ at 0xffffc90000a52000, 9a:0c:c6:a7:37:06, IRQ 32
eth0: link up, 100Mbps, full-duplex, lpa 0x05E1

 

 

# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB Controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 01)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 SCSI storage controller: XenSource, Inc. Xen Platform Device (rev 01)
00:04.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 20)

 

 

查看以太网的链路连接是否正常
# ethtool eth0
Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
        Link partner advertised pause frame use: No
        Link partner advertised auto-negotiation: No
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 32
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: pumbg
        Wake-on: d
        Current message level: 0x00000007 (7)
        Link detected: yes

 

 

 

----------------------------- ifconfig

 

# ifconfig               # 查看所有网络接口的属性

 

 

网卡禁用
ifconfig eth0 down
将网卡启用
ifconfig eth0 up

 

 

 

把eth0接口的ip地址设置为:

#ifconfig eth0 10.10.1.250

 

#ifconfig eth0 10.10.1.250 netmask 255.255.255.0

 

 

 

-------------------------------  iptraf实时网络状况监测

yum install iptraf**

 

图形化界面(窗口放到最大)

 

 

-------------------------------  netperf 网络带宽工具

 

-------------------------------  dstat综合工具,综合了vmstat,iostat,ifstat,netsat

 

-------------------------------  tcptrace数据包分析工具

 

 

-------------------------------  TcpDump 抓取网络数据包

可以将网络中传送的数据包的“头”完全截获下来提供分析

 

在线扫描 http://tool.chinaz.com/port/

 

tcpdump tcp port 21 -vvv -i eth1  开始扫描21端口,就会在窗口中显示数据交互信息
tcpdump tcp port 23 -vvv -i eth1
tcpdump icmp or tcp port 23 -vvv -i eth1
tcpdump icmp or tcp port 21 -vvv -i eth1
tcpdump icmp or tcp port 21 -vvv -i eth1 -s 0 -w /tmp/ss.cap
tcpdump  -i eth0 -s 0 -w /tmp/ss.cap

 

wireshark.exe 分析cap文件

 

 

 

#tcpdump upd port 80 -vvv -i eth0    udp监控

 

#tcpdump tcp port 80 -vvv -i eth0      tcp监控

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes

15:43:37.651863 IP (tos 0x0, ttl  64, id 31962, offset 0, flags [DF], proto: TCP (6), length: 663) 192.168.1.156.9824 > sixplay252.http: P 240469115:240469738(623) ack 4085790091 win 16425

15:43:37.651885 IP (tos 0x0, ttl  64, id 15244, offset 0, flags [DF], proto: TCP (6), length: 40) sixplay252.http > 192.168.1.156.9824: ., cksum 0x85b5 (correct), 1:1(0) ack 623 win 51

15:43:37.786370 IP (tos 0x0, ttl  64, id 15245, offset 0, flags [DF], proto: TCP (6), length: 735) sixplay252.http > 192.168.1.156.9824: P 1:696(695) ack 623 win 51

15:43:37.991733 IP (tos 0x0, ttl  64, id 31963, offset 0, flags [DF], proto: TCP (6), length: 40) 192.168.1.156.9824 > sixplay252.http: ., cksum 0x43b6 (correct), 623:623(0) ack 696 win 16251

15:43:38.629918 IP (tos 0x0, ttl  64, id 50519, offset 0, flags [DF], proto: TCP (6), length: 40) sixplay252.http > 192.168.1.156.9829: F, cksum 0x839e (correct), 4104371606:4104371606(0) ack 2638033166 win 17

15:43:38.630428 IP (tos 0x0, ttl  64, id 31964, offset 0, flags [DF], proto: TCP (6), length: 40) 192.168.1.156.9829 > sixplay252.http: ., cksum 0x4386 (correct), 1:1(0) ack 1 win 16425

 

 

 

 

 

---------------------------KByte 与Kbit的区别(10Mb带宽)

1 Byte=8bit(位)。

8Mb=1MB

 

1M带宽下载速度的理论值就是 1Mb/s, 换成KB/S就是 1024除以8 = 128 KB/S
10M带宽下载速度的理论值就是 10Mb/s, 换成KB/S就是 10240除以8 = 1280 KB/S (每秒下载1280千字节),上传速度是减半640 KB/S (每秒下载640千字节)

我们平时说的那种内存大小是MB(大写)
这一个大小写不同就差了8倍.

100Mb=12.5MB
12.5MB理论下载速度就是12.5x1024=12800KB/S
上传速度是减半,下载为12800KB/S

 

 

支持多少人再线:

假如一个页面80KB

10Mb=10240Kb/S

10Mb=1024K0b/S     / 8   =  1280 KB/S

10Mb=1280KB / 80KB = 160人同时在线

 

---------------------------------

 

awstats分析日志,流量统计

使用Cacti监控你的网络

 

 


# iptables -L            # 查看防火墙设置
# route -n               # 查看路由表
# netstat -lntp          # 查看所有监听端口
# netstat -antp          # 查看所有已经建立的连接
# netstat -s             # 查看网络统计信息

 

 

 

 

#watch more /proc/net/dev

记录了不同网络接口(interface)上的各种包的记录
第一列是接口名称,一般你能看到 lo (自环,loopback接口)和 eth0 (网卡)
第二大列是这个接口上收到的包统计,第三大列是发送的统计,每一大列下又分为以下小列
收(如果是第三大列,就是发)字节数(byte), 包数(packet), 错误包数(errs), 丢弃包数(drop), fifo (First in first out)包数, frame (帧,这一项对普通以太网卡应该无效的)数, 压缩(compressed)包数(不了解), 多播(multicast, 比如广播包或者组播包)包数。

 

 

 

======================= 网卡 相关

 

 

ether 代表ethernet 以太网的意思

eth0,eth1,eth2,代表网卡一,网卡二,网卡三

 

网卡禁用
ifconfig eth0 down
将网卡启用
ifconfig eth0 up

 

 

 

 

ifup和ifdown ,仅就/etc/sysconfig/network-scripts内的ifcfg-ethx(x为数字)进行启动或关闭操作,并不能直接修改接口的参数,而需要手工调整ifcfg-ethx文件才行。

 

启动eth0

# ifup eth0

 

关闭eth0

# ifdown eth0

通过执行/etc/init.d/network restart 来重启网络接口,这条命令其实也要读取配置文件ifcfg-ethx。

 

 

 

 

 

==================== straceroute 追踪数据包传输路径

 

#straceroute -n www.sohu.com

#straceroute -n -f 8 -q 1 www.sohu.com

 

-f 8 表示从第8个路由器开始探测

-q 1 表示每个路由器只发送一个探测数据包

 

 

# traceroute 是用来发出数据包的主机到目标主机之间所经过的网关的工具

# traceroute -m 10 linuxsir.org 把跳数设置为10次;

# traceroute -n linuxsir.org 注:显示IP地址,不查主机名。

# traceroute -p 6888 linuxsir.org 注:探测包使用的基本UDP端口设置6888

# traceroute -q 4 linuxsir.org 注:把探测包的个数设置为值4;

# traceroute -r linuxsir.org 注:绕过正常的路由表,直接发送到网络相连的主机;

# traceroute -w 3 linuxsir.org 注:把对外发探测包的等待响应时间设置为5秒;

 

 

=================== 跟踪路由命令: tracert 76.73.44.2 -d

 


C:\Users\Administrator>tracert 66.90.103.147

Tracing route to 66.90.103.147 over a maximum of 30 hops

  1    25 ms    12 ms    42 ms  192.168.1.1
  2    54 ms    48 ms    63 ms  1.226.128.219.broad.fs.gd.dynamic.163data.com
 [219.128.226.1]
  3    41 ms    40 ms    47 ms  119.145.161.253
  4   119 ms    41 ms    87 ms  57.203.142.61.broad.fs.gd.dynamic.163data.com
 [61.142.203.57]
  5    69 ms   114 ms   101 ms  50.203.142.61.broad.fs.gd.dynamic.163data.com
 [61.142.203.50]
  6    40 ms    46 ms    43 ms  202.97.33.126
  7    54 ms    61 ms    43 ms  202.97.60.197
  8   296 ms   210 ms   208 ms  202.97.51.174
  9   333 ms   330 ms   329 ms  202.97.49.118
 10   339 ms     *      341 ms  be-10-401-pe01.600wseventh.ca.ibone.comcast.n
[75.149.229.193]
 11   345 ms   337 ms   340 ms  pos-1-4-0-0-cr01.losangeles.ca.ibone.comcast.
 [68.86.86.61]
 12   370 ms   464 ms   604 ms  pos-0-14-0-0-cr01.dallas.tx.ibone.comcast.net
8.86.85.142]
 13   385 ms   382 ms   387 ms  pos-0-10-0-0-cr01.atlanta.ga.ibone.comcast.ne
68.86.86.130]
 14   479 ms   422 ms   438 ms  pos-1-10-0-0-cr01.chicago.il.ibone.comcast.ne
68.86.85.61]
 15   404 ms   402 ms   502 ms  pos-0-4-0-0-pe01.350ecermak.il.ibone.comcast.
 [68.86.86.162]
 16   396 ms     *      408 ms  comcast02.chi.fdcservers.net [75.149.229.82]
 17   408 ms   397 ms   400 ms  66.90.103.147

Trace complete.


C:\Users\Administrator>tracert 76.73.44.2

Tracing route to . [76.73.44.2]
over a maximum of 30 hops:

  1     1 ms     3 ms    11 ms  192.168.1.1
  2    47 ms    50 ms    50 ms  1.226.128.219.broad.fs.gd.dynamic.163data.com.c
 [219.128.226.1]
  3    45 ms    48 ms   122 ms  219.135.125.20

 

 

================================== 网络配置 和 一台服务器绑定多个IP

 

 

 

 

vim /etc/resolv.conf

 

将你的DNS服务器地址补充到 nameserver 后面

 nameserver 8.8.8.8

nameserver 66.90.68.25
nameserver 66.90.68.26
search localdomain

 

 

vim /etc/sysconfig/network

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain
GATEWAY=66.90.103.1                   网关

 

 

 


-------/etc/sysconfig/network-scripts目录里面有ifcfg-eth0

 

 


#cat ifcfg-eth0

DEVICE=eth0
BOOTPROTO=static   (dhcp)
BROADCAST=66.90.103.255
HWADDR=00:07:E9:0F:33:AE   hw 代表hardware 硬件意思,MAC 地址是生产厂家定的,每个网卡拥有的唯一地址。
IPADDR=66.90.103.147
NETMASK=255.255.255.0
NETWORK=66.90.103.0
ONBOOT=yes


#cp ifcfg-eth0 ifcfg-eth0:0
#vim ifcfg-eth0:1 
 
DEVICE=eth0:1                 ###更换
BOOTPROTO=static
BROADCAST=66.90.103.255
HWADDR=00:07:E9:0F:33:AE
ADDR=67.159.22.162      ###更换 IP
NETMASK=255.255.255.248     ###更换 子网掩码
NETWORK=66.90.103.0
ONBOOT=yes

 /etc/init.d/network restart

 

 

 

 

  直接cp旧的文件,然后改一下就可以了。
  第一个IP是 eth0
  第二个IP是 eth0:0 (创建文件ifcfg-eth0:0,并把DEVICE改为eth0:0)
  第三个IP是 eth0:1 (创建文件ifcfg-eth0:1,并把DEVICE改为eth0:1)
  以此类推
  [root@localhost network-scripts]# service network restart || ifup eth0
  Shutting down interface eth0: [ OK ]
  Shutting down loopback interface: [ OK ]
  Bringing up loopback interface: [ OK ]
  Bringing up interface eth0: [ OK ]
  Bringing up interface eth1: [ OK ]
  Bringing up interface eth2: [ OK ]
  Bringing up interface eth3: [ OK ]

 

 

 

vim /httpd.conf


NameVirtualHost 67.159.22.162:80

<VirtualHost 67.159.22.162:80>
    DocumentRoot /var/www/html/myyouku
    ServerName www.myyouku.tk
</VirtualHost>

<VirtualHost 67.159.22.162:80>
    DocumentRoot /var/www/html/myyouku
    ServerName myyouku.tk
</VirtualHost>

 

 

=========================网卡流量统计

 

 

 

 


---------ifstat 

RHEL5也没有自带,但是这也是一个很不错的简单易用的工具。安装好,直接输入命令


--------------- sar
-n参数很有用,他有6个不同的开关:DEV | EDEV | NFS | NFSD | SOCK | ALL 。
DEV显示网络接口信息,
EDEV显示关于网络错误的统计数据,
NFS统计活动的NFS客户端的信息,
NFSD统计NFS服务器的信息,
SOCK显示套 接字信息,
ALL显示所有5个开关。
它们可以单独或者一起使用。


#sar –n DEV 1 4     
命令后面 1 4 意思是:每一秒钟取一次值,取四次。
rxpck/s:每秒钟接收的数据包
txpck/s:每秒钟发送的数据包
rxbyt/s:每秒钟接收的字节数
txbyt/s:每秒钟发送的字节数
rxcmp/s:每秒钟接收的压缩数据包
txcmp/s:每秒钟发送的压缩数据包
rxmcst/s:每秒钟接收的多播数据包


[root@localhost ~]# sar -n DEV 1 4
Linux 2.6.18-164.el5 (localhost.localdomain)     11/14/2010

02:14:25 PM     IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
02:14:26 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:14:26 PM      eth0    113.86     53.47  20223.76  21303.96      0.00      0.00      1.98
02:14:26 PM      sit0      0.00      0.00      0.00      0.00      0.00      0.00      0.00

02:14:26 PM     IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
02:14:27 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:14:27 PM      eth0    170.00     80.00 153211.00  22948.00      0.00      0.00      0.00
02:14:27 PM      sit0      0.00      0.00      0.00      0.00      0.00      0.00      0.00

02:14:27 PM     IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
02:14:28 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:14:28 PM      eth0    141.58     93.07  85465.35  65462.38      0.00      0.00      0.00
02:14:28 PM      sit0      0.00      0.00      0.00      0.00      0.00      0.00      0.00

02:14:28 PM     IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
02:14:29 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:14:29 PM      eth0    103.06     63.27  28159.18  59150.00      0.00      0.00      0.00
02:14:29 PM      sit0      0.00      0.00      0.00      0.00      0.00      0.00      0.00

Average:        IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
Average:           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:         eth0    132.25     72.50  71888.25  42137.25      0.00      0.00      0.50
Average:         sit0      0.00      0.00      0.00      0.00      0.00      0.00




------------ linux 自带
#watch more /proc/net/dev
# watch ifconfig



------------------------------Linux流量监控工具 - iftop

 

yum install flex byacc  libpcap ncurses ncurses-devel libpcap-devel

 

http://www.ex-parrot.com/~pdw/iftop/

 

tar zxvf iftop-0.17.tar.gz

cd iftop-0.17

./configure

make && make install

 

 

直接运行: iftop

iftop –I eth0 –n 就可以看到 eth0 网卡的流量状况

 

 

效果如下图:

五、相关参数及说明

1、iftop界面相关说明

界面上面显示的是类似刻度尺的刻度范围,为显示流量图形的长条作标尺用的。

中间的<= =>这两个左右箭头,表示的是流量的方向。

TX:发送流量
RX:接收流量
TOTAL:总流量
Cumm:运行iftop到目前时间的总流量
peak:流量峰值
rates:分别表示过去 2s 10s 40s 的平均流量

2、iftop相关参数

常用的参数

-i设定监测的网卡,如:# iftop -i eth1

-B 以bytes为单位显示流量(默认是bits),如:# iftop -B

-n使host信息默认直接都显示IP,如:# iftop -n

-N使端口信息默认直接都显示端口号,如: # iftop -N

-F显示特定网段的进出流量,如# iftop -F 10.10.1.0/24或# iftop -F 10.10.1.0/255.255.255.0

-h(display this message),帮助,显示参数信息

-p使用这个参数后,中间的列表显示的本地主机信息,出现了本机以外的IP信息;

-b使流量图形条默认就显示;

-f这个暂时还不太会用,过滤计算包用的;

-P使host信息及端口信息默认就都显示;

-m设置界面最上边的刻度的最大值,刻度分五个大段显示,例:# iftop -m 100M

进入iftop画面后的一些操作命令(注意大小写)

按h切换是否显示帮助;

按n切换显示本机的IP或主机名;

按s切换是否显示本机的host信息;

按d切换是否显示远端目标主机的host信息;

按t切换显示格式为2行/1行/只显示发送流量/只显示接收流量;

按N切换显示端口号或端口服务名称;

按S切换是否显示本机的端口信息;

按D切换是否显示远端目标主机的端口信息;

按p切换是否显示端口信息;

按P切换暂停/继续显示;

按b切换是否显示平均流量图形条;

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

按T切换是否显示每个连接的总流量;

按l打开屏幕过滤功能,输入要过滤的字符,比如ip,按回车后,屏幕就只显示这个IP相关的流量信息;

按L切换显示画面上边的刻度;刻度不同,流量图形条会有变化;

按j或按k可以向上或向下滚动屏幕显示的连接记录;

按1或2或3可以根据右侧显示的三列流量数据进行排序;

按<根据左边的本机名或IP排序;

按>根据远端目标主机的主机名或IP排序;

按o切换是否固定只显示当前的连接;

按f可以编辑过滤代码,这是翻译过来的说法,我还没用过这个!

按!可以使用shell命令,这个没用过!没搞明白啥命令在这好用呢!

按q退出监控。

 

 

---------------------------------- 流量监控工具 nload

 

http://www.roland-riegel.de/nload/index.html

wget http://www.roland-riegel.de/nload/nload-0.7.2.tar.gz



 

nload默认分为上下两块:
上半部分是:Incoming也就是进入网卡的流量,
下半部分是:Outgoing,也就是从这块网卡出去的流量,

每部分都有当前流量(Curr),平均流量(Avg),最小流量(Min),最大流量(Max),总和流量(Ttl)这几个部分,
看起来还是蛮直观的。



直接用nload回车即可,也可以指定网卡,如nload eth1
还可以指定是以K或M来显示流量,如nload -u M显示的流量是以MB为单位的

看看还有哪些参数或选项
[root@wdlinux ~]# nload -h

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值