Home  >  Article  >  Database  >  debian下利用MySQL保存iptables日志

debian下利用MySQL保存iptables日志

WBOY
WBOYOriginal
2016-06-07 16:51:411104browse

本文介绍如何在 debian下,通过 ulogd 把 iptables 的日志保存到 MySQL 中。这样做的好处很多,最主要的好处莫过于以后的日志统计

本文介绍如何在 debian下,通过 ulogd 把 iptables 的日志保存到 MySQL 中。这样做的好处很多,最主要的好处莫过于以后的日志统计会非常的便利。

安装 ulogd 以及 ulogd-mysql

首先执行如下命令:

$ sudo apt-get install ulogd
$ sudo apt-get install ulogd-mysql

安装完毕后,下面开始配置 ulogd。

首先,需要把 ulogd 的数据库脚本导入到数据库中:

$ mysql
mysql> create database ulogd;
mysql> use ulogd;
mysql> source /usr/share/doc/ulogd-mysql/mysql.table

然后再修改 ulogd.conf 的配置文件:

$ sudo vi /etc/ulogd.conf

找到# output plugins.行的字样,大约在43行左右,找到plugin=”/usr/lib/ulogd/ulogd_LOGEMU.so”将其注释掉,并取消 plugin=”/usr/lib/ulogd/ulogd_MYSQL.so”行的注释,,表示输出到 MySQL 中。接下来再找到配置文件中 MySQL 配置字段,大约在 59 行左右:

[MYSQL]
table="ulog"
pass=""
user="root"
db="ulogd"
host="localhost"

修改为相应选项即可。修改完毕,启动 ulogd 服务。

$ sudo /etc/init.d/ulogd restart

如果没有遇到什么错误提示,就说明已经成功了。

Step 2:配置 iptables

设置你要记录的 iptables 规则,比如要记录 80 端口的包。

-A INPUT -p tcp -m tcp –dport 80 -j ULOG

不过要注意的是,ULOG 不对包进行过滤,匹配上这一条规则之后,数据依旧继续往下匹配。

这样就基本配置完毕了,当服务器上的 80 端口有数据的时候,报文的一些信息就会被记录到 MySQL 中,便于以后的查看与统计。 

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn