知识百科 2023-11-02 12:00:07 作者:Dan.四季    

大家好!linux查看mac地址今天让小编来大家介绍下关于linux查看目录大小,以下是小编对此问题的归纳整理,让我们一起来看看吧!

有时出于各种原因,你可能需要配置额外的网络接口。

  • 来源:https://linux.cn/article-12165-1.html
  • 作者:Magesh Maruthamuthu
  • 译者:geekpi

默认情况下,在设置服务器时你会配置主网络接口。这是每个人所做的构建工作的一部分。有时出于各种原因,你可能需要配置额外的网络接口。

这可以是通过网络 绑定(bonding) / 协作(teaming)来提供高可用性,也可以是用于应用需求或备份的单独接口。

为此,你需要知道计算机有多少接口以及它们的速度来配置它们。

有许多命令可检查可用的网络接口,但是我们仅使用 ip 命令。以后,我们会另外写一篇文章来全部介绍这些工具。

在本教程中,我们将向你显示可用网络网卡(NIC信息,例如接口名称、关联的 IP 地址、MAC 地址和接口速度。

什么是 ip 命令

ip 命令 类似于 ifconfig, 用于分配静态 IP 地址、路由和默认网关等。

# ip a1: lo: mtu 65536 qdisc noqueue state UNKNOWNu0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;inet 127.0.0.1/8 scope host lou0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;inet6 ::1/128 scope hostu0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp; valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;link/ether fa:16:3e:a0:7d:5a brd ff:ff:ff:ff:ff:ffu0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;inet 192.168.1.101/24 brd 192.168.1.101 scope global eth0u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;inet6 fe80::f816:3eff:fea0:7d5a/64 scope linku0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp; valid_lft forever preferred_lft forever

什么是 ethtool 命令

ethtool 用于查询或控制网络驱动或硬件设置。

# ethtool eth0

1如何在 Linux 上使用 ip 命令检查可用的网络接口

在不带任何参数的情况下运行 ip 命令时,它会提供大量信息,但是,如果仅需要可用的网络接口,请使用以下定制的 ip 命令。

# ip a |awk u0026#39;/state UP/{print $2}u0026#39;eth0:eth1:

2如何在 Linux 上使用 ip 命令检查网络接口的 IP 地址

如果只想查看 IP 地址分配给了哪个接口,请使用以下定制的 ip 命令。

# ip -o a show | cut -d u0026#39; u0026#39; -f 2,7或ip a |grep -i inet | awk u0026#39;{print $7, $2}u0026#39;lo 127.0.0.1/8192.168.1.101/24192.168.1.102/24

3如何在 Linux 上使用 ip 命令检查网卡的 MAC 地址

如果只想查看网络接口名称和相应的 MAC 地址,请使用以下格式。

检查特定的网络接口的 MAC 地址:

# ip link show dev eth0 |awk u0026#39;/link/{print $2}u0026#39;00:00:00:55:43:5c

检查所有网络接口的 MAC 地址,创建该脚本:

# vi /opt/scripts/mac-addresses.sh#!/bin/ship a |awk u0026#39;/state UP/{print $2}u0026#39; | sed u0026#39;s/://u0026#39; | while read output;dou0026nbsp;u0026nbsp;echo $output:u0026nbsp;u0026nbsp;ethtool -P $outputdone

运行该脚本获取多个网络接口的 MAC 地址:

# sh /opt/scripts/mac-addresses.sheth0:Permanent address: 00:00:00:55:43:5ceth1:Permanent address: 00:00:00:55:43:5d

4如何在 Linux 上使用 ethtool 命令检查网络接口速度

如果要在 Linux 上检查网络接口速度,请使用 ethtool 命令。

检查特定网络接口的速度:

# ethtool eth0 |grep "Speed:"Speed: 10000Mb/s

检查所有网络接口速度,创建该脚本:

# vi /opt/scripts/port-speed.sh#!/bin/ship a |awk u0026#39;/state UP/{print $2}u0026#39; | sed u0026#39;s/://u0026#39; | while read output;dou0026nbsp;u0026nbsp;echo $output:u0026nbsp;u0026nbsp;ethtool $output |grep "Speed:"done

运行该脚本获取多个网络接口速度:

# sh /opt/scripts/port-speed.sheth0:Speed: 10000Mb/seth1:Speed: 10000Mb/s

5验证网卡信息的 Shell 脚本

通过此 shell 脚本你可以收集上述所有信息,例如网络接口名称、网络接口的 IP 地址,网络接口的 MAC 地址以及网络接口的速度。创建该脚本:

# vi /opt/scripts/nic-info.sh#!/bin/shhostnameecho "-------------"for iname in $(ip a |awk u0026#39;/state UP/{print $2}u0026#39;)dou0026nbsp;u0026nbsp;echo "$iname"u0026nbsp;u0026nbsp;ip a | grep -A2 $iname | awk u0026#39;/inet/{print $2}u0026#39;u0026nbsp;u0026nbsp;ip a | grep -A2 $iname | awk u0026#39;/link/{print $2}u0026#39;u0026nbsp;u0026nbsp;ethtool $iname |grep "Speed:"done

运行该脚本检查网卡信息:

# sh /opt/scripts/nic-info.shvps.2daygeek.com----------------eth0:192.168.1.101/2400:00:00:55:43:5cSpeed: 10000Mb/seth1:192.168.1.102/2400:00:00:55:43:5dSpeed: 10000Mb/s

via: https://www.2daygeek.com/linux-unix-check-network-interfaces-names-nic-speed-ip-mac-address/

作者: Magesh Maruthamuthu 选题: lujun9972 译者: geekpi 校对: wxy

本文由 LCTT 原创编译, Linux中国 荣誉推出

点击“了解更多”可访问文内链接

本文到此结束,希望对大家有所帮助。

 
打赏