1. 檢查是否有 check_dns 檢查指令
# locate check_dns
/usr/lib64/nagios/plugins/check_dns
2. 檢查一下,check_dns 須要加入的參數
# /usr/lib64/nagios/plugins/check_dns -h
Options:
-h, –help
Print detailed help screen
-V, –version
Print version information
–extra-opts=[section][@file]
Read options from an ini file. See http://nagiosplugins.org/extra-opts
for usage and examples.
-H, –hostname=HOST
The name or address you want to query
-s, –server=HOST
Optional DNS server you want to use for the lookup
-a, –expected-address=IP-ADDRESS|HOST
Optional IP-ADDRESS you expect the DNS server to return. HOST must end with
a dot (.). This option can be repeated multiple times (Returns OK if any
value match). If multiple addresses are returned at once, you have to match
the whole string of addresses separated with commas (sorted alphabetically).
-A, –expect-authority
Optionally expect the DNS server to be authoritative for the lookup
-w, –warning=seconds
Return warning if elapsed time exceeds value. Default off
-c, –critical=seconds
Return critical if elapsed time exceeds value. Default off
-t, –timeout=INTEGER
Seconds before connection times out (default: 10)[@more@]3. 測試一下
# /usr/lib64/nagios/plugins/check_dns -H www.ilc.edu.tw -s DNS’IP
DNS OK: 0.012 seconds response time. www.ilc.edu.tw returns 140.111.66.96|time=0.012217s;;;0.000000
4. 在 /etc/nagios/objects/commands.cfg 檔案加入
# ‘check_dns’ command definition
define command{
command_name check_dns
command_line $USER1$/check_dns -H $ARG1$ -s $HOSTADDRESS$
}
5. 在要偵測的 DNS 主機加入 dns.test.ilc.edu.tw 就是要偵測的 DNS 主機
# vim /etc/nagios/servers/dns.cfg
define service{
use generic-service ; Name of service template to use
host_name dns.test.ilc.edu.tw
service_description DNS
check_command check_dns!www.ilc.edu.tw
notifications_enabled 1
}
重新啟動 Nagios
# service nagios restart
Running configuration check…done.
Stopping nagios: .done.
Starting nagios: done.
如果沒有出現錯誤訊息,代表設定成功