問(wèn)題
最近不知道為什么,惡意代理的請(qǐng)求數(shù)越來(lái)越多,明明我返回的都是403Forbidden,但是由于數(shù)量實(shí)在龐大,還是消耗了我大量的帶寬和資源。之前的方法已經(jīng)沒有用了,想了半天還是研究研究防火墻吧,雖然僅僅靠Apache也能對(duì)某些IP進(jìn)行黑名單設(shè)置,但是感覺還是有點(diǎn)麻煩的。比如最常見的用iptables,或者是ufw,雖然都能很好的做到管理,但是他們基本都需要一條一條的加,十分麻煩。
網(wǎng)上搜索了下,找到了一個(gè)挺方便的小工具–CSF(ConfigServer & Security Firewall),這個(gè)工具據(jù)說(shuō)除了能夠方便的管理IP blacklist,而且也能稍加配置抵御一定量的DDOS攻擊。
安裝
工具本身可以在csf工具的官網(wǎng)上下載。
下載并解壓后可以參考其中的install.txt的說(shuō)明進(jìn)行安裝,講的簡(jiǎn)潔而且詳細(xì),注意給權(quán)限就行。需要說(shuō)明的是,這個(gè)工具其實(shí)也是基于iptables,只是簡(jiǎn)化了命令而已。
關(guān)于ddos的防護(hù)
根據(jù)readme.txt的描述,進(jìn)行ddos防護(hù)的功能主要是靠/etc/csf/csf.conf中的配置進(jìn)行控制的,尤其是當(dāng)中的PORTFLOOD參數(shù),一般都進(jìn)行如下設(shè)置:
#Syntax for the PORTFLOOD setting:#PORTFLOOD is a comma separated list of:port;protocol;hit count*;interval seconds#So, a setting of PORTFLOOD = "22;tcp;5;300,80;tcp;20;5" means:#1. If more than 5 connections to tcp port 22 within 300 seconds, then block#that IP address from port 22 for at least 300 seconds after the last packet is#seen, i.e. there must be a "quiet" period of 300 seconds before the block is#lifted#2. If more than 20 connections to tcp port 80 within 5 seconds, then block#that IP address from port 80 for at least 5 seconds after the last packet is#seen, i.e. there must be a "quiet" period of 5 seconds before the block is#lifted
這個(gè)可以根據(jù)個(gè)人需要修改。
關(guān)于black list
blacklist 就在/etc/csf/csf.deny里,可以有多種書寫方式,在該文件的頂部描述的十分清楚:
################################################################################ Copyright 2006-2017, Way to the Web Limited# URL: http://www.configserver.com# Email: sales@waytotheweb.com################################################################################ The following IP addresses will be blocked in iptables# One IP address per line# CIDR addressing allowed with a quaded IP (e.g. 192.168.254.0/24)# Only list IP addresses, not domain names (they will be ignored)## Note: If you add the text "do not delete" to the comments of an entry then# DENY_IP_LIMIT will ignore those entries and not remove them## Advanced port+ip filtering allowed with the following format# tcp/udp|in/out|s/d=port|s/d=ip## See readme.txt for more information regarding advanced port filtering#
簡(jiǎn)要概括就是每一行代表一個(gè)ip,也可以代表一個(gè)ip段(CIDR),而且我們也可以加注釋,甚至可以指定端口和協(xié)議。
最后,在做出修改后想要生效記得用csf -r命令。
針對(duì)惡意代理請(qǐng)求的防護(hù)方案
當(dāng)然,我用這個(gè)的目的是為了根本解決之前的惡意代理占用帶寬的問(wèn)題。有了這個(gè)工具,就可以十分輕松的進(jìn)行控制了,思路如下:
實(shí)現(xiàn)起來(lái)超級(jí)簡(jiǎn)單:
可以手動(dòng)查看下結(jié)果是否正確,確認(rèn)之后既可以csf -r重啟服務(wù)了。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選