SNMP 的设置
SNMP 的设置
网络需求
让监控端轮询 FortiGate 的系统信息,并接收 FortiGate 主动发送的 Trap。
网络拓扑

配置步骤
进入“网络 → 接口”,编辑接收 SNMP 查询的
lan接口,本例的 IPv4 地址为192.168.100.99。在“管理访问”中,按需在 IPv4(allowaccess)或 IPv6(ip6-allowaccess)下勾选“SNMP”(snmp)。
config system interface edit "lan" append allowaccess snmp config ipv6 append ip6-allowaccess snmp end next end进入“系统 → SNMP”,启用“SNMP 代理”(
set status enable),填写“描述(description)”“位置(location)”和“联系信息(contact-info)”,然后应用配置。监控端可以查询这三项信息。
config system snmp sysinfo set status enable set description "FortiGate_101F" set contact-info "bbai@fortinet.com" set location "Beijing" end在
SNMP v1/v2c中新建并启用 SNMP 团体(set status enable)。避免将“团体名称(name)”设为public。- 在“主机(
config hosts)”中将“IP 地址(ip)”填为192.168.100.177/32,将“主机类型(host-type)”设为“接受查询和发送陷阱”(any)。仅允许轮询时使用query,仅发送 Trap 时使用trap。IPv4 轮询条目可以填写子网,Trap 接收端填写单个 IP 地址。 - 在“IPv6 主机(
config hosts6)”中将“IP 地址(ipv6)”填为2001::2/128,将“主机类型(host-type)”设为“仅发送陷阱”(trap)。 - 在“查询”中按需启用 v1(
query-v1-status)和 v2c(query-v2c-status)。端口(query-v1-port、query-v2c-port)均为 UDP 161。 - 在“陷阱”中按需启用 v1(
trap-v1-status)和 v2c(trap-v2c-status)。本地端口(trap-v1-lport、trap-v2c-lport)和对端端口(trap-v1-rport、trap-v2c-rport)均为 UDP 162。 - 在“SNMP 事件(
events)”中选择触发 Trap 的事件。
重要
团体名称(Community)中不能包含字符
$,否则配置后读取 SNMP 会失败。
config system snmp community edit 1 set name "Fortinet123#" set status enable set query-v1-status enable set query-v2c-status enable set trap-v1-status enable set trap-v2c-status enable config hosts edit 1 set ip 192.168.100.177 255.255.255.255 set host-type any next end config hosts6 edit 1 set ipv6 2001::2/128 set host-type trap next end next end- 在“主机(
在
SNMP v3中新建用户fortinet(edit "fortinet"),并启用该用户(set status enable)。- 在“安全级别(
security-level)”中选择“身份验证”和“私有”(auth-priv)。将“认证算法(auth-proto)”设为“SHA1”(sha),将“加密算法(priv-proto)”设为“AES”(aes,即 AES-128),并分别填写认证密码(auth-pwd)和加密密码(priv-pwd)。 - 在“查询”中启用轮询(
set queries enable),端口(query-port)为 UDP 161。监控端使用相同的用户名、安全级别、算法和密码。 - 在“主机(
notify-hosts)”中添加 IPv4 Trap 接收端192.168.100.177和192.168.100.77,在“IPv6 主机(notify-hosts6)”中添加2100::2(如需)。 - 在“陷阱”中启用 Trap(
set trap-status enable),本地端口(trap-lport)和对端端口(trap-rport)均为 UDP 162。在“SNMP 事件(events)”中选择触发 Trap 的事件。

config system snmp user edit "fortinet" set status enable set queries enable set trap-status enable set notify-hosts 192.168.100.177 192.168.100.77 set notify-hosts6 2100::2 set security-level auth-priv set auth-proto sha set auth-pwd <认证密码> set priv-proto aes set priv-pwd <加密密码> next end提示
- SNMPv3 有三个安全级别。
no-auth-no-priv无认证、无加密,auth-no-priv仅认证,auth-priv同时启用认证和加密。 notify-hosts和notify-hosts6仅指定 Trap 接收端。需要限制轮询来源时,可使用 Local-in Policy。- SNMPv3 的 IPv4 主机只能填写单个单播 IPv4 地址。
- 只使用 SNMPv3 时,可跳过第 3 步。
- 在“安全级别(
相关信息
- 如果所有管理员都配置了可信主机,还需确认轮询源 IP 匹配至少一个管理员的可信主机。详见系统管理 → SNMP → SNMP 与管理员可信主机。
- 通过 HA 成员的独立管理口进行 SNMP 监控时,还需要额外配置,参见系统管理 → SNMP → SNMP 的 HA 独立管理。
结果验证
从
192.168.100.177使用本机snmpwalk对192.168.100.99发起 SNMPv2c 查询,依次读取设备描述、sysUpTime和 FortiOS 版本。$ /usr/bin/snmpwalk -v2c -c 'Fortinet123#' -On -t 2 -r 1 192.168.100.99 .1.3.6.1.2.1.1.1.0 .1.3.6.1.2.1.1.1.0 = STRING: "FortiGate_101F" $ /usr/bin/snmpwalk -v2c -c 'Fortinet123#' -On -t 2 -r 1 192.168.100.99 .1.3.6.1.2.1.1.3.0 .1.3.6.1.2.1.1.3.0 = Timeticks: (251234986) 29 days, 1:52:29.86 $ /usr/bin/snmpwalk -v2c -c 'Fortinet123#' -On -t 2 -r 1 192.168.100.99 .1.3.6.1.4.1.12356.101.4.1.1.0 .1.3.6.1.4.1.12356.101.4.1.1.0 = STRING: "v8.0.2,build0251,260928 (GA.F)"使用 SHA1 和 AES,以
authPriv发起 SNMPv3 查询,读取同一组 OID。$ /usr/bin/snmpwalk -v3 -l authPriv -u <认证密码> -a SHA -A fortinet -x AES -X <加密密码> -On -t 2 -r 1 192.168.100.99 .1.3.6.1.2.1.1.1.0 .1.3.6.1.2.1.1.1.0 = STRING: "FortiGate_101F" $ /usr/bin/snmpwalk -v3 -l authPriv -u <认证密码> -a SHA -A fortinet -x AES -X <加密密码> -On -t 2 -r 1 192.168.100.99 .1.3.6.1.2.1.1.3.0 .1.3.6.1.2.1.1.3.0 = Timeticks: (251234989) 29 days, 1:52:29.89 $ /usr/bin/snmpwalk -v3 -l <认证密码> -u fortinet -a SHA -A fortinet -x AES -X <加密密码> -On -t 2 -r 1 192.168.100.99 .1.3.6.1.4.1.12356.101.4.1.1.0 .1.3.6.1.4.1.12356.101.4.1.1.0 = STRING: "v8.0.2,build0251,260928 (GA.F)"在监控端打开 iReasoning MIB Browser 的“Tools → Trap Receiver”。在测试环境触发一个已启用的 SNMP 事件,确认收到来自 FortiGate 的 Trap,并核对
SNMP Version。
SNMP 排错
从
192.168.100.177向192.168.100.99发起轮询,在 FortiGate 上抓包,确认 UDP 161 的查询和应答。# diagnose sniffer packet any "udp and host 192.168.100.177 and port 161" 4确认“陷阱”开关和对应的“SNMP 事件”已启用。触发事件后,在 FortiGate 上抓包确认报文发往接收端的 UDP 162,再到监控端检查是否收到。以下以
192.168.100.177为例。# diagnose sniffer packet any "udp and dst host 192.168.100.177 and dst port 162" 4如果查询已到达 FortiGate 但轮询仍失败,或事件已触发但 FortiGate 未发出 Trap,开启
snmpdDebug 后复现问题。如下所示,Debug 输出中的failed to match community表示查询携带的 Community 未匹配到设备上的配置。# diagnose debug application snmpd -1 # diagnose debug enable FortiGate # snmpd: updating cache: idx_cache snmpd: <msg> 47 bytes 192.168.90.254:44539 -> 200.1.1.1/200.1.1.1:161 (itf 3.3) snmpd: checking if community "Fortinet123#2" is valid snmpd: updating cache: vdom_idx_map_cache snmpd: updating vdom idx mapping snmpd: Creating vdom_idx_cache for root snmpd: Vdom created kernel-index=0, snmp-index=1, name=root snmpd: checking against community "Fortinet123#" snmpd: vdom name mismatch snmpd: checking against community "FortiManager" snmpd: name mismatch. snmpd: failed to match community "Fortinet123#2" snmpd: </msg> 0排查结束后关闭 Debug 并清除调试设置。
# diagnose debug disable # diagnose debug reset
注意事项
使用 iReasoning MIB Browser 的“get bulk”方式去 get FortiGate 某节点的多个子节点时,默认情况下最多只能读取 10 个,如下所示读取 FortiGate 的接口列表时,使用 get bulk 方式只能读取 10 个接口信息:

此时读取的接口信息是不全的,需要在 iReasoning MIB Browser 的软件配置中,修改“get bulk”的最大值,

再次执行“get bulk”,所有的接口信息都可以 get 到:

也可以使用 walk 方式代替 get bulk 遍历节点。