黑帽联盟

 找回密码
 会员注册
查看: 1602|回复: 0

[资源教程] Linux VPS使用ipset快速屏蔽指定国家的IP访问

[复制链接]

906

主题

38

听众

3375

积分

管理员

Rank: 9Rank: 9Rank: 9

  • TA的每日心情
    无聊
    11 小时前
  • 签到天数: 1697 天

    [LV.Master]伴坛终老

    说明:ipset是iptables的扩展,它允许你创建匹配整个IP地址集合的规则。可以快速的让我们屏蔽某个IP段。这里分享个屏蔽指定国家访问的方法,有时候还可以有效的帮网站阻挡下攻击。

    方法
    首先需要得到国家IP段,下载地址:http://www.ipdeny.com/ipblocks/。这里以我们国家为例。
    1、安装ipset
    #Debian/Ubuntu系统
    apt-get -y install ipset

    #CentOS系统
    yum -y install ipset

    2、创建规则
    #创建一个名为cnip的规则
    ipset -N cnip hash:net
    #下载国家IP段
    wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone
    #将IP段添加到cnip规则中
    for i in $(cat /root/cn.zone ); do ipset -A cnip $i; done

    3、开始屏蔽
    iptables -I INPUT -p tcp -m set --match-set cnip src -j DROP

    4、解除屏蔽
    #-D为删除规则
    iptables -D INPUT -p tcp -m set --match-set cnip src -j DROP


    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部