[Dnsmasq] IP アドレスがリース・解放された時にログを出力する

概要

Dnsmasq の DHCP サーバーで IP アドレスがリース・解放された時にログを出力する。

環境

  • Debian 9 “stretch”
  • Dnsmasq 2.76

手順

スクリプトの作成

ホームディレクトリに dnsmasq-dhcp-script.sh の名前で以下の内容のスクリプトを作成。

#!/bin/bash

LOG="/home/ryo/dhcp.log"
DATE=date +"%Y-%m-%d %H:%M:%S" 

echo "$DATE $2 $3 $4 ($1)" >> $LOG

スクリプトが呼び出される時の引数の内容は以下の通り。

$1 はアクションに応じて 'add' 'del' 'old' のどれか。
$2 は MAC アドレス
$3 は IP アドレス
$4 はホスト名

/etc/dnsmasq.conf の設定

以下の1行を追加。

dhcp-script=/home/ryo/dnsmasq-dhcp-script.sh
スクリプトは必ずフルパスで書く。
実行ユーザーは root。

Dnsmasq の再起動

$ sudo systemctl restart dnsmasq

実行例

$ cat/home/ryo/dhcp.log
2018-03-16 13:39:48 xx:xx:xx:xx:xx:xx 192.168.1.121 Galaxy-Note8 (old)
2018-03-16 13:40:06 xx:xx:xx:xx:xx:xx 192.168.1.101  (old)
2018-03-16 13:40:06 xx:xx:xx:xx:xx:xx 192.168.1.109 Google-Home (old)
2018-03-16 13:42:10 xx:xx:xx:xx:xx:xx 192.168.1.121 Galaxy-Note8 (old)
2018-03-16 13:42:12 xx:xx:xx:xx:xx:xx 192.168.1.121 Galaxy-Note8 (old)
2018-03-16 14:04:21 xx:xx:xx:xx:xx:xx 192.168.1.140 GAINSPAN_000000 (old)
2018-03-16 14:06:07 xx:xx:xx:xx:xx:xx 192.168.1.112 bravia804077653xxxxxx (add)
2018-03-16 14:27:50 xx:xx:xx:xx:xx:xx 192.168.1.191 Chromecast (old)
2018-03-16 14:44:21 xx:xx:xx:xx:xx:xx 192.168.1.140 GAINSPAN_000000 (old)

関連記事

[Dnsmasq] DHCP サーバーを設置する
概要Dnsmasq を使って、DHCP サーバーを設置する。環境Debian 9 “stretch”Dnsmasq 2.76手順Dnsmasq のインストール# apt install dnsmasq/et...
[Dnsmasq] 家庭内 LAN 用にローカル DNS サーバーを設置する
概要Dnsmasq を使って、家庭内 LAN 用にローカル DNS サーバーを設置する。環境Debian 9Dnsmasq 2.76ローカルのドメインは .local とする手順Dnsmasq のインストール...

コメント

タイトルとURLをコピーしました