Mikrotik RB751G-2HnD路由器上的SNMP

时间:2020-03-21 11:48:22  来源:igfitidea点击:

在Mikrotik RB751G-2HnD路由器上为Zabbix监视系统配置SNMP。

Mikrotik路由器上的SNMP

SSH进入Mikrotik路由器。
默认情况下应禁用SNMP:

> snmp print
          enabled: no
          contact: 
         location: 
        engine-id: 
      trap-target: 0.0.0.0
   trap-community: (unknown)
     trap-version: 1
  trap-generators:

创建新的SNMP社区

创建一个新的名为“ zabbix”的SNMP社区,在本示例中,我们将使用托管在Debian计算机(IP 10.10.1.17)上的Zabbix监视系统,因此社区名称为“ zabbix”,其IP地址为10.10.1.17.

> snmp community add name=zabbix read-access=yes write-access=no addresses=10.10.1.17/32

检查可用的社区:

> snmp community print value-list
                       name: public        zabbix
                  addresses: 0.0.0.0/0     10.10.1.17/32
                   security: none          none
                read-access: yes           yes
               write-access: no            no
    authentication-protocol: MD5           MD5
        encryption-protocol: DES           DES
    authentication-password:               
        encryption-password:

为新社区启用SNMP

启用“ zabbix” SNMP社区:

> snmp set trap-community=zabbix trap-version=2 enabled=yes

检查SNMP设置:

> snmp print
          enabled: yes
          contact: 
         location: 
        engine-id: 
      trap-target: 
   trap-community: zabbix
     trap-version: 2
  trap-generators:

在防火墙上启用SNMP

添加防火墙规则以允许SNMP流量从Zabbix服务器(IP 10.10.1.17)到路由器(IP 10.10.1.1)UDP端口161:

> ip firewall filter add chain=input src-address=10.10.1.17/32 dst-address=10.10.1.1/32 protocol=udp dst-port=161 action=accept

要监视的SNMP OID

从Mikrotik获取SNMP OID

> interface print oid
Flags: D - dynamic, X - disabled, R - running, S - slave 
 0  R  name=.1.3.6.1.2.1.2.2.1.2.1 mtu=.1.3.6.1.2.1.2.2.1.4.1 
       mac-address=.1.3.6.1.2.1.2.2.1.6.1 admin-status=.1.3.6.1.2.1.2.2.1.7.1 
       oper-status=.1.3.6.1.2.1.2.2.1.8.1 bytes-in=.1.3.6.1.2.1.31.1.1.1.6.1 
       packets-in=.1.3.6.1.2.1.31.1.1.1.7.1 discards-in=.1.3.6.1.2.1.2.2.1.13.1 
       errors-in=.1.3.6.1.2.1.2.2.1.14.1 bytes-out=.1.3.6.1.2.1.31.1.1.1.10.1 
       packets-out=.1.3.6.1.2.1.31.1.1.1.11.1 discards-out=.1.3.6.1.2.1.2.2.1.19.1 
       errors-out=.1.3.6.1.2.1.2.2.1.20.1
 1  XS name=.1.3.6.1.2.1.2.2.1.2.2 mtu=.1.3.6.1.2.1.2.2.1.4.2 
       mac-address=.1.3.6.1.2.1.2.2.1.6.2 admin-status=.1.3.6.1.2.1.2.2.1.7.2 
       oper-status=.1.3.6.1.2.1.2.2.1.8.2 bytes-in=.1.3.6.1.2.1.31.1.1.1.6.2 
       packets-in=.1.3.6.1.2.1.31.1.1.1.7.2 discards-in=.1.3.6.1.2.1.2.2.1.13.2 
       errors-in=.1.3.6.1.2.1.2.2.1.14.2 bytes-out=.1.3.6.1.2.1.31.1.1.1.10.2 
       packets-out=.1.3.6.1.2.1.31.1.1.1.11.2 discards-out=.1.3.6.1.2.1.2.2.1.19.2 
       errors-out=.1.3.6.1.2.1.2.2.1.20.2
[...]

上面的输出不显示接口名称,但显示其ID。

找出OID的接口顺序

可以通过以下方式找到接口名称:

> interface print terse
 0  R  name=ether1 default-name=ether1 type=ether mac-address=[...]:2C fast-path=yes 
 1  XS name=ether2 default-name=ether2 type=ether mac-address=[...]:2D fast-path=yes 
 2   S name=ether3 default-name=ether3 type=ether mac-address=[...]:2E fast-path=yes 
 3  RS name=ether4 default-name=ether4 type=ether mac-address=[...]:2F fast-path=yes 
 4  RS name=ether5 default-name=ether5 type=ether mac-address=[...]:30 fast-path=yes 
 5  RS name=wlan0  default-name=wlan1 type=wlan mac-address=[...]:31 fast-path=no 
 6  R  name=wlan1  type=wlan mac-address=[...]:31 fast-path=no 
 7  R  name=lan-bridge type=bridge mac-address=[...]:2D fast-path=no

我们看到ID为0的是ether1,ID为1的是ether2,依此类推。

Snmwalk:从Linux服务器获取SNMP OID

也可以从启用了Mikrotik防火墙访问的Zabbix服务器中检索SNMP OID。
安装SNMP软件包:

# apt-get install snmp

通过使用“ zabbix”社区名称和SNMP版本2c从目标计算机10.10.1.1检索管理值的子树:

$snmpwalk -v 2c -c zabbix 10.10.1.1 > snmp-oid.txt
  • 2c:SNMP版本。可能的选项是1、2c或者3.
  • zabbix:社区名称,例如公众等
  • 10.10.1.1:目标计算机的IP,或者本地计算机的localhost。

Grep输出文件以找出接口OID及其名称:

$grep -w 3.6.1.2.1.2.2.1.2 snmp-oid.txt
iso.3.6.1.2.1.2.2.1.2.1 = STRING: "ether1"
iso.3.6.1.2.1.2.2.1.2.2 = STRING: "ether2"
iso.3.6.1.2.1.2.2.1.2.3 = STRING: "ether3"
iso.3.6.1.2.1.2.2.1.2.4 = STRING: "ether4"
iso.3.6.1.2.1.2.2.1.2.5 = STRING: "ether5"
iso.3.6.1.2.1.2.2.1.2.6 = STRING: "wlan0"
iso.3.6.1.2.1.2.2.1.2.7 = STRING: "lan-bridge"
iso.3.6.1.2.1.2.2.1.2.8 = STRING: "wlan1"

SNMP OID和接口

至于路由板751G-2HnD(http://routerboard.com/RB751G-2HnD):

name=.1.3.6.1.2.1.2.2.1.2.1  | ether1
name=.1.3.6.1.2.1.2.2.1.2.2  | ether2
name=.1.3.6.1.2.1.2.2.1.2.3  | ether3
name=.1.3.6.1.2.1.2.2.1.2.4  | ether4
name=.1.3.6.1.2.1.2.2.1.2.5  | ether5
name=.1.3.6.1.2.1.2.2.1.2.6  | wlan1
name=.1.3.6.1.2.1.2.2.1.2.7  | bridge-lan
name=.1.3.6.1.2.1.2.2.1.2.8  | wlan2 (created manually)

至于路由板2011UAS-2HnD-IN(http://routerboard.com/RB2011UiAS-2HnD-IN):

name=.1.3.6.1.2.1.2.2.1.2.1  | sfp1
name=.1.3.6.1.2.1.2.2.1.2.2  | ether1
name=.1.3.6.1.2.1.2.2.1.2.3  | ether2
name=.1.3.6.1.2.1.2.2.1.2.4  | ether3
name=.1.3.6.1.2.1.2.2.1.2.5  | ether4
name=.1.3.6.1.2.1.2.2.1.2.6  | ether5
name=.1.3.6.1.2.1.2.2.1.2.7  | ether6
name=.1.3.6.1.2.1.2.2.1.2.8  | ether7
name=.1.3.6.1.2.1.2.2.1.2.9  | ether8
name=.1.3.6.1.2.1.2.2.1.2.10 | ether9
name=.1.3.6.1.2.1.2.2.1.2.11 | ether10
name=.1.3.6.1.2.1.2.2.1.2.12 | wlan1
name=.1.3.6.1.2.1.2.2.1.2.13 | bridge-lan

使用OID

8是接口状态:

iso.3.6.1.2.1.2.2.1.8.16

10是入站流量:

iso.3.6.1.2.1.2.2.1.10.1

16是出站流量:

iso.3.6.1.2.1.2.2.1.16.2