zoukankan      html  css  js  c++  java
  • iptables:ipset批量管理ip

    1、安装

    安装: yum -y install ipset apt-get -y install ipset

    2、创建一个ipset

    ipset create whitelist hash:net

    3、加入一个名单ip

    ipset add whitelist 1.1.1.1

    ipset list  查看ipset名单

    4.去除名单ip

    ipset del whitelist 1.1.1.1

    5.创建防火墙规则,与防火墙/kvm联用

    无法访问宿主机

    iptables -A INPUT -i br1 -p tcp -m state --state NEW,ESTABLISHED --src 1.1.1.0/24 -j DROP

    无法访问虚拟机

    iptables -A FORWARD -i br1 -p tcp -m state --state NEW,ESTABLISHED --src 1.1.1.0/24 -j DROP

    允许ipset名单访问

    iptables -I INPUT -i br1 -p tcp -m set --match-set whitelist src -j ACCEPT

    iptables -I FORWARD -i br1 -p tcp -m set --match-set whitelist src -j ACCEPT

    也可以批量禁止

    iptables -I INPUT -m set –match-set whitelist src -p tcp –destination-port 80 -j DROP 

    6.将ipset规则保存到文件/恢复ipset规则

    ipset save whitelist -f ipset.conf 

    ipset -f /etc/ipset.conf

    7.删除ipset

    ipset destroy whitelist

  • 相关阅读:
    HDU 5744
    HDU 5815
    POJ 1269
    HDU 5742
    HDU 4609
    fzu 1150 Farmer Bill's Problem
    fzu 1002 HangOver
    fzu 1001 Duplicate Pair
    fzu 1150 Farmer Bill's Problem
    fzu 1182 Argus 优先队列
  • 原文地址:https://www.cnblogs.com/ywxbbbbb/p/10100748.html
Copyright © 2011-2022 走看看