Check switch port status over SNMP: ifOperStatus, ifAlias, speed

· Vladimir Chemeris, the developer of SNMP Inspector

To check a switch port over SNMP, you read a few objects that share the port’s ifIndex: the configured state, the link state, the description, the speed and the time of the last change. Duplex and the error counters sit in other tables under the same index, so one snmpget can carry them all.

The developer recorded the output below on 2026-11-22 with net-snmp 5.6.2.1, the snmpget in /usr/bin on a Mac. The main device is a MikroTik RB4011iGS+5HacQ2HnD router on RouterOS 7.25.1 (192.0.2.1). IF-MIB defines these objects for any interface, so the same commands work on a switch. The duplex example comes from a Proxmox VE host running net-snmp snmpd (192.0.2.12). The addresses read 192.0.2.x, and <community> hides the community string. The compatibility page lists what SNMP Inspector read from the same devices.

Find the ifIndex by port name

Each port object below takes the ifIndex as its last number. Walk ifName and filter for the port:

$ snmpwalk -v2c -c <community> 192.0.2.1 ifName | grep -w ether7
IF-MIB::ifName.7 = STRING: ether7

The number after ifName. is the index, 7. If you know the description and not the name, search ifAlias the same way:

$ snmpwalk -v2c -c <community> 192.0.2.1 ifAlias | grep -i switch
IF-MIB::ifAlias.11 = STRING: SWITCH10G

RFC 2863 asks ifName to carry the name the device itself uses, the one you would type at its console. ifDescr can hold a longer text, and on RouterOS it repeats the name. The same RFC promises a stable ifIndex “at least from one re-initialization of the entity’s network management system to the next re-initialization”. Look the index up again after a reboot or a firmware upgrade instead of keeping it in a script.

ifAdminStatus vs ifOperStatus

Read both columns for the ports you care about in one GET. On the RB4011, ether4 has a link, ether5 has none, and someone disabled wifi1:

$ snmpget -v2c -c <community> 192.0.2.1 ifName.4 ifAdminStatus.4 ifOperStatus.4 ifName.5 ifAdminStatus.5 ifOperStatus.5 ifName.23 ifAdminStatus.23 ifOperStatus.23
IF-MIB::ifName.4 = STRING: ether4
IF-MIB::ifAdminStatus.4 = INTEGER: up(1)
IF-MIB::ifOperStatus.4 = INTEGER: up(1)
IF-MIB::ifName.5 = STRING: ether5
IF-MIB::ifAdminStatus.5 = INTEGER: up(1)
IF-MIB::ifOperStatus.5 = INTEGER: down(2)
IF-MIB::ifName.23 = STRING: wifi1
IF-MIB::ifAdminStatus.23 = INTEGER: down(2)
IF-MIB::ifOperStatus.23 = INTEGER: down(2)

ifAdminStatus holds the state the configuration asks for. ifOperStatus reports what the interface does now. The RB4011 had no disabled Ethernet port during the test, so its disabled wireless interface stands in for one.

ifAdminStatus ifOperStatus At the rack
up(1) up(1) Enabled, link up
up(1) down(2) Enabled, no link: check the cable, the far-end device and the SFP
down(2) down(2) Disabled in the configuration: a new cable won’t bring it up

RFC 2863 gives ifOperStatus seven values. Besides up and down, watch for lowerLayerDown(7), an interface that is down because an interface below it is down, and notPresent(6), an interface with a missing component. A script that compares the value with 1 alone reports both as plain down.

ifAlias: the port description

$ snmpget -v2c -c <community> 192.0.2.1 ifAlias.4 ifAlias.5 ifAlias.11 ifAlias.13 ifName.13
IF-MIB::ifAlias.4 = STRING: 
IF-MIB::ifAlias.5 = STRING: Empty4
IF-MIB::ifAlias.11 = STRING: SWITCH10G
IF-MIB::ifAlias.13 = STRING: defconf
IF-MIB::ifName.13 = STRING: bridge

ifAlias sits in ifXTable and holds the description an operator typed. RFC 2863 calls it a “non-volatile ‘handle’ for the interface” and has the agent keep it across reboots, even when the ifIndex changes. RouterOS fills it from the interface comment: the default configuration puts the comment defconf on bridge, and ifAlias.13 returns it. ether4 has no comment, and the agent returns an empty string with no error.

The owner of this router typed Empty4 and SWITCH10G, and someone may have repatched those ports since. Before you move a cable because of a description, confirm the far end with the LLDP neighbor of the port or the MAC addresses behind it.

ifHighSpeed vs ifSpeed

$ snmpget -v2c -c <community> 192.0.2.1 ifSpeed.4 ifHighSpeed.4 ifSpeed.11 ifHighSpeed.11 ifSpeed.5 ifHighSpeed.5
IF-MIB::ifSpeed.4 = Gauge32: 100000000
IF-MIB::ifHighSpeed.4 = Gauge32: 100
IF-MIB::ifSpeed.11 = Gauge32: 4294967295
IF-MIB::ifHighSpeed.11 = Gauge32: 10000
IF-MIB::ifSpeed.5 = Gauge32: 0
IF-MIB::ifHighSpeed.5 = Gauge32: 0

ifSpeed counts bit/s in a Gauge32, which stops at 4,294,967,295. RFC 2863 tells agents to report that maximum for faster interfaces and to give the speed in ifHighSpeed, in units of 1,000,000 bit/s. The SFP+ port shows both: ifSpeed.11 sits at the ceiling, and ifHighSpeed.11 reads 10000, which makes 10 Gbit/s. Read ifHighSpeed, and the ceiling doesn’t apply.

ether4 is a gigabit port that linked at 100 Mbit/s. A 100 Mbit/s device at the far end gives that reading, and so can a cable with a damaged pair: 1000BASE-T needs all four pairs, and 100BASE-TX runs on two. ether5 has no link. RouterOS and the net-snmp agent in this lab both report speed 0 for a port without link, so read the speed next to ifOperStatus.

ifLastChange vs sysUpTime: when the port changed state

$ snmpget -v2c -c <community> 192.0.2.1 sysUpTime.0 ifLastChange.4 ifLastChange.5 ifLastChange.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (63208600) 7 days, 7:34:46.00
IF-MIB::ifLastChange.4 = Timeticks: (1659) 0:00:16.59
IF-MIB::ifLastChange.5 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.10 = Timeticks: (63096362) 7 days, 7:16:03.62

ifLastChange holds the value of sysUpTime at the moment the interface entered its current operational state. Read both in one request, subtract, and divide by 100, since TimeTicks count hundredths of a second.

  • ether10: 63,208,600 minus 63,096,362 is 112,238, so the port changed state 18 min 42 s before the read.
  • ether4: 1659 means 16.59 s after the agent started. The port has held its state for 7 days 7 h 34 min.
  • ether5: 0. IF-MIB returns zero “if the current state was entered prior to the last re-initialization of the local network management subsystem”. The port has had no link since at least the agent start.

RFC 3418 defines sysUpTime as the time since the network management part of the system last started, so an agent restart resets it while the device keeps forwarding. One read shows the last change alone: a port that flapped 20 times this morning shows the time of the last flap. Read ifLastChange twice, a few minutes apart. A new value on the second read means the port changed state in between.

Duplex: dot3StatsDuplexStatus

Duplex lives in EtherLike-MIB, and net-snmp 5.6.2.1 on the Mac doesn’t load that module by default. Without it, snmpget can’t turn the name into an OID and stops before it sends a request:

$ snmpget -v2c -c <community> 192.0.2.1 dot3StatsDuplexStatus.4
No log handling enabled - using stderr logging
dot3StatsDuplexStatus.4: Unknown Object Identifier (Sub-id not found: (top) -> dot3StatsDuplexStatus)
[exit 1]

With -m +EtherLike-MIB the request goes out, and RouterOS 7.25.1 answers that it doesn’t serve the object:

$ snmpget -m +EtherLike-MIB -v2c -c <community> 192.0.2.1 dot3StatsDuplexStatus.4
EtherLike-MIB::dot3StatsDuplexStatus.4 = No Such Object available on this agent at this OID
[exit 0]

The Proxmox host serves it. Its 2.5 Gbit/s port enp4s0 reports full duplex, and eno1, without link, has no row:

$ snmpget -m +EtherLike-MIB -v2c -c <community> 192.0.2.12 ifName.3 ifOperStatus.3 ifHighSpeed.3 dot3StatsDuplexStatus.3 ifName.2 ifOperStatus.2 dot3StatsDuplexStatus.2
IF-MIB::ifName.3 = STRING: enp4s0
IF-MIB::ifOperStatus.3 = INTEGER: up(1)
IF-MIB::ifHighSpeed.3 = Gauge32: 2500
EtherLike-MIB::dot3StatsDuplexStatus.3 = INTEGER: fullDuplex(3)
IF-MIB::ifName.2 = STRING: eno1
IF-MIB::ifOperStatus.2 = INTEGER: down(2)
EtherLike-MIB::dot3StatsDuplexStatus.2 = No Such Instance currently exists at this OID

dot3StatsDuplexStatus reads unknown(1), halfDuplex(2) or fullDuplex(3), and its index matches the ifIndex. Record a missing answer as Unknown and don’t assume full duplex. In a duplex mismatch, the half-duplex end counts late collisions and the full-duplex end counts FCS errors; switch port errors has the details.

Traffic and error counters

$ snmpget -v2c -c <community> 192.0.2.1 ifHCInOctets.11 ifHCOutOctets.11 ifInErrors.11 ifOutErrors.11 ifInDiscards.11
IF-MIB::ifHCInOctets.11 = Counter64: 1088332025725
IF-MIB::ifHCOutOctets.11 = Counter64: 419527234466
IF-MIB::ifInErrors.11 = Counter32: 0
IF-MIB::ifOutErrors.11 = Counter32: 0
IF-MIB::ifInDiscards.11 = Counter32: 0

One read gives totals since the counters started. For a rate, read twice and divide each change by the seconds between the reads. Take the 64-bit ifHCInOctets and ifHCOutOctets: at 10 Gbit/s the 32-bit ifInOctets wraps in 3.4 seconds, and the arithmetic is in ifInOctets vs ifHCInOctets. The error counters have no 64-bit version, and a zero on an idle port proves little. For errors and FCS counters under traffic, see switch port errors.

Checklist: one port in five reads

  1. Find the ifIndex. snmpwalk -v2c -c <community> 192.0.2.1 ifName | grep -w ether7, or walk ifAlias and filter by the description. The number after the last dot is the ifIndex.
  2. Read the status. GET ifAdminStatus and ifOperStatus for that index in one request. up(1) with down(2) means an enabled port without link.
  3. Read speed and duplex. GET ifHighSpeed for the speed in Mbit/s. Add -m +EtherLike-MIB and GET dot3StatsDuplexStatus. If the agent answers No Such Object, record duplex as unknown.
  4. Read the last change. GET sysUpTime.0 and ifLastChange in one request, subtract, and divide by 100 to get the seconds since the port changed state.
  5. Read the counters twice. GET the octet and error counters, wait 30-60 seconds with traffic on the link, GET them again and divide each change by the interval.

OID and command table

In the commands, $A stands for -v2c -c <community> 192.0.2.1, and 7 is the ifIndex.

You want Object and OID Command
The ifIndex ifName 1.3.6.1.2.1.31.1.1.1.1 snmpwalk $A ifName
The description ifAlias 1.3.6.1.2.1.31.1.1.1.18 snmpget $A ifAlias.7
Enabled or disabled ifAdminStatus 1.3.6.1.2.1.2.2.1.7 snmpget $A ifAdminStatus.7
Link up or down ifOperStatus 1.3.6.1.2.1.2.2.1.8 snmpget $A ifOperStatus.7
Speed in Mbit/s ifHighSpeed 1.3.6.1.2.1.31.1.1.1.15 snmpget $A ifHighSpeed.7
Speed in bit/s, up to 4294967295 ifSpeed 1.3.6.1.2.1.2.2.1.5 snmpget $A ifSpeed.7
Last state change ifLastChange 1.3.6.1.2.1.2.2.1.9, sysUpTime 1.3.6.1.2.1.1.3.0 snmpget $A sysUpTime.0 ifLastChange.7
Duplex dot3StatsDuplexStatus 1.3.6.1.2.1.10.7.2.1.19 snmpget -m +EtherLike-MIB $A dot3StatsDuplexStatus.7
Traffic ifHCInOctets 1.3.6.1.2.1.31.1.1.1.6, ifHCOutOctets 1.3.6.1.2.1.31.1.1.1.10 snmpget $A ifHCInOctets.7 ifHCOutOctets.7
Errors ifInErrors 1.3.6.1.2.1.2.2.1.14, ifOutErrors 1.3.6.1.2.1.2.2.1.20 snmpget $A ifInErrors.7 ifOutErrors.7
Discards ifInDiscards 1.3.6.1.2.1.2.2.1.13 snmpget $A ifInDiscards.7

A switch port in SNMP Inspector

SNMP Inspector reads the same objects when you open a port on iPhone or iPad. The port card shows the status as Up, Down, Admin down, Lower layer down or Not present, with the time since the last change beside it. The demo port in the screenshot reads “Changed” and “6h ago”. The speed comes from ifHighSpeed, and the errors card shows errors per second from two reads in place of the totals. Raw values names the source of each field: “Status · ifOperStatus”, “Speed · ifHighSpeed, Mbit/s”, “Duplex · dot3StatsDuplexStatus”. If the agent doesn’t serve duplex, as on the RB4011, the card says “Unknown: no EtherLike-MIB” in place of a duplex value.

The same card lists the port’s VLAN under “PVID” and “Untagged · tagged”, the LLDP neighbor or “No neighbor reported”, and the MAC addresses the switch learned on the port. To find a port you know by its description, type part of it into the port list search, “Search name, alias, LLDP, MAC or VLAN”. The app has no SET operation and never writes to the device.

Questions

What is the difference between ifAdminStatus and ifOperStatus?

ifAdminStatus is the state the configuration asks for: up(1) for an enabled port, down(2) for a port someone disabled. ifOperStatus is the state the port is in now. An enabled port without link reads up(1) and down(2), so check the cable, the far-end device and the SFP.

How do I find the ifIndex of a switch port by name?

Walk ifName and filter by the name: snmpwalk -v2c -c <community> 192.0.2.1 ifName | grep -w ether7 prints IF-MIB::ifName.7 = STRING: ether7, so the ifIndex is 7. Walk ifAlias the same way to search by description. Look the index up again after a reboot or an upgrade.

How do I see when a switch port went down with SNMP?

GET sysUpTime.0 and the port's ifLastChange in one request and subtract. The difference, in hundredths of a second, is the time since the port entered its current state. A value of 0 means the state began before the agent last started. IF-MIB keeps the last change and no flap count.

Why does snmpget say Unknown Object Identifier for dot3StatsDuplexStatus?

Your net-snmp didn't load EtherLike-MIB, so it can't turn the name into an OID and sends nothing. Add -m +EtherLike-MIB or use the number 1.3.6.1.2.1.10.7.2.1.19. If the agent then answers No Such Object, it doesn't serve duplex, as RouterOS 7.25.1 did in this test.

How do I read a switch port description over SNMP?

Read ifAlias (1.3.6.1.2.1.31.1.1.1.18). It holds the description an operator set, such as the interface comment on RouterOS. An empty string means the port has no description. ifDescr holds the agent's own text about the interface and on RouterOS repeats the name.