Como verificar e modificar VLANs em um switch TP-Link JetStream via SNMP
Este artigo demonstra como verificar as configurações de VLAN, criar e excluir VLANs, bem como adicionar e remover portas em VLANs no switch TP-Link JetStream via o protocolo SNMP (Simple Network Management Protocol).
1. Requisitos.
Você deve compreender o seguinte antes de ler este documento:
- Como as VLANs funcionam e como configurá-las no switch TP-Link JetStream? Guia Oficial.
- Como configurar SNMP v2c/v3 no switch TP-Link JetStream? Guia Oficial.
- Leitura, compreensão e uso de MIBs.
- Configurar e usar comandos NET-SNMP, incluindo snmpget, snmpset, snmptable, snmpwalk ou outro software SNMP.
2. Preparações.
Aqui descrevemos brevemente a configuração do SNMP v2c. Para um Guia de Configuração detalhado do SNMP, consulte o Guia Oficial.
- Vá em Maintenance (Manutenção) --> SNMP --> Global Config, habilite o SNMP.

- Vá em SNMP v1/v2c, adicione uma nova comunidade, o nome da comunidade (Community name) é tplink e o Modo de Acesso (Access Mode) é Read & Write (Leitura e Escrita).

- Net-SNMP disponível em http://www.net-snmp.org/ Procure os modelos de switch TP-Link no site oficial e baixe o arquivo MIBs na página de Suporte, depois copie os arquivos MIBs para a pasta MIBs do Net-SNMP.
3. Operações.
Todos os comandos serão listados em azul itálico e negrito. O arquivo MIB utilizado aqui para configurações de VLAN é “tplink-vlan-dot1qVlan.mib”, e o endereço IP do switch neste exemplo é 192.168.0.1.
3.1 Mostrar tabela de VLAN.
snmptable -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanConfigTable
|
dot1qVlanId |
dot1qVlanDescription |
vlanTagPortMemberAdd |
vlanUntagPortMemberAdd |
vlanPortMemberRemove |
dot1qVlanStatus
|
|
1 |
“System-VLAN” |
“” |
“1/0/1-28” |
“” |
active |
3.2 Criar VLAN 100, nomeá-la como “VLAN100” e adicionar portas untag 1/0/2-4.
Use o comando snmpset para definir o ID da VLAN, o Nome da VLAN, as portas a serem adicionadas e a ação “createAndGo” a ser executada.
snmpset -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 dot1qVlanId.100 i 100 dot1qVlanDescription.100 s VLAN100 vlanUntagPortMemberAdd.100 s 1/0/2-4 dot1qVlanStatus.100 i 4
TPLINK-DOT1Q-VLAN-MIB::dot1qVlanId.100 = INTEGER: 100
TPLINK-DOT1Q-VLAN-MIB::dot1qVlanDescription.100 = STRING: "VLAN100"
TPLINK-DOT1Q-VLAN-MIB::vlanUntagPortMemberAdd.100 = STRING: "1/0/2-4"
TPLINK-DOT1Q-VLAN-MIB::dot1qVlanStatus.100 = INTEGER: createAndGo(4)
Nota:
- O último número no OID é o número da VLAN a ser criada ou excluída.
- dot1qVlanStatus possui duas ações: createAndGo (4) para criar VLANs e destroy (6) para excluir VLANs.
- “i” para integer (inteiro), “s” para “String”.
Mostre a tabela de VLAN, e as configurações de VLAN terão sido atualizadas para entrar em vigor.
snmptable -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanConfigTable
|
dot1qVlanId |
dot1qVlanDescription |
vlanTagPortMemberAdd |
vlanUntagPortMemberAdd |
vlanPortMemberRemove |
dot1qVlanStatus
|
|
1 |
“System-VLAN” |
“” |
“1/0/1-28” |
“” |
active |
|
100 |
“VLAN100” |
“” |
“1/0/2-4” |
“” |
active |
3.3 Remover porta untag 1/0/2 da VLAN 100.
snmpset -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanPortMemberRemove.100 s 1/0/2
TPLINK-DOT1Q-VLAN-MIB::vlanPortMemberRemove.100 = STRING: "1/0/2"
snmptable -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanConfigTable
|
dot1qVlanId |
dot1qVlanDescription |
vlanTagPortMemberAdd |
vlanUntagPortMemberAdd |
vlanPortMemberRemove |
dot1qVlanStatus
|
|
1 |
“System-VLAN” |
“” |
“1/0/1-28” |
“” |
active |
|
100 |
“VLAN100” |
“” |
“1/0/3-4” |
“” |
active |
A porta 1/0/2 foi removida da VLAN 100.
3.4 Adicionar porta untag 1/0/5 à VLAN 100.
snmpset -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanUntagPortMemberAdd.100 s 1/0/5
TPLINK-DOT1Q-VLAN-MIB::vlanUntagPortMemberAdd.100 = STRING: "1/0/5"
snmptable -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanConfigTable
|
dot1qVlanId |
dot1qVlanDescription |
vlanTagPortMemberAdd |
vlanUntagPortMemberAdd |
vlanPortMemberRemove |
dot1qVlanStatus
|
|
1 |
“System-VLAN” |
“” |
“1/0/1-28” |
“” |
active |
|
100 |
“VLAN100” |
“” |
“1/0/3-5” |
“” |
active |
A porta 1/0/5 foi adicionada à VLAN 100.
3.5 Verificar o ID da Porta por snmpwalk.
Cada porta tem seu próprio ifIndex SNMP, ou você pode chamar de ID da Porta. Para verificar e gerenciar as configurações de VLAN da porta, precisamos saber a correspondência entre as portas e os IDs através do snmpwalk.
De acordo com o resultado abaixo, o ID da porta GigaEthernet 1/0/1 é 49153, da GigaEthernet 1/0/2 é 49154 ……
snmpwalk -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1
RFC1213-MIB::sysDescr.0 = STRING: "JetStream 24-Port Gigabit L2 Managed Switch with 4 SFP Slots"
……
RFC1213-MIB::ifIndex.1 = INTEGER: 1
RFC1213-MIB::ifIndex.49152 = INTEGER: 49152
RFC1213-MIB::ifIndex.49153 = INTEGER: 49153
RFC1213-MIB::ifIndex.49154 = INTEGER: 49154
RFC1213-MIB::ifIndex.49155 = INTEGER: 49155
RFC1213-MIB::ifIndex.49156 = INTEGER: 49156
RFC1213-MIB::ifIndex.49157 = INTEGER: 49157
……
RFC1213-MIB::ifDescr.1 = STRING: "Vlan-interface1"
RFC1213-MIB::ifDescr.49152 = STRING: "AUX0"
RFC1213-MIB::ifDescr.49153 = STRING: "gigabitEthernet 1/0/1 : copper"
RFC1213-MIB::ifDescr.49154 = STRING: "gigabitEthernet 1/0/2 : copper"
RFC1213-MIB::ifDescr.49155 = STRING: "gigabitEthernet 1/0/3 : copper"
RFC1213-MIB::ifDescr.49156 = STRING: "gigabitEthernet 1/0/4 : copper"
RFC1213-MIB::ifDescr.49157 = STRING: "gigabitEthernet 1/0/5 : copper"
……
3.6 Mostrar tabela de VLAN por porta.
snmptable -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanPortConfigTable
SNMP table: TPLINK-DOT1Q-VLAN-MIB::vlanPortConfigTable
|
vlanPortNumber |
vlanPortPvid |
vlanPortIngressCheck |
vlanPortAcceptFrameType |
vlanPortLag |
|
"1/0/1" |
1 |
enable |
all |
N/A |
|
“1/0/2” |
1 |
enable |
all |
N/A |
|
“1/0/3” |
1 |
enable |
all |
N/A |
|
…… |
…… |
…… |
…… |
…… |
snmpwalk -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanPortPvid
TPLINK-DOT1Q-VLAN-MIB::vlanPortPvid.49153 = INTEGER: 1
TPLINK-DOT1Q-VLAN-MIB::vlanPortPvid.49154 = INTEGER: 1
TPLINK-DOT1Q-VLAN-MIB::vlanPortPvid.49155 = INTEGER: 1
……
3.7 Mudar o PVID da porta 1/0/1 para a VLAN 100.
snmpset -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanPortPvid.49153 i 100
TPLINK-DOT1Q-VLAN-MIB::vlanPortPvid.49153 = INTEGER: 100
snmptable -c tplink -v 2c -m TPLINK-DOT1Q-VLAN-MIB 192.168.0.1 vlanPortConfigTable
SNMP table: TPLINK-DOT1Q-VLAN-MIB::vlanPortConfigTable
|
vlanPortNumber |
vlanPortPvid |
vlanPortIngressCheck |
vlanPortAcceptFrameType |
vlanPortLag |
|
"1/0/1" |
100 |
enable |
all |
N/A |
|
“1/0/2” |
1 |
enable |
all |
N/A |
|
“1/0/3” |
1 |
enable |