アーカイブ

‘rsyslog’ カテゴリーのアーカイブ

rsyslogでiptablesログの振り分け設定

2015 年 7 月 3 日 Comments off
今までは、iptablesのログは、全部一緒にmessagesログに書き込む設定にしていた。というかデフォルト設定のままであったのでこのような状態でした。
下記のような感じです。
May 17 03:31:48 www16071ue chkrootkit: Checking `chkutmp'... chkutmp: nothing deleted
May 17 03:31:48 www16071ue chkrootkit: Checking `OSX_RSPLUG'... not infected
May 17 03:33:14 www16071ue kernel: [IPTABLES INPUT] : IN=eth0 OUT= MAC=XX:XX:05:01:60:71:XX: ...
May 17 03:34:29 www16071ue kernel: ip_tables: (C) 2000-2006 Netfilter Core Team
May 17 03:34:31 www16071ue kernel: nf_conntrack version 0.5.0 (7970 buckets, 31880 max)
May 17 03:34:33 www16071ue freshclam[6949]: ClamAV update process started at Sun May 17 03:34:33 2015
May 17 03:34:33 www16071ue freshclam[6949]: main.cld is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
May 17 03:35:37 www16071ue freshclam[6949]: Downloading daily-20469.cdiff [100%]
May 17 03:35:37 www16071ue freshclam[6949]: Downloading daily-20470.cdiff [100%]
chkrootのログやiptablesのログ(input)やfreshclam(clamAV)の定義体のダウンロードログなどごちゃごちゃです。
特にiptablesのログは、アクセス量とともに膨大なものとなるのでやはり別にしたほうが後で解析するときに楽ですのでiptablesログを振り分けてみようと思います。
vi /etc/rsyslog.confの中の
#### RULES ####

の部分以下に下記を追記、および編集します。

 
#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 /dev/console
kern.info                                               /var/log/iptables.log

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
#*.info;mail.none;authpriv.none;cron.none                /var/log/messages
*.info;kern.!info;mail.none;authpriv.none;cron.none      /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog
kern.infoを別のファイル(/var/log/iptables.log)に書き込ませる設定
これは、iptablesのログは、カーネル情報(kern.info)なのでこのように記述する。
また、今までmessagesに書き込んでいたこのカーネル情報(kern.info)を除外するのでinfoの前に!をつける。
カーネル以外のinfoは、このmessagesに書き込まれる。
これでrsyslogを再起動でOKです。
[root@www16071ue log]# /etc/init.d/rsyslog restart
システムロガーを停止中:                                    [  OK  ]
システムロガーを起動中:                                    [  OK  ]
これで/var/log以下にiptables.logが作成されていれば大丈夫です。
また、messagesにiptablesのログが書き込まれていなければOKです。
[root@www16071ue ~]# ls -la /var/log/iptables.log
-rw------- 1 root root 164523  7月  1 12:24 2015 /var/log/iptables.log
また、iptablesのログを振り分けてログ出力の接頭語でログファイルを分けると見やすくなるので下記のように変えてみました。
:msg, contains, "IPTABLES FRAGMENT"       -/var/log/iptables-fragmentlog
:msg, contains, "IPTABLES DENY_COUNTRY"         -/var/log/iptables-deny_country.log
:msg, contains, "IPTABLES INPUT"                -/var/log/iptables-input.log
:msg, contains, "IPTABLES PINGDEATH"            -/var/log/iptables-pingdeath.log
この辺の接頭語等は、各サーバで設定しているiptablesルールで変わりますのでご了承ください。
なお、messagesに書き込まれているところのkernel:の後の記述と一致すればいいのでログを確認してください。
下記ログであれば「 IPTABLES INPUT 」です。
May 17 03:33:14 www16071ue kernel: [IPTABLES INPUT] : IN=eth0 OUT= MAC=XX:XX:05:01:60:71:XX: …
iptables等振り分けの参考にさせていただいたサイトを紹介しておきます。
rsyslogを利用したログファイル作成と、logrotateを利用したログのローテーション
追記(20150722)
*.info;kern.!info;mail.none;authpriv.none;cron.none /var/log/messages
とすると他のkern.info情報も取りこぼしてしまうことが判明したため(clamdなど)
*.info;kern.info;mail.none;authpriv.none;cron.none /var/log/messages
とデフォルト設定に戻しました。
追加でiptablesログを出すようにしました。
iptablesログだけmessagesから省く仕様は、勉強して考えます(–;
カテゴリー: iptables, Linux, rsyslog, 不正アクセス タグ: ,