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 nas VLANs, no switch TP-Link JetStream através do Protocolo Simples de Gerenciamento de Rede (SNMP).
1. Requisitos.
Você deve entender o seguinte antes de ler este documento:
- Como as VLANs funcionam e como configurar VLANs no switch TP-Link JetStream? Guia Oficial.
- Como configurar o SNMP v2c/v3 no switch TP-Link JetStream? Guia Oficial.
- Ler, entender e usar MIBs.
- Configurar e usar os comandos do 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 (Configuração Global), ative o SNMP.

- Vá em SNMP v1/v2c, adicione uma nova comunidade, o nome da Comunidade é tplink, e o Modo de Acesso é Read & Write (Leitura e Gravação).

- Net-SNMP disponível em http://www.net-snmp.org/. Pesquise pelos modelos do seu switch TP-Link no site oficial e baixe o arquivo de MIBs na página de Suporte, em seguida, copie os arquivos MIBs para a pasta MIBs do Net-SNMP.
3. Operações.
Todos os comandos serão listados em itálico azul e negrito. O arquivo MIBs usado aqui para as configurações de VLAN é “tplink-vlan-dot1qVlan.mib”, e o endereço IP do switch aqui é 192.168.0.1.
3.1 Exibir a 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 a VLAN 100, nomeá-la como “VLAN100” e adicionar as 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.
- O dot1qVlanStatus possui duas ações, createAndGo (4) para criar VLANs e destroy (6) para excluir VLANs.
- “i” para número inteiro (integer), “s” para texto (“String”).
Exiba a tabela de VLAN e as configurações de VLAN foram 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 a 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 a 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 pelo snmpwalk.
Cada porta tem seu próprio ifIndex SNMP, ou pode-se dizer o ID da Porta. Para verificar e gerenciar as configurações de VLAN das portas, precisamos saber a correspondência entre as portas e os IDs através do snmpwalk.
De acordo com o resultado a seguir, 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 Exibir a Tabela de VLAN das portas.
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 Alterar 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 |
all |
N/A |
|
…… |
…… |
…… |
…… |
…… |