使用iptables封指定IP访问网站的方法

本文介绍了一种利用iptables封禁频繁访问网站的恶意IP地址的方法。通过分析Apache access_log找出盗链IP,并提供了一系列iptables命令,包括封禁单个IP、IP段以及特定端口等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用iptables封指定IP访问网站的方法

近来网站访问量异常增长,通过分析apache access_log找出了频繁访问的IP地址,确认是盗链,决定使用iptables封掉.

脚本如下:

# awk '{print $1}' access_log.20110622 |sort |uniq -c |sort -nr |more
15112 183.38.186.60
5289 218.83.160.164
4566 58.61.154.18
4428 183.39.105.113
3169 121.14.162.56
2121 113.108.116.17
1971 121.14.162.46
1614 121.14.162.65
1515 192.168.39.134
1430 59.152.221.14
1391 121.14.162.47
1350 183.38.181.117
1317 183.38.189.202
1293 121.14.162.85
1285 121.14.162.117

iptables的使用方法如下:

封单个IP的命令
iptables -I INPUT -s 183.38.186.60 -j DROP

封IP段的命令
iptables -I INPUT -s 183.38.186.0/16 -j DROP

封整个段的命令
iptables -I INPUT -s 183.38.0.0/8 -j DROP

封几个段的命令
iptables -I INPUT -s 183.38.186.0/24 -j DROP
iptables -I INPUT -s 183.38.187.0/24 -j DROP

只封80端口
iptables -I INPUT -p tcp –-dport 80 -s 183.38.186.0/24 -j DROP
iptables -I INPUT -s 183.38.186.0/24 -j DROP

删除所有限制项
iptables -F

删除指定限制项

iptables -D INPUT 数字

如 iptables -D INPUT 1

查看iptables配置项
# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP tcp -- 10.200.1.149 anywhere tcp dpt:http

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
#

删除一个配置项
# iptables -D INPUT 1

复核iptables配置项
# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值