Ubuntuでufwのログを/var/log/syslogに出力させない方法です。
これにより「/var/log/syslog」の内容がufwのログで埋もれてしまい読みにくくなることを防ぐことが出来ます。
rsyslog設定ファイルの編集
Ubuntuの初期設定では、ufwのログは「/var/log/syslog」と「/var/log/ufw.log」に出力されますが、「rsyslog」の設定を変更することで「/var/log/syslog」に出力されないようにすることができます。
ufwのログに関する設定は、「/etc/rsyslog.d/20-ufw.conf」なのでこちらを編集していきます。
$ cd /etc/rsyslog.d/ $ sudo cp -p 20-ufw.conf 20-ufw.conf_$(date "+%Y%m%d_%H%M%S") $ sudo vi 20-ufw.conf
編集内容
最後の行に設定されている「#& stop」の行頭にある「#」を削除して設定を有効化します。
編集前は以下のような設定になっています。
# Log kernel generated UFW log messages to file :msg,contains,"[UFW " /var/log/ufw.log # Uncomment the following to stop logging anything that matches the last rule. # Doing this will stop logging kernel generated UFW log messages to the file # normally containing kern.* messages (eg, /var/log/kern.log) #& stop
編集後のファイル内容は以下のようになります。
# Log kernel generated UFW log messages to file
:msg,contains,"[UFW " /var/log/ufw.log
# Uncomment the following to stop logging anything that matches the last rule.
# Doing this will stop logging kernel generated UFW log messages to the file
# normally containing kern.* messages (eg, /var/log/kern.log)
& stop
設定の説明
「/etc/rsyslog.d/20-ufw.conf」ではrsyslogのログ(メッセージ)のフィルタリングを行っています。
「:msg,contains,"[UFW " /var/log/ufw.log」は、rsyslogのログに「[UFW 」が含まれている場合「/var/log/ufw.log」に出力する設定です。
- :msg, rsyslogのログ全体を表している
- contains, 指定された文字列が含まれているかを評価
「& stop」は、以降のルールによる処理を停止するという設定になります。
そのため、 [UFW が含まれるメッセージは「/var/log/ufw.log」に出力され、それ以外のファイルにはログが出力されないようになります。
設定反映
設定を反映させるためにrsyslogを再起動します。
$ sudo systemctl restart rsyslog
動作確認
ufwのログが「/var/log/ufw.log」にだけ出力されて、「/var/log/syslog」に出力されていないことを確認してください。
コメント