LoginSignup
21
19

More than 5 years have passed since last update.

snmptrapd.conf(v1,v2c,v3,inform含む)

Last updated at Posted at 2016-06-24

いろんなサイト見ても、いまいちパッとしないsnmptrapd.confの書き方。

とりあえず、以下の内容で、やりたいことができたので、メモっておく。

# 受信ポート設定
snmpTrapdAddr udp:162
snmpTrapdAddr udp6:10162

# createUserトークンがあると、snmptrapd起動時に、
# /var/lib/net-snmp/snmptrapd.confという別のコンフィグに、
# ユーザーが追加される。
# -eは、エンジンIDを自分で指定してユーザーを作るとき、使用する。
# 一度でも追加しておけば、createUserの部分を削除しても、
# 以降も問題なくトラップを受信できる。
# ・・・。作ったユーザーは、どうやって消すんだろ?
#createUser test1 MD5 authp1234 DES encp1234
#createUser test2 SHA authp1234 DES encp1234
#createUser test3 MD5 authp1234
#createUser test4 SHA authp1234
#createUser test5
createUser -e 0x8000000001020304 test1 MD5 authp1234 DES encp1234
createUser -e 0x8000000001020304 test2 SHA authp1234 DES encp1234
createUser -e 0x8000000001020304 test3 MD5 authp1234
createUser -e 0x8000000001020304 test4 SHA authp1234
createUser -e 0x8000000001020304 test5

# v1, v2c, v2c inform用の設定。
# log,execute,netは、それぞれ、syslog出力、コマンド実行、転送を意味する。
# ログに出力したいだけなら、logだけでも良い。
authCommunity log,execute,net public

# v3, v3 inform用の設定。
# authCommunityと、だいたい同じ。
# 末尾に、createUserでどの認証、暗号化をセットしたかによって、
# 末尾の内容が異なる模様(違ったら突っ込みください)
# noAuthNoPrivなら、noauth
# authNoPrivなら、何もなし
# authPrivなら、priv
authUser log,execute,net test1 priv
authUser log,execute,net test2 priv
authUser log,execute,net test3
authUser log,execute,net test4
authUser log,execute,net test5 noauth

コンフィグを変更したら、snmptrapdを再起動。
snmptrapコマンドで、上記設定でちゃんと受信できているか確認する。


[root@localhost ~]# /usr/bin/snmptrap -v 1 -c 'public' -t 2 -r 1 '192.168.0.1:162' .1.3.6.1.4.1.8072.99999 localhost 6 1 '' .1.3.6.1.4.1.8072.99999.1 s '123'
[root@localhost ~]# /usr/bin/snmptrap -v 2c -c public -t 2 -r 1 '192.168.0.1:162' '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s '123'
[root@localhost ~]# /usr/bin/snmpinform -v 2c -c public -t 2 -r 1 '192.168.0.1:162' '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s '123'
[root@localhost ~]# /usr/bin/snmptrap -e 0x8000000001020304 -v 3 -l authPriv -u 'test1' -a 'MD5' -A 'authp1234' -x 'DES' -X 'encp1234' -t 2 -r 1 '192.168.0.1:162' '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s '123'
[root@localhost ~]# /usr/bin/snmpinform -v 3 -l authPriv -u 'test1' -a 'MD5' -A 'authp1234' -x 'DES' -X 'encp1234' -t 2 -r 1 '192.168.0.1:162' '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s '123'

以下シスログの内容。(snmptrapでgrepしてます)
ちゃんと受信できた。


Jun 24 13:14:55 localhost snmptrapd[1299]: 2016-06-24 13:14:55 localhost.localdomain [127.0.0.1] (via UDP: [192.168.0.1]:34166->[192.168.0.1]) TRAP, SNMP v1, community public
Jun 24 13:15:40 localhost snmptrapd[1299]: 2016-06-24 13:15:40 localhost.localdomain [UDP: [192.168.0.1]:45924->[192.168.0.1]]:
Jun 24 13:15:54 localhost snmptrapd[1299]: 2016-06-24 13:15:54 localhost.localdomain [UDP: [192.168.0.1]:38342->[192.168.0.1]]:
Jun 24 13:16:34 localhost snmptrapd[1299]: 2016-06-24 13:16:34 localhost.localdomain [UDP: [192.168.0.1]:50987->[192.168.0.1]]:
Jun 24 13:16:52 localhost snmptrapd[1299]: 2016-06-24 13:16:52 localhost.localdomain [UDP: [192.168.0.1]:57580->[192.168.0.1]]:

シスログが出ない場合は、起動オプションとpsの内容を確認する。
起動オプションが以下のようになっていれば、出るはず。


/usr/sbin/snmptrapd -Lsd -p /var/run/snmptrapd.pid

これでも出ない場合は、syslogが動いてないとか、別の理由であり、
多岐にわたるので、頑張ってトラブルシュートしてください。

以下、/var/lib/net-snmp/snmptrapd.confの内容。
createUserによって、ユーザーが追加されているのを確認できる。

[root@localhost ~]# cat /var/lib/net-snmp/snmptrapd.conf
#
# net-snmp (or ucd-snmp) persistent data file.
#
############################################################################
# STOP STOP STOP STOP STOP STOP STOP STOP STOP
#
#          **** DO NOT EDIT THIS FILE ****
#
# STOP STOP STOP STOP STOP STOP STOP STOP STOP
############################################################################
#
# DO NOT STORE CONFIGURATION ENTRIES HERE.
# Please save normal configuration tokens for snmptrapd in SNMPCONFPATH/snmptrapd.conf.
# Only "createUser" tokens should be placed here by snmptrapd administrators.
# (Did I mention: do not edit this file?)
#















usmUser 1 3 0x8000000001020304 0x746573743100 0x746573743100 NULL .1.3.6.1.6.3.10.1.1.2 0x4cc75cd1c27dad6e5b93874fb1f0ddf3 .1.3.6.1.6.3.10.1.2.2 0x7afbd34014756fc5f1c708a8526dfcb8 0x
usmUser 1 3 0x8000000001020304 0x746573743200 0x746573743200 NULL .1.3.6.1.6.3.10.1.1.3 0x91795f9499195a34e2a29ca18ca5f0837c62cf25 .1.3.6.1.6.3.10.1.2.2 0x7d8a94662d687b880a389d1ea5ff6ed5 0x
usmUser 1 3 0x8000000001020304 0x746573743300 0x746573743300 NULL .1.3.6.1.6.3.10.1.1.2 0x4cc75cd1c27dad6e5b93874fb1f0ddf3 .1.3.6.1.6.3.10.1.2.1 0x 0x
usmUser 1 3 0x8000000001020304 0x746573743400 0x746573743400 NULL .1.3.6.1.6.3.10.1.1.3 0x91795f9499195a34e2a29ca18ca5f0837c62cf25 .1.3.6.1.6.3.10.1.2.1 0x 0x
usmUser 1 3 0x8000000001020304 0x746573743500 0x746573743500 NULL .1.3.6.1.6.3.10.1.1.1 0x .1.3.6.1.6.3.10.1.2.1 0x 0x
usmUser 1 3 0x8000000001020304 0x617574682d7573657200 0x617574682d7573657200 NULL .1.3.6.1.6.3.10.1.1.3 0xca2b5f4a4aaba35006966dbdb5429fcb17b44e9d .1.3.6.1.6.3.10.1.2.1 0x 0x
usmUser 1 3 0x8000000001020304 0x707269762d7573657200 0x707269762d7573657200 NULL .1.3.6.1.6.3.10.1.1.3 0xca2b5f4a4aaba35006966dbdb5429fcb17b44e9d .1.3.6.1.6.3.10.1.2.4 0xca2b5f4a4aaba35006966dbdb5429fcb 0x
usmUser 1 3 0x8000000001020305 0x746573743100 0x746573743100 NULL .1.3.6.1.6.3.10.1.1.2 0x18e71b4052de9202ea1c025b2c5e7237 .1.3.6.1.6.3.10.1.2.2 0x42ac93351431dd396daaca144da48f97 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x746573743100 0x746573743100 NULL .1.3.6.1.6.3.10.1.1.2 0xbab6d8f762d016bf1e44824f59ee88ff .1.3.6.1.6.3.10.1.2.2 0xe76cdc7a68736305a96e8d81221d0848 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x746573743200 0x746573743200 NULL .1.3.6.1.6.3.10.1.1.3 0x31effd5e4231ff92808818b37c95ca189f70697c .1.3.6.1.6.3.10.1.2.2 0x3199e071f576ab4db6d439e3ce4938f6 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x746573743300 0x746573743300 NULL .1.3.6.1.6.3.10.1.1.2 0xbab6d8f762d016bf1e44824f59ee88ff .1.3.6.1.6.3.10.1.2.1 0x 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x746573743400 0x746573743400 NULL .1.3.6.1.6.3.10.1.1.3 0x31effd5e4231ff92808818b37c95ca189f70697c .1.3.6.1.6.3.10.1.2.1 0x 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x746573743500 0x746573743500 NULL .1.3.6.1.6.3.10.1.1.1 0x .1.3.6.1.6.3.10.1.2.1 0x 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x65786d643564657300 0x65786d643564657300 NULL .1.3.6.1.6.3.10.1.1.2 0xbab6d8f762d016bf1e44824f59ee88ff .1.3.6.1.6.3.10.1.2.2 0xe76cdc7a68736305a96e8d81221d0848 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x657873686164657300 0x657873686164657300 NULL .1.3.6.1.6.3.10.1.1.3 0x31effd5e4231ff92808818b37c95ca189f70697c .1.3.6.1.6.3.10.1.2.2 0x3199e071f576ab4db6d439e3ce4938f6 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x686f6765686f676500 0x686f6765686f676500 NULL .1.3.6.1.6.3.10.1.1.3 0x396a33f2fe8bbacb39de453cd64f0560fea5b9d7 .1.3.6.1.6.3.10.1.2.4 0x396a33f2fe8bbacb39de453cd64f0560 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x6578617574686d643500 0x6578617574686d643500 NULL .1.3.6.1.6.3.10.1.1.2 0xbab6d8f762d016bf1e44824f59ee88ff .1.3.6.1.6.3.10.1.2.1 0x 0x
usmUser 1 3 0x80001f8880f3f1b00b34ab285600000000 0x65786175746873686100 0x65786175746873686100 NULL .1.3.6.1.6.3.10.1.1.3 0x31effd5e4231ff92808818b37c95ca189f70697c .1.3.6.1.6.3.10.1.2.1 0x 0x
engineBoots 112
oldEngineID 0x80001f8880f3f1b00b34ab285600000000
[root@localhost ~]#
[root@localhost ~]#

ここに内容がある限り、/etc/snmp/snmptrapd.confの内容から、createUserを消してしまっても、
問題なくトラップを受信できる。

/etc/snmp/snmptrapd.confの中身には、認証キー、暗号キーどちらも平文で書かれているので、
ユーザーが追加できたことを確認したら、/etc/snmp/snmptrapd.confのほうは
消したほうが良いのかもしれない。

あと、oldEngineIDに書いてあるエンジンIDの記述は、無効?になっている模様。
-eを未指定で作成した場合は、やはりv3 trapは受けられない、、、で良い、、、(自信ないです。複雑すぎる・・・)

以下createUserを消した後の/etc/snmp/snmptrapd.conf

snmpTrapdAddr udp:162
snmpTrapdAddr udp6:10162

authCommunity log,execute,net public

authUser log,execute,net test1 priv
authUser log,execute,net test2 priv
authUser log,execute,net test3
authUser log,execute,net test4
authUser log,execute,net test5 noauth

21
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
19