Use MySQL to save iptables logs in debian

Source: Internet
Author: User
This article describes how to use ulogd to save iptables logs to MySQL In debian. This method has many benefits, and the main benefit is the log statistics in the future.

This article describes how to use ulogd to save iptables logs to MySQL In debian. This method has many benefits, and the main benefit is the log statistics in the future.

This article describes how to use ulogd to save iptables logs to MySQL In debian. There are many benefits to doing so. The main benefit is that the log statistics in the future will be very convenient.

Install ulogd and ulogd-mysql

First, run the following command:

$ Sudo apt-get install ulogd
$ Sudo apt-get install ulogd-mysql

After the installation is complete, configure ulogd.

First, you need to import the ulogd database script to the database:

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

Then modify the ulogd. conf configuration file:

$ Sudo vi/etc/ulogd. conf

Find # output plugins. the line number is about 43 rows. Comment out plugin = "/usr/lib/ulogd/ulogd_LOGEMU.so, uncomment the plugin = "/usr/lib/ulogd/ulogd_MYSQL.so" line to output it to MySQL. Next, find the MySQL configuration field in the configuration file, which is about 59 rows:

[MYSQL]
Table = "ulog"
Pass = ""
User = "root"
Db = "ulogd"
Host = "localhost"

Modify it to the corresponding options. After modification, start the ulogd service.

$ Sudo/etc/init. d/ulogd restart

If no error message is displayed, it means the operation is successful.

Step 2: Configure iptables

Set the iptables rules you want to record, for example, the packet to record port 80.

-A input-p tcp-m tcp-dport 80-j ULOG

However, it should be noted that ULOG does not filter packets. After matching this rule, the data continues to be matched.

In this way, the basic configuration is complete. When port 80 on the server has data, some information about the packets will be recorded in MySQL for later viewing and statistics.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.