zl程序教程

您现在的位置是:首页 >  工具

当前栏目

(转)CentOS6 iptables 记录指定IP的网络访问日志

日志网络IP 记录 访问 指定 iptables CentOs6
2023-09-11 14:15:22 时间

 

修改文件/etc/rsyslog.conf 加入

#DIY iptables Log save
#kern.warning /var/log/iptables/iptables.log
kern.debug /var/log/iptables/iptables.log

修改文件/etc/sysconfig/iptables

-A INPUT -p tcp -m limit --limit 1/sec -j LOG --log-level 7

service rsyslog restart

service iptables restart

 

# 清理和压缩每天产生的大量日志

#!/bin/bash

#clear iptables Log

YY=`date +%Y`
mm=`date +%m`
dd=`date +%d`
Basedic='/var/log/iptables'

cd $Basedic
/bin/mkdir -p ${YY}/${mm}
/bin/mv iptables.${YY}${mm}* ${YY}/${mm}
~
# clean up  循环删除1年前日志find /var/log/iptables/ -type f -mtime +365 -exec rm -f {} \;

 

#!/bin/bash
##
#
timer=`date +%Y%m%d`
addrs="/var/log/iptables"

/bin/mv $addrs/iptables.log{,.$timer}
/bin/touch $addrs/iptables.log
/etc/init.d/rsyslog restart
cd $addrs && /bin/tar -zcf iptables.$timer.tar.gz iptables.log.$timer --remove-files

 

 

参考内容:https://blog.csdn.net/WQ7X/article/details/105220711