Unix/Linux 网络接口管理相关命令介绍

 

Unix/Linux 网络接口管理相关命令介绍

获取网络适配器列表信息

在获知网络接口使用状态之前,你可能需要知道你当前的系统使用的网络适配器,在 Linux 和 AIX 中查看网络设备器的属性使用不同的命令,下面的例子给出了在不同系统上如何查看网络设备器的属性。

Linux 系统启动加载网卡驱动会输出识别到的所有网络适配器信息。dmesg 显示系统开机信息。所以可以利用该命令取得系统网络适配器列表。清单 1 命令输出显示共有 2 块网卡,eth0 与 eth1,其中仅 eth1 被启用。

在 RHEL5.3 系统上查看网络适配器
  1. # dmesg|grep -i eth
  2. IBM eHEA ethernet device driver (Release EHEA_0092-03)
  3. ehea: eth0: Jumbo frames are enabled
  4. ehea: eth0 -> logical port id #1
  5. ehea: eth1: Jumbo frames are enabled
  6. ehea: eth1 -> logical port id #2
  7. ehea: eth1: Physical port up
  8. eth1: no IPv6 routers present
复制代码
查看网络接口状态

网络接口状态包括接口是否启用,是否设置 IP 地址、MTU 大小、收发的包数等,查询的命令为 ifconfig, 在不同操作系统其输出格式略有不同。

清单 3 为在 RHEL5.3 上的输出,其显示两个以太网络接口,eth0 未配置 ip 地址,未被启用;eth1 配置了 IP 地址并被启用。
  1. # ifconfig -a
  2. eth0      Link encap:Ethernet  HWaddr 00:1A:64:44:AC:34
  3.           BROADCAST MULTICAST  MTU:1500  Metric:1
  4.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  5.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  6.           collisions:0 txqueuelen:1000
  7.           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  8. eth1      Link encap:Ethernet  HWaddr 00:1A:64:44:AC:35
  9.           inet addr:9.114.70.151  Bcast:9.114.70.255  Mask:255.255.255.128
  10.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  11.           RX packets:12337126 errors:0 dropped:0 overruns:0 frame:0
  12.           TX packets:6250179 errors:0 dropped:0 overruns:0 carrier:0
  13.           collisions:0 txqueuelen:1000
  14.           RX bytes:17295472097 (16.1 GiB)  TX bytes:673204981 (642.0 MiB)
  15. lo        Link encap:Local Loopback
  16.           inet addr:127.0.0.1  Mask:255.0.0.0
  17.           inet6 addr: ::1/128 Scope:Host
  18.           UP LOOPBACK RUNNING  MTU:16436  Metric:1
  19.           RX packets:20168 errors:0 dropped:0 overruns:0 frame:0
  20.           TX packets:20168 errors:0 dropped:0 overruns:0 carrier:0
  21.           collisions:0 txqueuelen:0
  22.           RX bytes:1989243 (1.8 MiB)  TX bytes:1989243 (1.8 MiB)
复制代码
查看网络接口连接属性

网络接口连接属性包括连接模式、连接速度、链路状态、协商方式等。

Linux 上用于查询及设置以太网卡参数的一个常用命令是 ethtool,它可以获取网卡的各种详细的诊断信息,包括连接模式(全双工 / 半双工)、连接速度(10M/100M/1000M 等)、是否支持自动协商等、链路状态、驱动版本、总线位置等等。ethtool 的查询以及配置功能需要相应网卡设备驱动的支持,从本质上说,ethtool 的功能是调用驱动提供的 ethtool 接口,来实现用户所要求的操作。基本上,Linux 2.4 以上内核的网卡驱动均支持这个命令。但根据具体驱动的不同,显示的信息可能大同小异。

在 RHEL5.3 系统上查看网络适配器连接属性
  1. # ethtool eth1
  2. Settings for eth1:
  3.         Supported ports: [ FIBRE ]
  4.         Supported link modes:   10baseT/Half 10baseT/Full
  5.                                 100baseT/Half 100baseT/Full
  6.                                 1000baseT/Full
  7.         Supports auto-negotiation: Yes
  8.         Advertised link modes:  10000baseT/Full
  9.         Advertised auto-negotiation: Yes
  10.         Speed: 1000Mb/s
  11.         Duplex: Full
  12.         Port: FIBRE
  13.         PHYAD: 0
  14.         Transceiver: internal
  15.         Auto-negotiation: on
  16.         Current message level: 0x000000cc (204)
  17.         Link detected: yes
复制代码
主要字段含义:
Supported ports 支持的端口类型
Supported link modes 支持的连接模式
Supports auto-negotiation 是否支持自动协商
Speed 当前的连接速度
Duplex 当前的双工状态
Port 端口类型
Auto-negotiation 自动协商状态
Link detected 链路状态

显示网络接口流量

Linux 上,/proc 文件系统提供了大量的信息反映系统的各种运行状态,包括许多网络相关的统计信息。其中文件 /proc/net/dev 实时反映了网络接口的流量信息。清单7显示了 eth1 当前共接收了 17295646453 字节,发送了 673360865 字节。

在 RHEL5.3 系统上查看网络流量
  1. # cat /proc/net/dev
  2. Inter-|   Receive                                                |  Transmit
  3. face |bytes    packets errs drop fifo frame compressed
  4. multicast|bytes    packets errs drop fifo colls carrier compressed
  5.     lo: 1989443   20172    0    0    0     0          0         0  
  6.         1989443   20172    0    0    0     0          0         0
  7.    eth0:      0       0    0    0    0     0          0         0        
  8.               0       0    0    0    0     0          0         0
  9.    eth1:17295646453 12338767    0    0     0          0         0      1406
  10.         673360865    6251399    0    0     0          0         0          0
复制代码
主要字段含义:
bytes 发送或接受的总字节数
packets 发送或接受的报文总数
errs 被设备驱动监测到发送或接受的错误报文总数
drop 由于系统资源限制,被设备驱动丢弃的报文总数
fifo FIFO 缓存错误数
frame 帧错误数
compressed 发送或接受的压缩报数
multicast 接受到的多播报数
colls 接口检测到的冲突数
carrier 连接介质出现故障次数 , 如 : 网线接

http://www.tech-q.cn/thread-1409-1-1.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值