1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
|
---
myst:
html_meta:
description: |
SNMP is an Internet standard protocol for collecting and
organizing information about managed devices on IP networks and
for modifying that information to change device behavior.
keywords: snmp, snmpv2c, snmpv3, mib, community, trap, usm, vacm, engineid
---
(snmp)=
# SNMP
{abbr}`SNMP (Simple Network Management Protocol)` is an Internet
standard protocol for collecting and organizing information about
managed devices on IP networks and for modifying that information to
change device behavior. Devices that support SNMP typically include
routers, switches, servers, workstations, and printers.
SNMP exposes management data as variables organized in a management
information base ({abbr}`MIB (Management Information Base)`), which
describes the managed system's status and configuration. Managed
devices run a software component called an agent, which has local
knowledge of management information and translates it to and from an
SNMP-specific form. One or more administrative computers, running
{abbr}`NMS (Network Management System)` software, remotely query (and,
in some circumstances, manipulate) these variables.
Three significant versions of SNMP have been developed and deployed.
SNMPv1 is the original version of the protocol. More recent versions,
SNMPv2c and SNMPv3, feature improvements in performance, flexibility,
and security.
A VyOS router is such a managed device: VyOS provides its SNMP agent,
configurable under `service snmp`. When you commit the configuration,
VyOS generates the agent configuration from these settings and starts
the agent, which then answers SNMP requests and sends notifications to
any configured monitoring systems (trap targets).
## SNMP protocol versions
VyOS supports community-based SNMPv2c and SNMPv3. SNMPv3 is recommended
because of improved security (authentication and encryption).
### SNMPv2c
SNMPv2c authorizes clients using the concept of communities. A
community may be authorized read-only (`ro`, the most common case) or
read-write (`rw`). A configured community also authorizes SNMPv1
requests.
SNMP can work synchronously or asynchronously. In synchronous
communication, the monitoring system queries the router periodically.
In asynchronous communication, the router sends notifications to a trap
target.
SNMPv2c authenticates requests only by the community string, which is
transmitted in clear text, and supports no encryption. Restrict access
to the addresses or networks of trusted clients, and prefer SNMPv3
where possible.
### SNMPv3
SNMPv3 introduced the security features missing from previous protocol
versions. Each SNMPv3 message carries security parameters whose meaning
depends on the security model in use. VyOS uses the
{abbr}`USM (User-based Security Model)` (RFC 3414) together with the
{abbr}`VACM (View-based Access Control Model)` (RFC 3415).
The security approach in SNMPv3 targets:
- Confidentiality: Encryption of packets to prevent snooping by an
unauthorized source.
- Integrity: Message integrity to ensure that a packet has not been
tampered with while in transit, including an optional packet replay
protection mechanism.
- Authentication: Verification that the message is from a valid source.
## Configuration
### Listener
```{cfgcmd} set service snmp listen-address \<address\> port \<1-65535\>
Configure a local IPv4 or IPv6 address, and optionally a port, on which
the SNMP agent listens for incoming SNMP requests.
The address must already be assigned to a local interface in the same
{abbr}`VRF (Virtual Routing and Forwarding)` as the agent. Otherwise,
the commit fails.
Repeat the command to configure multiple addresses.
When unset, the agent listens on all local IPv4 and IPv6 addresses.
The default port is 161.
When at least one listen address is configured, VyOS automatically adds
127.0.0.1 and ::1 (port 161) to the configured listen addresses.
```
Example:
```none
set service snmp listen-address 192.0.2.1
set service snmp listen-address 2001:db8::1
```
```{cfgcmd} set service snmp protocol \<udp | tcp\>
**Configure the transport protocol on which the SNMP agent listens.**
The default is `udp`.
```
Example:
```none
set service snmp protocol tcp
```
```{cfgcmd} set service snmp vrf \<name\>
Bind the SNMP agent to the specified VRF instance.
The VRF must already be configured under `set vrf name <name>`.
Otherwise, the commit fails.
```
Example:
```none
set service snmp vrf mgmt
```
### System information
```{cfgcmd} set service snmp contact \<contact\>
Configure the system contact information that the SNMP agent publishes
in the SNMPv2-MIB `sysContact` object (RFC 3418).
The value is limited to 255 characters.
```
Example:
```none
set service snmp contact 'admin@example.com'
```
```{cfgcmd} set service snmp location \<location\>
Configure the system location information that the SNMP agent publishes
in the SNMPv2-MIB `sysLocation` object (RFC 3418).
The value is limited to 255 characters.
```
Example:
```none
set service snmp location 'UK, London'
```
```{cfgcmd} set service snmp description \<description\>
Configure the system description that the SNMP agent publishes in the
SNMPv2-MIB `sysDescr` object (RFC 3418).
By default, the SNMP agent publishes `VyOS <version>` as the system
description. The value is limited to 255 characters.
```
Example:
```none
set service snmp description 'Edge router'
```
### SNMPv2c communities
By default, a community grants access to the whole MIB except the
routing and address resolution tables. `set service snmp oid-enable`
adds them.
```{cfgcmd} set service snmp community \<name\>
Configure a community string that authorizes client requests.
The community name may contain alphanumeric characters and `-`, `_`,
`!`, `@`, `*`, `#`, with a maximum length of 100 characters.
```
Example:
```none
set service snmp community routers
```
```{cfgcmd} set service snmp community \<name\> authorization \<ro | rw\>
Configure the authorization granted to clients using the specified
community: read-only (`ro`) or read-write (`rw`).
The default is `ro`.
```
Example:
```none
set service snmp community routers authorization ro
```
```{cfgcmd} set service snmp community \<name\> client \<address\>
**Configure an IPv4 or IPv6 address of a client allowed to contact the
router using the specified community.**
Repeat the command to allow multiple clients.
On its own, this does not restrict access, because the default for
`network` permits requests from any source address. Configure `network`
as well, so that the agent accepts requests for this community only from
the addresses and prefixes you list.
```
Example:
```none
set service snmp community routers client 203.0.113.10
set service snmp community routers client 2001:db8::10
```
```{cfgcmd} set service snmp community \<name\> network \<prefix\>
**Configure an IPv4 or IPv6 prefix from which clients are allowed to
contact the router using the specified community.**
Repeat the command to allow multiple prefixes.
The default is `0.0.0.0/0` and `::/0`, which permits requests from any
source address.
```
Example:
```none
set service snmp community routers network 192.0.2.0/24
set service snmp community routers network 2001:db8:ffff:eeee::/64
```
### Trap notifications
VyOS pre-configures `linkUp` and `linkDown` notification events. Every
10 seconds, the SNMP agent evaluates the operational status of the
interfaces it collects data from and notifies the configured trap
targets of interface state changes.
```{cfgcmd} set service snmp trap-target \<address\> community \<community\>
Configure a destination host for SNMPv2c trap notifications and the
community string that the SNMP agent sends with them.
Repeat the command to configure multiple trap targets.
Each trap target requires a community. Otherwise, the commit fails.
```
Example:
```none
set service snmp trap-target 203.0.113.10 community routers
```
```{cfgcmd} set service snmp trap-target \<address\> port \<1-65535\>
Configure the destination port for traps that the SNMP agent sends to
the specified trap target.
The default is 162.
```
Example:
```none
set service snmp trap-target 203.0.113.10 port 10162
```
```{cfgcmd} set service snmp trap-source \<address\>
Configure the source IPv4 or IPv6 address that the router uses for SNMP
notifications.
```
Example:
```none
set service snmp trap-source 192.0.2.1
```
### SNMPv3
Access to the MIB over SNMPv3 is configured in three parts: views,
groups, and users. A view is a named list of MIB subtrees. A subtree is
written as an {abbr}`OID (object identifier)` and contains every object
whose OID starts with it. A group combines a view, an access
permission, and a security level. Each user belongs to a group, and the
group's view determines what that user may reach.
```{cfgcmd} set service snmp v3 engineid \<id\>
Configure the unique identifier of the SNMP agent (snmpEngineID, RFC
3411).
The value must contain an even number of lowercase hexadecimal
characters and be 2 to 36 characters long.
The ID must be configured when any user is defined under
`service snmp v3 user`. Otherwise, the commit fails.
Changing the ID after users are configured leaves their stored keys
tied to the previous value. Set their passwords again under
`service snmp v3 user`.
```
Example:
```none
set service snmp v3 engineid 000000000000000000000002
```
```{cfgcmd} set service snmp v3 group \<name\> view \<view\>
**Configure the MIB view that determines which objects members of the
specified group can access.**
Each group requires a view, and the view must already be defined under
`service snmp v3 view`. Otherwise, the commit fails.
```
Example:
```none
set service snmp v3 group default view default
```
```{cfgcmd} set service snmp v3 group \<name\> mode \<ro | rw\>
Configure the access permission granted to the specified group:
read-only (`ro`) or read-write (`rw`).
With `rw`, the SNMP agent uses the group's view for both read and write
access. The default is `ro`.
```
Example:
```none
set service snmp v3 group default mode ro
```
```{cfgcmd} set service snmp v3 group \<name\> seclevel \<noauth | auth | priv\>
Configure the security level required for the specified group.
- noauth: Messages are not authenticated and not encrypted.
- auth: Messages are authenticated but not encrypted.
- priv: Messages are authenticated and encrypted.
The default is `auth`.
```
Example:
```none
set service snmp v3 group default seclevel priv
```
```{cfgcmd} set service snmp v3 user \<name\> auth \<plaintext-password | encrypted-password\> \<value\>
**Configure the authentication key for the specified SNMPv3 user,
either as a plaintext password or as the derived key itself.**
A plaintext password must be at least 8 characters long. A key must use
lowercase hexadecimal characters (`0` to `9`, `a` to `f`).
Upon commit, VyOS derives a key from the plaintext password and the ID,
using the selected authentication protocol, and replaces
`plaintext-password` with the resulting `encrypted-password` in the
configuration.
Each user requires an authentication key. Otherwise, the commit fails.
```
Example:
```none
set service snmp v3 user vyos auth plaintext-password vyos12345678
```
```{cfgcmd} set service snmp v3 user \<name\> auth type \<md5 | sha\>
Configure the authentication protocol used by the specified user:
HMAC-MD5-96 (md5) or HMAC-SHA-96 (sha).
The default is `md5`.
VyOS derives both the authentication key and the privacy key of the
user using this protocol. Changing it after the keys are derived leaves
them tied to the previous protocol. Set the authentication and privacy
passwords again under `service snmp v3 user`.
```
Example:
```none
set service snmp v3 user vyos auth type sha
```
```{cfgcmd} set service snmp v3 user \<name\> privacy \<plaintext-password | encrypted-password\> \<value\>
Configure the privacy key for the specified SNMPv3 user, either as a
plaintext password or as the derived key itself.
A plaintext password must be at least 8 characters long. A key must use
lowercase hexadecimal characters (`0` to `9`, `a` to `f`).
Upon commit, VyOS derives a key from the plaintext password and the ID,
using the selected authentication protocol, and replaces
`plaintext-password` with the resulting `encrypted-password` in the
configuration.
Each user requires a privacy key. Otherwise, the commit fails.
```
Example:
```none
set service snmp v3 user vyos privacy plaintext-password vyos12345678
```
```{cfgcmd} set service snmp v3 user \<name\> privacy type \<des | aes\>
Configure the privacy protocol used by the specified user: CBC-DES
(des) or CFB128-AES-128 (aes).
The default is `des`.
```
Example:
```none
set service snmp v3 user vyos privacy type aes
```
```{cfgcmd} set service snmp v3 user \<name\> group \<group\>
**Assign the specified SNMPv3 user to a group.**
Groups are defined under `service snmp v3 group`.
Each user must be assigned a group. Otherwise, the commit fails.
```
Example:
```none
set service snmp v3 user vyos group default
```
```{cfgcmd} set service snmp v3 user \<name\> mode \<ro | rw\>
**Configure the access permission of the specified user: read-only
(`ro`) or read-write (`rw`).**
The value does not affect what the user may access. Access is
determined by the group the user belongs to, configured under
`service snmp v3 group`.
The default is `ro`.
```
Example:
```none
set service snmp v3 user vyos mode ro
```
```{cfgcmd} set service snmp v3 view \<name\> oid \<oid\>
**Configure an OID subtree included in the specified MIB view.**
Repeat the command to include multiple subtrees.
Each view requires at least one OID. Otherwise, the commit fails.
```
Example:
```none
set service snmp v3 view default oid 1
```
```{cfgcmd} set service snmp v3 view \<name\> oid \<oid\> exclude \<oid\>
**Exclude an OID subtree from the specified MIB view.**
Repeat the command to exclude multiple subtrees.
```
Example:
```none
set service snmp v3 view default oid 1 exclude 1.3.6.1.2.1.4
```
<!-- The command below is intentionally left undocumented. The CLI accepts
and stores the value, but the generated agent configuration omits it,
so the mask never reaches the running service. Verified on VyOS 1.5.0.
```{cfgcmd} set service snmp v3 view \<name\> oid \<oid\> mask \<hex-octets\>
**Define a bitmask indicating which numbers of the OID an object's OID
must match, instead of all of them, for the object to be in the view.**
```
-->
```{cfgcmd} set service snmp v3 trap-target \<address\>
**Configure a destination host (trap target) for SNMPv3
notifications.**
The SNMP agent authenticates and encrypts every notification it sends
to an SNMPv3 trap target.
Each SNMPv3 trap target requires an authentication key and a privacy
key. Otherwise, the commit fails.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10
```
```{cfgcmd} set service snmp v3 trap-target \<address\> port \<1-65535\>
**Configure the destination port for notifications that the SNMP agent
sends to the specified trap target.**
The default is 162.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10 port 10162
```
```{cfgcmd} set service snmp v3 trap-target \<address\> protocol \<udp | tcp\>
Configure the transport protocol for notifications that the SNMP agent
sends to the specified trap target.
The default is udp.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10 protocol udp
```
```{cfgcmd} set service snmp v3 trap-target \<address\> type \<inform | trap\>
Configure whether the SNMP agent sends notifications to the specified
trap target as acknowledged InformRequests (inform) or as unacknowledged
traps (trap).
The default is inform.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10 type trap
```
```{cfgcmd} set service snmp v3 trap-target \<address\> user \<name\>
**Configure the security name that the SNMP agent sends in
notifications to the specified trap target.**
The name does not have to match any user configured under
`service snmp v3 user`. Those users authorize incoming queries, not
outgoing notifications.
The agent sends the name in clear text. The receiver uses it to select
the keys for verifying and decrypting the notification. Configure the
receiver with this name and the keys from `auth` and `privacy` of this
trap target.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10 user vyos
```
```{cfgcmd} set service snmp v3 trap-target \<address\> auth \<plaintext-password | encrypted-password\> \<value\>
**Configure the authentication key for notifications that the SNMP
agent sends to the specified trap target, either as a plaintext password
or as the key itself.**
A plaintext password must be at least 8 characters long. A key must use
lowercase hexadecimal characters (`0` to `9`, `a` to `f`).
VyOS stores the value as entered and passes it to the SNMP agent
unchanged. A plaintext password therefore stays readable in the
configuration and in configuration backups. An encrypted password keeps
the password itself out of the configuration, but it is a working key.
Anyone who obtains it can send notifications in the router's name.
Exactly one of `plaintext-password` or `encrypted-password` must be
configured. Otherwise, the commit fails.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10 auth plaintext-password vyos12345678
```
```{cfgcmd} set service snmp v3 trap-target \<address\> auth type \<md5 | sha\>
Configure the authentication protocol for notifications that the SNMP
agent sends to the specified trap target: HMAC-MD5-96 (md5) or
HMAC-SHA-96 (sha).
The default is `md5`.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10 auth type sha
```
```{cfgcmd} set service snmp v3 trap-target \<address\> privacy \<plaintext-password | encrypted-password\> \<value\>
**Configure the privacy key for notifications that the SNMP agent sends
to the specified trap target, either as a plaintext password or as the
key itself.**
A plaintext password must be at least 8 characters long. A key must use
lowercase hexadecimal characters (`0` to `9`, `a` to `f`).
VyOS stores the value as entered and passes it to the SNMP agent
unchanged. A plaintext password therefore stays readable in the
configuration and in configuration backups. An encrypted password keeps
the password itself out of the configuration, but it is a working key.
Anyone who obtains it can decrypt captured notifications.
Exactly one of `plaintext-password` or `encrypted-password` must be
configured. Otherwise, the commit fails.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10 privacy plaintext-password vyos12345678
```
```{cfgcmd} set service snmp v3 trap-target \<address\> privacy type \<des | aes\>
Configure the privacy protocol for notifications that the SNMP agent
sends to the specified trap target: CBC-DES (des) or CFB128-AES-128
(aes).
The default is des.
```
Example:
```none
set service snmp v3 trap-target 203.0.113.10 privacy type aes
```
### MIB options
```{cfgcmd} set service snmp mib interface-max \<1-4294967295\>
**Limit how many interfaces the SNMP agent collects data from.**
By default, the agent collects data from all local interfaces.
Once a limit is set, the agent sorts the interfaces by their number and
collects data from that many, starting with the lowest.
```
Example:
```none
set service snmp mib interface-max 1000
```
```{cfgcmd} set service snmp mib interface \<prefix\>
**Restrict the interfaces the SNMP agent collects data from to those
whose names begin with the specified prefix.**
By default, the agent collects data from all local interfaces.
Accepted prefixes: `br`, `bond`, `dum`, `eth`, `gnv`, `macsec`, `peth`,
`sstpc`, `tun`, `veth`, `vti`, `vtun`, `vxlan`, `wg`, `wlan`, `wwan`.
Repeat the command to include multiple prefixes.
```
Example:
```none
set service snmp mib interface eth
set service snmp mib interface bond
```
```{cfgcmd} set service snmp oid-enable \<ip-forward | ip-route-table | ip-net-to-media-table | ip-net-to-physical-phys-address\>
Enable OID subtrees that community-based access excludes by default.
- ip-forward: ipForward (.1.3.6.1.2.1.4.24)
- ip-route-table: ipRouteTable (.1.3.6.1.2.1.4.21)
- ip-net-to-media-table: ipNetToMediaTable (.1.3.6.1.2.1.4.22)
- ip-net-to-physical-phys-address: ipNetToPhysicalPhysAddress (.1.3.6.1.2.1.4.35)
Repeat the command to enable multiple subtrees.
Enabling these subtrees may lead to system instability and high
resource consumption, for example, on systems with large routing
tables. VyOS prints a corresponding warning at commit time.
```
Example:
```none
set service snmp oid-enable ip-forward
```
### SMUX peer
{abbr}`SMUX (SNMP Multiplexing)`, defined in
[RFC 1227](https://datatracker.ietf.org/doc/html/rfc1227), is a legacy
protocol that lets a separate process, called a SMUX peer, answer
requests for part of the MIB on behalf of the SNMP agent.
```{cfgcmd} set service snmp smux-peer \<oid\>
**Register an OID subtree so that a SMUX peer can answer requests for
it.**
Repeat the command to register multiple subtrees.
```
Example:
```none
set service snmp smux-peer 1.3.6.1.4.1.3317.1.2.2
```
### Script extensions
The SNMP agent can run a custom script and report its output and exit
status through the extension MIB (NET-SNMP-EXTEND-MIB), shown in the
query below. Create the script, upload it to the router using
`scp your_script.sh vyos@your_router:/config/user-data`, and then
register it with the command below.
```{cfgcmd} set service snmp script-extensions extension-name \<name\> script \<script\>
**Configure a script that the SNMP agent runs under the specified
name.**
The agent reports the script's output and exit status to clients. It
runs the script when a client asks for either of them.
Specify either a filename, which VyOS looks for in `/config/user-data/`,
or an absolute path to a script kept elsewhere. Names and paths may
contain lowercase letters, digits, and the characters `.`, `-`, `_`,
and paths may also contain `/`.
Every configured name must point to a script path. Otherwise, the
commit fails.
VyOS does not require the file to exist yet. If it is missing at commit
time, VyOS prints a warning and commits anyway. If it is present, VyOS
makes it executable.
```
Example:
```none
set service snmp script-extensions extension-name my-extension script your_script.sh
```
The script's output and exit status can then be queried:
```none
vyos@vyos# snmpwalk -v2c -c routers 127.0.0.1 nsExtendOutput1Table
NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."my-extension" = STRING: hello
NET-SNMP-EXTEND-MIB::nsExtendOutputFull."my-extension" = STRING: hello
NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."my-extension" = INTEGER: 1
NET-SNMP-EXTEND-MIB::nsExtendResult."my-extension" = INTEGER: 0
```
## Operation
```{opcmd} show snmp community \<community\>
Show the status of the SNMP agent on the local system, queried over
SNMPv1 with the specified community string.
```
```{opcmd} show snmp community \<community\> host \<host\>
Show the status of the SNMP agent on the specified remote host, queried
over SNMPv1 with the specified community string.
```
```{opcmd} show snmp mib ifmib
Show the IF-MIB `ifAlias`, `ifDescr`, and `ifIndex` values for all
interfaces.
```
```{opcmd} show snmp mib ifmib \<if-alias | if-descr | if-index\> \<interface\>
Show the IF-MIB `ifAlias`, `ifDescr`, or `ifIndex` value for the
specified interface.
```
```{opcmd} show snmp v3
Show the configured SNMPv3 groups, trap targets, users, and views.
```
```{opcmd} show snmp v3 group
Show the configured SNMPv3 groups.
```
```{opcmd} show snmp v3 trap-target
Show the configured SNMPv3 trap targets.
```
```{opcmd} show snmp v3 user
Show the configured SNMPv3 users.
```
```{opcmd} show snmp v3 view
Show the configured SNMPv3 views.
```
```{opcmd} show snmp v3 certificates
Show SNMP {abbr}`TSM (Transport Security Model)` certificates from
`/etc/snmp/tls/certs/`.
```
```{opcmd} show log snmp
Show the SNMP agent log for the current boot.
```
```{opcmd} monitor log snmp
Show the SNMP agent log for the current boot and follow new entries in
real time.
```
```{opcmd} restart snmp
Restart the SNMP agent. The command fails when SNMP is not configured or
while a commit is in progress.
```
## VyOS MIBs
All SNMP MIBs shipped with a VyOS image are located in
`/usr/share/snmp/mibs/`. An SNMP client uses these files to show
symbolic object names such as `SNMPv2-MIB::sysDescr.0` instead of
numeric OIDs. Copy them to the client to get the same names there, with
SCP once the SSH service is configured:
```none
scp -r vyos@your_router:/usr/share/snmp/mibs /your_folder/mibs
```
(solarwinds)=
## SolarWinds Orion
SolarWinds Orion is a network monitoring and management platform. To
manage the configuration of a device, it opens a command-line session
and runs commands on it. Since every system has its own commands, Orion
needs a device template that maps its actions, such as retrieving the
configuration or rebooting, to that system's commands.
Orion selects the template by the system object identifier that a device
reports in the SNMPv2-MIB `sysObjectID` object. A VyOS router always
reports `1.3.6.1.4.1.44641`, so a template with this value applies to
every VyOS device.
To add the template, create a file named
`VyOS-1.3.6.1.4.1.44641.ConfigMgmt-Commands` with the following content
and then import it in Orion using Device Templates Management:
```none
<Configuration-Management Device="VyOS" SystemOID="1.3.6.1.4.1.44641">
<Commands>
<Command Name="Reset" Value="set terminal width 0${CRLF}set terminal length 0"/>
<Command Name="Reboot" Value="reboot${CRLF}Yes"/>
<Command Name="EnterConfigMode" Value="configure"/>
<Command Name="ExitConfigMode" Value="commit${CRLF}exit"/>
<Command Name="DownloadConfig" Value="show configuration commands"/>
<Command Name="SaveConfig" Value="commit${CRLF}save"/>
<Command Name="Version" Value="show version"/>
<Command Name="MenuBased" Value="False"/>
<Command Name="VirtualPrompt" Value=":~"/>
</Commands>
</Configuration-Management>
```
## Examples
### SNMPv2c
```none
# Define a community
set service snmp community routers authorization 'ro'
# Allow monitoring access only from these networks. For specific
# addresses, use /32 and /128 prefixes.
set service snmp community routers network '192.0.2.0/24'
set service snmp community routers network '2001:db8:ffff:eeee::/64'
# Define optional router information
set service snmp location 'UK, London'
set service snmp contact 'admin@example.com'
# Send trap notifications to this host
set service snmp trap-target 203.0.113.10 community 'routers'
# Listen only on specific IP addresses (port defaults to 161)
set service snmp listen-address 192.0.2.1 port 161
set service snmp listen-address 2001:db8::1
```
(snmp-v3-example)=
### SNMPv3
The following example lets the SNMP agent listen only on IP address
192.0.2.1 and configures a new user named "vyos" with password
"vyos12345678", using `sha` for authentication and `aes` for privacy.
```none
set service snmp listen-address 192.0.2.1
set service snmp location 'VyOS Datacenter'
set service snmp v3 engineid '000000000000000000000002'
set service snmp v3 group default mode 'ro'
set service snmp v3 group default view 'default'
set service snmp v3 user vyos auth plaintext-password 'vyos12345678'
set service snmp v3 user vyos auth type 'sha'
set service snmp v3 user vyos group 'default'
set service snmp v3 user vyos privacy plaintext-password 'vyos12345678'
set service snmp v3 user vyos privacy type 'aes'
set service snmp v3 view default oid 1
```
After commit, VyOS replaces the plaintext passwords with the derived
keys. The resulting configuration looks like:
```none
vyos@vyos# show service snmp
listen-address 192.0.2.1 {
}
location "VyOS Datacenter"
v3 {
engineid 000000000000000000000002
group default {
mode ro
view default
}
user vyos {
auth {
encrypted-password 4e52fe55fd011c9c51ae2c65f4b78ca93dcafdfe
type sha
}
group default
privacy {
encrypted-password 4e52fe55fd011c9c51ae2c65f4b78ca93dcafdfe
type aes
}
}
view default {
oid 1 {
}
}
}
```
Test the configuration on the router itself or from another host by
running the following command:
% stop_vyoslinter
`snmpwalk -v 3 -u vyos -a SHA -A vyos12345678 -x AES -X vyos12345678 -l authPriv 192.0.2.1 .1`
% start_vyoslinter
|