zoukankan      html  css  js  c++  java
  • iptables和ipset

    ipset

    yum -y install ipset

    创建一个set

    hash:net 指定可以向集合添加ip段或ip地址,

    ipset create blacklist hash:net hashsize 4096 maxelem 100000 timeout 300

    hash:ip 指定可以向集合添加ip地址

    ipset create whitelist hash:net hashsize 4096 maxelem 1000000

    添加删除、删除ip

    ipset add blacklist 10.10.10.0/24 timeout 60

    ipset del blacklist 10.10.10.0/24

    查看set内容

    ipset list blacklist

    创建防火墙规则

    iptabels -A INPUT -m set --match-set blacklist src -j DROP

    保存

    ipset save blacklist -f blacklist.txt

    删除ipset

    ipset destroy blacklist

    清空

    ipset flush blacklist

    导入ipset规则

    ipset restore -f blacklist.txt

    封禁多个端口

    iptables -A INPUT -p tcp -m set --match-set blacklist src -m multiport --dports 443,80 -j DROP

    iptables

    yum install -y iptables
    yum install iptables-services
    systemctl start iptables
    systemctl enable iptables
    systemctl stop firewalld
    systemctl disable firewalld
    
    iptables -F
    # 清空所有自定义规则
    iptables -X
    # 所有计数器归0
    iptables -Z
    # 允许来自于lo接口的数据包(本地访问)
    iptables -A INPUT -i lo -j ACCEPT
    
    # 允许ping
    # iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
    
    # iptables -A INPUT -s 192.168.0.0/16 -j ACCEPT
    #允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
    iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT
    
    #其他入站一律丢弃
    iptables -P INPUT DROP
    #所有出站一律绿灯
    iptables -P OUTPUT ACCEPT
    # 所有转发一律丢弃
    #iptables -P FORWARD DROP
    
  • 相关阅读:
    14、流程分析法
    13、场景法
    SPL之Iterator(迭代器)接口
    MySQL的自动补全和语法高亮工具MyCli
    如何在mmseg3添加词库
    sphinx 配置文件全解析
    配置samba 服务器 共享Linux目录
    Centos7 下coreseek的安装
    机器学习常用的降维方法
    mysql 分类
  • 原文地址:https://www.cnblogs.com/ray-mmss/p/14465302.html
Copyright © 2011-2022 走看看