# 03-修改設定檔存取控制 NetSNMP

**3.1 設定檔的路徑**

snmpd.conf 主要是用來設定 agent 的運作和管理，而 NetSNMP 預設會在以下幾個路徑去尋找 snmpd.conf：/etc/snmp、 /usr/share/snmp、/usr/lib/snmp 和 $HOME/.snmp。但是在 ubuntu 10.04 中，預設的 snmp 資料夾放置在 /usr/local/share/ 中，所以必須把撰寫好的設定檔放至 /usr/local/share/snmp 中讓 NetSNMP 可以搜尋到。所以我們必須依序下列指令將設定檔放到適當的位置：

\#cd net-snmp-5.5

進入 net-snmp-5.5 後，此檔案資料夾中有一個設定檔的範例檔 EXAMPLE.conf，所以此時我們只需使用此範例檔並且將檔案放置適當的位置，並將範例檔檔名修改成 snmpd.conf 即可開始設定管理資訊。

\[net-snmp-5.5]#sudo cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf

**3.2 Agent behavior**

agentaddress \[\<transport-specifier>:]\<transport-address>\[,...]

定義要 listen 的 IP 位址和通訊埠。

基本上都會設定 listen 本地端 IP 位址以及 localhost，讓本地端主機和外部主機都可以由此 IP 獲得服務，而 NetSNMP 服務預設的通訊埠(port)為161，如圖 8。

<figure><img src="/files/eYl5nKVmmE5QByeCtvaV" alt=""><figcaption><p>圖 8 Agent behavior設定</p></figcaption></figure>

**3.3 Access control**

設定一：

rocommunity COMMUNITY

rwcommunity COMMUNITY

此處實作 SNMPv1 或 SNMPv2c 群組中的權限設定。rocommunity 定義只可讀取 ( snmpget 和 snmpgetnext)，rwcommunity 定義可讀取 ( snmpget 和 snmpgetnext) 也可以寫入 (snmpset)。

將 rocommunity 設定成 public，並且將 rwcommunity 設定成 private，如圖 9。

<figure><img src="/files/QpOh8TQyebcwZ2WnxzaA" alt=""><figcaption><p>圖 9定義 access control community name</p></figcaption></figure>

設定二：

如圖 10，在snmpd.conf 中定義 security name 與其相對應的 community name 和主要的 IP 位址來源。

<figure><img src="/files/w9QxR5mwHp2qojkki7i5" alt=""><figcaption><p>圖 10 定義 security name 和相對應的 IP 位址</p></figcaption></figure>

**3.4 System information**

此項目主要定義系統相關資訊，如圖 11。

設定一：System Group

sysLocation STRING

sysContact STRING

sysName STRING

將系統位置、聯絡人，系統名稱 (sysLocation.0、sysContact.0和sysName.0) 分別設定相關資訊。

sysServices NUMBER

設定sysServices.0，預設值為72。

<figure><img src="/files/VMjsyi6L2U7f83vYsBXT" alt=""><figcaption><p>圖 11設定 System Group</p></figcaption></figure>

設定二：Process Monitoring

proc NAME \[MAX \[MIN]]

監視本機端的 process，並使用名稱 (在/bin/ps –e中的程序名稱) 來定義。如果定義監視的 process 名稱少於 MIN 或大於 MAX，prErrorFlag 都會被設定為1，並且可以將相對應的訊息設定在 prErrMessage 中，但並不會自動觸發trap。假如 MIN 以及 MAX 沒有被定義，代表此程序至少要有一個；假如只定義 MAX，則 MIN 的預設值為0。

相對應的設定如圖 12。

<figure><img src="/files/ZsdjjGU2FZT70w2natbc" alt=""><figcaption><p>圖 12 Process Monitoring 設定</p></figcaption></figure>

設定三：Disk Monitoring

disk PATH \[ MINSPACE | MINPERCENT% ]

監視使用多少的磁碟資源，以及可用的磁碟空間。MINSPACE可使用Kb或者北分比(%)表示，分母為磁碟總容量。如果低於定義的MINSPACE，dskErrorFlag會被設定為1，以及相對應的錯誤訊息可設定在 dskErrorMsg 中。

includeAllDisks MINPERCENT%

配置監視所有磁碟系統的百分比。

相對應的設定如圖 13

<figure><img src="/files/cQKut4k1QVrFDE6cIUJR" alt=""><figcaption><p>圖 13 Disk Monitoring 設定</p></figcaption></figure>

設定四：System Load

load MAX1 \[MAX5 \[MAX15]]

查看 local system 的平均負載，可設定平均每 1min、5mins 或 15mins 統計一次。如超過設定的負載，laErrorFlag 會被設成1，以及相對應的錯誤訊息可設定在 laErrMessage 中。

相對應的設定值如圖 14。

<figure><img src="/files/CCv37iU8ew7v87tcLWxJ" alt=""><figcaption><p>圖 14 System Load 設定</p></figcaption></figure>

**3.5 Active Monitoring**

trapsink HOST \[COMMUNITY \[PORT]]

trap2sink HOST \[COMMUNITY \[PORT]]

informsink HOST \[COMMUNITY \[PORT]]

定義 snmptrap 接收者的位址，可分別為 SNMPv1 TRAPs、SNMPv2c TRAP2s 或 SNMPv2 INFORM。

作相對應的設定如圖 15，開啟接收 snmptrap。

<figure><img src="/files/o8lHkWR1BCIVeaqpRnJg" alt=""><figcaption><p>圖 15 Notification Handling 設定</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://netsnmp-install.netdpi.net/03-configure-netsnm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
