加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux的ifIndex持久性

发布时间:2020-12-13 17:21:06 所属栏目:Linux 来源:网络整理
导读:我们使用OpManager来监控远程 linux机器上的接口设备.这些框具有VLAN,我们用它来收集有关正在中继到框中的网络的信息.例如,我们有eth0.2,eth0.3,eth0.12,eth0.13,eth0.22,eth0.23(分别与vlans 2,3,12,13,22,23相对应). 我们在管理IP地址上使用SNMP来检查并确
我们使用OpManager来监控远程 linux机器上的接口设备.这些框具有VLAN,我们用它来收集有关正在中继到框中的网络的信息.例如,我们有eth0.2,eth0.3,eth0.12,eth0.13,eth0.22,eth0.23(分别与vlans 2,3,12,13,22,23相对应).

我们在管理IP地址上使用SNMP来检查并确保接口已启动.但是,如果我们必须重新启动网络服务,我们就会遇到接口索引发生变化的问题.我们会收到如下错误消息:

接口’eth0.23 – eth0.23’已关闭.接口描述为’eth0.23′,索引为11.电路ID未配置.

即使界面已启动并正在运行.

如何通过重新启动将索引值更改为持久性.如果我们将接口从静态IP更改为动态,我们已经看到了这一点.

解决方法

简而言之,SNMP RFC不需要在网络管理器重新初始化之间使用ifIndex持久性. net-snmp不提供任何特殊功能来提供此功能.

来自RFC 2863:

The requirement for constancy (between
re-initializations) of an interface’s
ifIndex value is met by requiring that
after an interface is dynamically
removed,its ifIndex value is not
re-used by a different dynamically
added interface until after the
following re-initialization of the
network management system.

需要注意的是,当系统重新初始化(即重新启动)时,明确允许ifIndex条目用于任何接口.

从Linux内核(net / core / dev.c):

static int dev_new_index(struct net *net)
{
    static int ifindex;
    for (;;) {
        if (++ifindex <= 0)
            ifindex = 1;
        if (!__dev_get_by_index(net,ifindex))
            return ifindex;
    }
}

内核中的ifindex分配使用简单的递增算法.这是相关的,因为在net-snmp(agent / mibgroup / if-mib / data_access / interface_ioctl.c)中:

oid
netsnmp_access_interface_ioctl_ifindex_get(int fd,const char *name)
{
#ifndef SIOCGIFINDEX
    return 0;
#else
    struct ifreq    ifrq;
    int rc = 0;

    DEBUGMSGTL(("access:interface:ioctl","ifindex_getn"));

    rc = _ioctl_get(fd,SIOCGIFINDEX,&ifrq,name);
    if (rc < 0) {
        DEBUGMSGTL(("access:interface:ioctl","ifindex_get error on inerface '%s'n",name));
        return 0;
    }

    return ifrq.ifr_ifindex;
#endif /* SIOCGIFINDEX */
}

该函数最终被调用以填充ifindex,它只是使用IOCTL接口从Linux内核中检索SIOCGIFINDEX值.

当我使用基于SNMP的监控系统遇到这种性质的问题时,我最终使用另一种方法来引用网络接口.特别是,我使用接口名称而不是接口索引号(即“eth0”,“eth1”,“vlan150”等).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读