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

 

修改文件/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

posted @   Cong0ks  阅读(284)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
历史上的今天:
2021-08-26 中华人民共和国 个人信息保护法 (全文学习)八章 七十四条 2021年11月1日起施行
2019-08-26 English trip EM4-LP 3A AT The MARKET Teacher:Patrick
2019-08-26 I1-3 Telephone English Teacher:Taylor
2019-08-26 Phonics 自然拼读法 ar er ir ur or 元音字母组合 Teacher:Lamb
2018-08-26 新概念 Lesson 3 Nice to meet you
点击右上角即可分享
微信分享提示