首页 > 其他 > 详细

iptables和ipset

时间:2021-03-01 21:58:53      阅读:33      评论:0      收藏:0      [点我收藏+]

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

iptables和ipset

原文:https://www.cnblogs.com/ray-mmss/p/14465302.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!