网络接口故障排除

以下各节介绍排除 ifupdown2 和网络接口故障的各种方法。

监控接口流量速率和 PPS

监控接口的流量速率和 PPS 以确保最佳网络性能和可靠性。您可以使用提供的数据来高效地分配和利用网络资源,从而确保服务质量并防止网络瓶颈。这些数据可帮助您全面了解网络运行状况,检测任何 DDoS 攻击,并查看当前网络是否可以处理高峰负载,或者您是否需要未来的网络容量扩展和升级。

通过同时监控流量速率和 PPS,您可以识别使用高峰时段,并调整带宽分配或优化数据包路径,以确保低延迟和高吞吐量。

  • 您只能监控物理端口的流量速率和 PPS。
  • 命令输出提供近似值。

要显示所有接口的流量速率和 PPS 的摘要视图,请运行 nv show interface rates 命令。

此输出显示接收和发送的流量速率计数器(以比特/秒为单位)、数据包速率计数器(以数据包/秒为单位)以及链路利用率百分比。速率计数器的计量单位根据速率计数器的值动态变化。比特单位可以是 kbps、Mbps、Gbps 或 Tbps,数据包单位可以是 kpps、Mpps、Gpps 和 Tpps。

cumulus@switch:~$ nv show interface rates
Interface  Intvl  In-Bits Rate  In-Util  In-Pkts Rate  Out-Bits Rate  Out-Util  Out-Pkts Rate
---------  -----  ------------  -------  ------------  -------------  --------  -------------
swp1       60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp2       60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp3       60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp4       60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp5       60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp6       60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp7       60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp8       60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp9       60     10.00 Gbps    100.0%   822.41 kpps   10.00 Gbps     100.0%    822.42 kpps
swp10      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp11      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp12      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp13      60     7.34 Gbps     73.4%    603.21 kpps   5.00 Gbps      50.0%     411.19 kpps
swp14      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp15      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp16      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp17      60     8.42 Gbps     84.2%    692.80 kpps   6.73 Gbps      67.3%     553.59 kpps
swp18      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp19      60     204 bps       0.0%     0 pps         539 bps        0.0%      1 pps
swp20      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp21      60     6.73 Gbps     67.3%    553.59 kpps   8.42 Gbps      84.2%     692.81 kpps
swp22      60     10.00 Gbps    100.0%   14.88 Mpps    10.00 Gbps     100.0%    14.88 Mpps
swp23      60     10.00 Gbps    100.0%   14.88 Mpps    10.00 Gbps     100.0%    14.88 Mpps
swp24      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp25      60     5.00 Gbps     50.0%    411.19 kpps   7.34 Gbps      73.4%     603.21 kpps
swp26      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp27      60     10.00 Gbps    100.0%   822.42 kpps   10.00 Gbps     100.0%    822.41 kpps
swp28      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp29      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp30      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp31      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps
swp32      60     0 bps         0.0%     0 pps         0 bps          0.0%      0 pps

要显示特定接口的流量速率和 PPS,请运行 nv show interface <interface> rates 命令。

cumulus@switch:~$ nv show interface swp1 rates
                operational
---------------  -----------
load-interval    10        
in-bits-rate     10.00 Gbps
in-utilization   100.0%    
in-pkts-rate     822.41 kpps
out-bits-rate    10.00 Gbps
out-utilization  100.0%    
out-pkts-rate    822.40 kpps

nv show interface <interface> rates 命令仅支持使用过滤器选项的接口范围;例如,nv show interface rates --filter "Interface=swp1|Interface=swp2"

您可以使用 nv set system counter rates load-interval 命令配置要用于计算接口速率的负载间隔。您可以指定介于 1 到 600 之间的值。默认负载间隔为 60 秒。

Cumulus Linux 在负载间隔时间段内使用数据并对其求平均值,以计算接口速率计数器。接口速率是等权重平均值。您全局配置负载间隔,而不是为接口配置。

cumulus@switch:~$ nv set system counter rates load-interval 30
cumulus@switch:~$ nv config apply

要将负载间隔重置为默认值 60 秒,请运行 nv unset system counter rates load-interval 命令。

要查看配置的负载间隔,请运行 nv show system counter rates 命令。

启用网络日志记录

要在运行 systemctl start networking.servicesystemctl restart networking.service 以及交换机启动时获取详细日志,请使用 systemctl edit networking.service 命令创建覆盖文件,并添加以下行

[Service]
# remove existing ExecStart rule
ExecStart=
# start ifup with verbose option
ExecStart=/sbin/ifup -av

当您运行 systemctl edit 命令时,您需要运行 systemctl daemon-reload

要禁用日志记录,请执行以下任一操作

  • 删除覆盖文件。运行 systemctl cat networking 命令以显示覆盖文件的名称。
  • 运行 systemctl edit networking.service 命令并删除您添加的行。

排除特定接口启动

要排除某个接口,使其在您启动交换机或启动、停止或重新加载网络服务时不启动

  1. /etc/systemd/system/networking.service.d 目录中创建一个文件(例如,/etc/systemd/system/networking.service.d/override.conf)。

  2. 将行 ExecStart=/sbin/ifup -a -X <interface>ExecStop=/sbin/ifdown -a -X <interface> 添加到文件中。以下示例阻止 eth0 启动

    [Service]
    ExecStart=
    ExecStart=/sbin/ifup -a -X eth0
    ExecStop=
    ExecStop=/sbin/ifdown -a -X eth0
    

您可以排除在 /etc/network/interfaces 文件中指定的任何接口。

使用 ifquery 验证和调试接口配置

您可以使用 ifquery 打印已解析的 interfaces 文件条目。

要使用 ifqueryinterfaces 文件中漂亮地打印 iface 条目,请运行

cumulus@switch:~$ sudo ifquery bond0
auto bond0
iface bond0
    address 14.0.0.9/30
    address 2001:ded:beef:2::1/64
    bond-slaves swp25 swp26

使用 ifquery --check 检查 interfaces 文件中接口的当前运行状态。如果配置不匹配,该命令将返回退出代码 01。下面的行 bond-xmit-hash-policy layer3+7 失败,因为它应该读取 bond-xmit-hash-policy layer3+4

cumulus@switch:~$ sudo ifquery --check bond0
iface bond0
    bond-xmit-hash-policy layer3+7  [fail]
    bond-slaves swp25 swp26         [pass]
    address 14.0.0.9/30             [pass]
    address 2001:ded:beef:2::1/64   [pass]

ifquery --check 是一项实验性功能。

使用 ifquery --runninginterfaces 文件格式打印接口的运行状态

cumulus@switch:~$ sudo ifquery --running swp1
auto swp1
iface swp1
	mtu 9000
	hwaddress 48:b0:2d:01:46:04

ifquery --syntax-help 提供有关 interfaces 文件中支持的所有可能属性的帮助。有关 interfaces 文件的完整语法,请参阅 man interfacesman ifupdown-addons-interfaces

您可以使用 ifquery --print-savedstate 检查 ifupdown2 状态数据库。ifdown 仅适用于此状态数据库中存在的接口。

cumulus@leaf1$ sudo ifquery --print-savedstate eth0  
auto eth0
iface eth0 inet dhcp

Mako 模板错误

调试并获取有关模板错误的详细信息的简单方法是在您的接口模板文件或 /etc/network/interfaces 本身上使用 mako-render 命令。

cumulus@switch:~$ sudo mako-render /etc/network/interfaces
iface swp51

cumulus@leaf02:mgmt:~$ sudo mako-render /etc/network/interfaces
# Auto-generated by NVUE!
# Any local modifications will prevent NVUE from re-generating this file.
# md5sum: ac1ff9d35c3cd51f7aa3073ae32debf2
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*.intf

auto lo
iface lo inet loopback
    address 10.10.10.1/32
    vxlan-local-tunnelip 10.10.10.1

auto mgmt
iface mgmt
    address 127.0.0.1/8
    address ::1/128
    vrf-table auto

auto RED
iface RED
    address 127.0.0.1/8
    address ::1/128
    vrf-table auto

auto BLUE
iface BLUE
    address 127.0.0.1/8
    address ::1/128
    vrf-table auto

auto eth0
iface eth0 inet dhcp
    ip-forward off
    ip6-forward off
    vrf mgmt

auto swp1
iface swp1

auto swp2
iface swp2

auto swp3
iface swp3

auto swp51
iface swp51

auto swp52
iface swp52

auto bond1
iface bond1
    mtu 9000
    bond-slaves swp1
    bond-mode 802.3ad
    bond-lacp-bypass-allow yes
    bridge-access 10

auto bond2
iface bond2
    mtu 9000
    bond-slaves swp2
    bond-mode 802.3ad
    bond-lacp-bypass-allow yes
    bridge-access 20

auto bond3
iface bond3
    mtu 9000
    bond-slaves swp3
    bond-mode 802.3ad
    bond-lacp-bypass-allow yes
    bridge-access 30

auto vlan10
iface vlan10
    address 10.1.10.2/24
    address-virtual 00:00:5e:00:01:01 10.1.10.1/24
    hwaddress 44:38:39:22:01:78
    vrf RED
    vlan-raw-device br_default
    vlan-id 10

auto vlan20
iface vlan20
    address 10.1.20.2/24
    address-virtual 00:00:5e:00:01:01 10.1.20.1/24
    hwaddress 44:38:39:22:01:78
    vrf RED
    vlan-raw-device br_default
    vlan-id 20

auto vlan30
iface vlan30
    address 10.1.30.2/24
    address-virtual 00:00:5e:00:01:01 10.1.30.1/24
    hwaddress 44:38:39:22:01:78
    vrf BLUE
    vlan-raw-device br_default
    vlan-id 30

auto vxlan48
iface vxlan48
    bridge-vlan-vni-map 10=10 20=20 30=30
    bridge-learning off

auto vlan3159_l3
iface vlan3159_l3
    vrf RED
    vlan-raw-device br_l3vni
    vlan-id 3159

auto vlan3607_l3
iface vlan3607_l3
    vrf BLUE
    vlan-raw-device br_l3vni
    vlan-id 3607

auto vxlan99
iface vxlan99
    bridge-vlan-vni-map 3159=4001 3607=4002
    bridge-learning off

auto br_default
iface br_default
    bridge-ports bond1 bond2 bond3 vxlan48
    hwaddress 44:38:39:22:01:78
    bridge-vlan-aware yes
    bridge-vids 10 20 30
    bridge-pvid 1
    bridge-stp yes
    bridge-mcsnoop no
    mstpctl-forcevers rstp

auto br_l3vni
iface br_l3vni
    bridge-ports vxlan99
    hwaddress 44:38:39:22:01:78
    bridge-vlan-aware yes

ifdown 无法找到存在的接口

如果您尝试关闭您知道存在的接口,请将 ifdown--use-current-config 选项结合使用,以强制 ifdown 检查当前的 /etc/network/interfaces 文件以查找接口。例如

cumulus@switch:~$ sudo ifdown br0
error: cannot find interfaces: br0 (interface was probably never up ?)

cumulus@switch:~$ sudo brctl show
bridge name   bridge id      STP enabled interfaces
br0      8000.44383900279f   yes     downlink
                             peerlink

cumulus@switch:~$ sudo ifdown br0 --use-current-config 

删除对子接口的所有引用

如果您的配置具有子接口(无论是 VLAN、链路聚合还是其他物理接口),并且您从正在运行的配置中删除了该接口,则必须删除配置中对它的每个引用。否则,父接口将继续使用该接口。

例如,考虑以下配置

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto bond1
iface bond1
    bond-slaves swp2 swp1

auto bond3
iface bond3
    bond-slaves swp8 swp6 swp7

auto br0
iface br0
    bridge-ports swp3 swp5 bond1 swp4 bond3
    bridge-pathcosts  swp3=4 swp5=4 swp4=4
    address 11.0.0.10/24
    address 2001::10/64

bond1 是 br0 的成员。如果删除 bond1,则必须从 br0 配置中删除对它的引用。否则,如果使用 ifreload -a 重新加载配置,则 bond1 仍是 br0 的一部分。

MTU 数值结果超出范围错误

当您尝试在接口上设置的 MTU 高于较低接口或依赖接口的 MTU 时,会发生 MTU Numerical result out of range 错误。Linux 期望上层接口的 MTU 小于或等于下层接口的 MTU。

在下面的示例中,swp1.100 VLAN 接口是物理接口 swp1 的上层接口。如果您想将 VLAN 接口上的 MTU 更改为 9000,则还必须在下层接口 swp1 上包含新的 MTU。

auto swp1.100
iface swp1.100
    mtu 9000

auto swp1 
iface swp1  
    mtu 9000

iproute2 批处理命令失败

出于性能原因,ifupdown2 批量处理 iproute2 命令。批处理命令在错误消息中包含 ip -force -batch -。失败的命令编号在此行的末尾:Command failed -:1

以下是命令 1 的示例错误:link set dev host2 master bridge。将链路聚合 host2 添加到名为 bridge 的网桥时出错,因为 host2 没有有效的地址。

error: failed to execute cmd 'ip -force -batch - [link set dev host2 master bridge
addr flush dev host2
link set dev host1 master bridge
addr flush dev host1
]'(RTNETLINK answers: Invalid argument
Command failed -:1)
warning: bridge configuration failed (missing ports)

当网桥端口没有有效的硬件地址,或者当您添加到网桥的接口是不完整的链路聚合时,可能会发生此错误;没有从属接口的链路聚合是不完整的,并且没有有效的硬件地址。

MLAG 接口丢包

跨 MLAG 对等链路接口丢失大量数据包通常不是问题。这可能是为了防止 BUM(广播、未知单播和组播)数据包环路而发生的。有关更多详细信息以及如何检测这些丢包的信息,请参阅 MLAG 部分