2007年10月25日木曜日

syslog サーバーの設定

syslog サーバーの設定

環境:Linux(Fedora Core)
対象:syslog サービス

最近、韓国からのサーバーアタックが尋常じゃないほど多い(1日平均、30件ぐらい。)ので、韓国経由のパケットはDROP(応答も返さない)する設定にしました。。

それでも、フィイアーウォールには、アタックの検出が発生しています。
そこで、syslog サーバーにlogを保存して、攻撃元を管理することにしました。

1.syslogサービスの設定

ファイアーウォール側の設定は、サーバーを指定するだけなので・・・
ここでは、syslogサーバーの設定を記述します。

受けとるだけなら簡単で、以下のコマンドでOKなのですが。
# /sbin/syslogd -r

これだとsyslog のサービスを毎回再起動しなきゃいけないので、
設定ファイルに設定する方法を記載しておきます。

syslogの設定は、以下のファイルに保存されています。

/etc/sysconfig/syslog

おそらく、インストールした状態の設定が記載されているはずです。
また、サービスはデフォルトで起動状態のはずですので、
このファイルに必要な設定を追記して、再起動すればOKなはずです。

早速、viで開いてみると・・・

# vi /etc/sysconfig/syslog


==========
/etc/sysconfig/syslog 更新前の内容
----------
# Options to syslogd
# -m 0 disables 'MARK' messages.
# -r enables logging from remote machines
# -x disables DNS lookups on messages recieved with -r
# See syslogd(8) for more details
SYSLOGD_OPTIONS="-m 0"
# Options to klogd
# -2 prints all kernel oops messages twice; once for klogd to decode, and
# once for processing with 'ksymoops'
# -x disables all klogd processing of oops messages entirely
# See klogd(8) for more details
KLOGD_OPTIONS="-x"
#
SYSLOG_UMASK=077
# set this to a umask value to use for all log files as in umask(1).
# By default, all permissions are removed for "group" and "other".
==========

となっていました。

で、6行目をコメントアウトして、以下のように修正します。

SYSLOGD_OPTIONS="-m 0 -r"

後で見たときに、なんで変更したのかがよく分かるように、
コメント追記するのを忘れずに保存してください。

==========
/etc/sysconfig/syslog 更新済みの内容
----------
# Options to syslogd
# -m 0 disables 'MARK' messages.
# -r enables logging from remote machines
# -x disables DNS lookups on messages recieved with -r
# See syslogd(8) for more details

## デフォルトの状態
##SYSLOGD_OPTIONS="-m 0"
## 起動時の設定をlogサーバーとして設定します。
SYSLOGD_OPTIONS="-m 0 -r"

# Options to klogd
# -2 prints all kernel oops messages twice; once for klogd to decode, and
# once for processing with 'ksymoops'
# -x disables all klogd processing of oops messages entirely
# See klogd(8) for more details
KLOGD_OPTIONS="-x"
#
SYSLOG_UMASK=077
# set this to a umask value to use for all log files as in umask(1).
# By default, all permissions are removed for "group" and "other".
==========

これで、OKです。

あとは、以下のコマンドを実行して、syslogサービスを再起動します。
/etc/rc.d/init.d/syslog restart

2.ネットワークの設定
対象となるサーバーにiptablesを設定しているので、
次に、ネットワークの設定が必要になります。

ファイアーウォール等を設定していなければ、以下の設定は必要ありません。

syslog サーバーがlogを受け取るには、UDPの514ポートを使用しますので、
iptables で、対象となるネットワークサーバー、ネットワーク機器からの
UDP経由でのアクセスを許可する必要があります。

iptables の設定は、以下のファイルに記述します。
/etc/sysconfig/iptables

設定内容は、サーバーの設定にあわせたほうがいいと思います。
ここでは、記述例として参考にしてください。


-A Firewall-INPUT -p udp -m udp --dport 512 -j ACCEPT

それぞれのオプションの意味は、iptables --helpを参照してください。

-A [chain] : どのチェインに追加するかを指定します。
-p [proto] : 対象となるプロトコルを設定します。
-m [match] : extension を設定
--dport [num] : ポート番号の設定
-j [target] : 適用するルールを設定

と、こんな感じです。

これで、iptables を再起動すれば、設定内容を読み込んでくれるはずです。

/etc/rc.d/init.d/iptables restart

## 端末からの確認
以下のコマンドで確認することができます

logger -p info "TEST MESSAGE."

0 件のコメント: