我正在尝试使用SNMP获取接口的IPv6地址。我有很多接口,其中一些是真实的,我可以很容易地找到它们的IP地址:
jeffs@jeffs-desktop:/home/jeffs $ ip -6 --oneline addr list
1: lo inet6 ::1/128 scope host \ valid_lft forever preferred_lft forever
2: eno1 inet6 2602:61:7120:f400:513b:e4e2:f5ad:5a7/64 scope global noprefixroute \ valid_lft forever preferred_lft forever
2: eno1 inet6 fd00::ae7f:4068:cb55:3152/64 scope global noprefixroute \ valid_lft forever preferred_lft forever
2: eno1 inet6 fe80::59d:1419:ef30:64de/64 scope link noprefixroute \ valid_lft forever preferred_lft forever
5: cbr0 inet6 fe80::b0c6:b1ff:fea1:5313/64 scope link \ valid_lft forever preferred_lft forever
...
19: veth24a321f8 inet6 fe80::f0c6:99ff:fe07:e05f/64 scope link \ valid_lft forever preferred_lft forever
jeffs@jeffs-desktop:/home/jeffs $
我在RFC 8986中读到ipv6IfTable表已被IP-MIB :: ipv6InterfaceTable淘汰。但是,如果我尝试读取表格,则不会获得任何条目。
jeffs@jeffs-desktop:/home/jeffs $ snmptable -v2c -Le -c XXXX -m IP-MIB localhost IP-MIB::ipv6InterfaceTable
IP-MIB::ipv6InterfaceTable: No entries
jeffs@jeffs-desktop:/home/jeffs $
我不明白为什么此表为空。我有很多接口,它们有IPv6地址。实际上,eno1具有全球唯一的IPv6地址。
我一直在戳刺和刺探,并做了一些创造性的谷歌搜索。我发现令我惊讶的一件事是:
jeffs@jeffs-desktop:/home/jeffs $ snmpwalk -v2c -Le -OS -c XyZZy43+ -m IP-MIB localhost IPV6-MIB::ipv6Interfaces
IPV6-MIB::ipv6Interfaces.0 = Gauge32: 13
jeffs@jeffs-desktop:/home/jeffs $
即使RFC 8096很清楚OID已过时,我也没想到。
Blockquote
该对象已作废;没有直接替换,但其值可以从IP-MIB :: ipv6InterfaceTable中的行数得出
摆脱它会破坏事情,并且IETF不愿意做这种事情(这就是为什么我们使用IPv6而不是IPv5的原因)。
我看到了如何使用SNMP构建接口表:
jeffs@jeffs-desktop:/home/jeffs/logbooks (master) * $ snmptable -v 2c -Le -c XyZZy43+ localhost IF-MIB::ifXTable
SNMP table: IF-MIB::ifXTable
ifName ifInMulticastPkts ifInBroadcastPkts ifOutMulticastPkts ifOutBroadcastPkts ifHCInOctets ifHCInUcastPkts ifHCInMulticastPkts ifHCInBroadcastPkts ifHCOutOctets ifHCOutUcastPkts ifHCOutMulticastPkts ifHCOutBroadcastPkts ifLinkUpDownTrapEnable ifHighSpeed ifPromiscuousMode ifConnectorPresent ifAlias ifCounterDiscontinuityTime
lo 0 0 0 0 413900083 1276519 0 0 ? 10 false false 0:0:00:00.00
eno1 2047 0 0 0 14412199986 14760150 2047 0 6894953967 9384868 0 0 ? 1000 false true 0:0:00:00.00
enp3s0 0 0 0 0 0 0 0 0 0 0 0 0 ? 0 false true 0:0:00:00.00
docker0 0 0 0 0 0 0 0 0 0 0 0 0 ? 0 false true 0:0:00:00.00
cbr0 0 0 0 0 85316065 178890 0 0 155204359 196644 0 0 ? 0 false true 0:0:00:00.00
...
jeffs@jeffs-desktop:/home/jeffs/logbooks (master) * $
我也看到了如何建立IP地址表:
jeffs@jeffs-desktop:/home/jeffs $ snmptable -v2c -Le -OS -c XyZZy43+ -m IP-MIB localhost IP-MIB::ipAddressTable
SNMP table: IP-MIB::ipAddressTable
ipAddressIfIndex ipAddressType ipAddressPrefix ipAddressOrigin ipAddressStatus ipAddressCreated ipAddressLastChanged ipAddressRowStatus ipAddressStorageType
5 unicast IP-MIB::ipAddressPrefixOrigin.5.ipv4."10.1.1.0".24 manual preferred 0:0:00:30.19 0:0:00:30.19 active volatile
1 unicast IP-MIB::ipAddressPrefixOrigin.1.ipv4."127.0.0.0".8 manual preferred 0:0:00:00.00 0:0:00:00.00 active volatile
4 unicast IP-MIB::ipAddressPrefixOrigin.4.ipv4."172.17.0.0".16 manual preferred 0:0:00:30.19 0:0:00:30.19 active volatile
4 broadcast IP-MIB::ipAddressPrefixOrigin.4.ipv4."172.17.0.0".16 manual preferred 0:0:00:30.19 0:0:00:30.19 active volatile
2 unicast IP-MIB::ipAddressPrefixOrigin.2.ipv4."192.168.0.0".24 manual preferred 0:0:00:30.19 0:0:00:30.19 active volatile
2 broadcast IP-MIB::ipAddressPrefixOrigin.2.ipv4."192.168.0.0".24 manual preferred 0:0:00:30.19 0:0:00:30.19 active volatile
1 unicast IP-MIB::ipAddressPrefixOrigin.1.ipv6."00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01".128 manual preferred 0:0:00:00.00 0:0:00:00.00 active volatile
2 unicast IP-MIB::ipAddressPrefixOrigin.2.ipv6."26:02:00:61:71:20:f4:00:00:00:00:00:00:00:00:00".64 manual preferred 0:0:00:30.19 0:0:00:30.19 active volatile
....
我只是看不到如何使用SNMP从接口名称映射到IPv4或IPv6地址。也许我想得太过分了-我可能已经想出了一些方法来分叉{ip addr list}命令并在一小时前解析其输出。
谢谢