使用iptables记录谁访问了HDFS

使用iptables记录谁访问了HDFS


iptables -t filter -F
iptables -t filter -A INPUT -p tcp –dport 22 –match state –state NEW -j LOG

如果使用syslog,那么编辑/etc/syslog.conf,添加:
kern.warning /var/log/iptables.log
如果使用rsyslog,那么编辑/etc/rsyslog.d/60-iptables.conf,添加:
kern.warning /var/log/iptables.log

http://gr8idea.info/os/tutorials/security/iptables5.html

上面的方法虽然正确,但是在真实300+datanode的环境中,服务器启动iptables以及log功能后,系统资源会紧张,具体是什么紧张我还没有数据。
而且kernel.warning这种粗狂的方式貌似dmesg , tty0系统终端, /var/log/message里面都是这种log,当然还有自己指定的文件 /var/log/iptables下面。

rsyslog采用另外一种方式:

:msg,contains,"IPTABLES: "        /var/log/iptables.log

对应的iptables配置如下

iptables -t filter -F
iptables -t filter -A INPUT -p tcp --dport 9000 --match state --state NEW -j LOG --log-prefix "IPTABLES: " --log-level 7
iptables -t filter -L -n --line-numbers

我怀疑是写文件太浪费磁盘io了吧,把日志直接写到远端rsyslog服务器试试。

远程的先不测试了。

换用了另外一种方式

#!/usr/bin/env bash

# @author: zzlyzq@gmail.com
# @date: 2015.03.05
# @description :对于hdfs master9000tcp端口实行白名单限制,避免恶意主机接入hdfs机群造成这样或者那样的破坏。

# @usage: 该sh脚本对于当前文件夹下的所有*.txt文件进行读取,每一行作为一个输入,然后产生
# iptables -t filter -A INPUT -s $ip -j ACCEPT

# 清空所有filter配置策略,重新配置
iptables -t filter -F
# 下面的三条是为了提高性能,因为我们主要是限制tcp port 9000,所以对于其他的udp icmp 和 非tcp 9000可以直接ACCEPT通过,无需匹配INPUT的默认ACCEPT策略
iptables -t filter -A INPUT -p icmp -j ACCEPT
iptables -t filter -A INPUT -p udp -j ACCEPT
iptables -t filter -A INPUT -p tcp -m multiport ! --dport 9000 -j ACCEPT

for file in `ls *.txt`
do
    # echo $file
    for ip in `cat $file`
    do
    if [ ${#ip} -lt 7 ];then
            # 简单过滤,如果一行的size小于7,三个点+4个字儿,那么就继续
            echo "find less than7"
        continue
    fi
    command="iptables -t filter -A INPUT -s $ip -p tcp --dport 9000 -j ACCEPT"
    echo $command
    $command
    done
done

iptables -t filter -A INPUT -p tcp --dport 9000 -j LOG --log-prefix "IPTABLES: "
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值