一、 csf 防火牆
csf 防火牆提供了基於 web GUI 的管理方式,並且提供 cPanel 外掛外掛,而且還可以基於 CLI 來管理.
1 防止暴力破解密碼,自動遮蔽連續登陸失敗的 IP;
2 管理網際網路埠,只開放必要的埠;
3 免疫小流量的 DDos 和 CC 攻擊;
 
二、 csf 安裝:
<1> 安裝依賴包:
# yum -y install perl-libwww-perl perl iptables
<2> 下載並安裝 csf:
# wget http://www.configserver.com/free/csf.tgz
# tar -xzf csf.tgz
# cd csf
# sh install.sh
 
<3>測試 csf 是否能正常工作:
# per /etc/csf/csftest.pl
-bash: per: command not found
[root@sqj csf]# perl /etc/csf/csftest.pl
Testing ip_tables/iptable_filter…OK
Testing ipt_LOG…OK
Testing ipt_multiport/xt_multiport…OK
Testing ipt_REJECT…OK
Testing ipt_state/xt_state…OK
Testing ipt_limit/xt_limit…OK
Testing ipt_recent…OK
Testing xt_connlimit…OK
Testing ipt_owner/xt_owner…OK
Testing iptable_nat/ipt_REDIRECT…OK
Testing iptable_nat/ipt_DNAT…OK
 
RESULT: csf should function on this server
 
三、 csf 的配置:
csf 的配置檔案是 /etc/csf/csf.conf
引數:
<1>TESTING = “0”  //預設的 1(測試模式) 修改為 0(正式模式;
 
<2>TCP_IN  TCP_OUT
# Allow incoming TCP ports
TCP_IN = “20,21,22,25,53,80,110,143,443,465,587,993,995”
# Allow outgoing TCP ports
TCP_OUT = “20,21,22,25,53,80,110,113,443,587,993,995”
安全起見, 可以修改 SSH 預設埠為其他埠, 然後把相應的埠加入 TCP_IN TCP_OUT 中即可!
某些程式需要開啟一定範圍的埠, 例如 Pureftpd 的 passive mode, 可使用 30000:35000 的方式開啟 30000-35000 範圍的埠. 同上方式加入.
 
<3>ICMP_IN = “1”
# Allow incoming PING 是否允許別人 ping 你的站群伺服器, 預設為 1, 允許,0 為不允許.
 
<4>免疫小規模 ddos 攻擊
# To disable this feature, set this to 0
CT_LIMIT = “150”    //固定時間內同一個 IP 請求的次數
 
# Connection Tracking interval. Set this to the the number of seconds between
# connection tracking scans
CT_INTERVAL = “30”   //指上面的固定時間, 單位為秒;
 
# Send an email alert if an IP address is blocked due to connection tracking
CT_EMAIL_ALERT = “1”   //是否傳送郵件
 
# If you want to make IP blocks permanent then set this to 1, otherwise blocks
# will be temporary and will be cleared after CT_BLOCK_TIME seconds
CT_PERMANENT = “0”    //是否對可以 IP 採取永久遮蔽, 預設為 0, 即臨時性遮蔽.
 
# If you opt for temporary IP blocks for CT, then the following is the interval
# in seconds that the IP will remained blocked for (e.g. 1800 = 30 mins)
CT_BLOCK_TIME = “1800”  //臨時性遮蔽時間
 
# If you don’t want to count the TIME_WAIT state against the connection count
# then set the following to “1”
CT_SKIP_TIME_WAIT = “0”  //是否統計 TIME_WAIT 連結狀態
 
<5>CT_PORTS = “”
# Leave this option empty to count all states against CT_LIMIT
CT_STATES = “”  對什麼埠進行檢測, 為空則檢測所有. 通常只需定義對 HTTP 服務 80 埠進行檢測.
 
四、黑名單、白名單
配置檔案路徑: /etc/csf/csf.allow  /etc/csf/csf.deny
若要禁某個 IP, 可以把對應 IP(或 IP 段) 加入 csf.deny 配置檔案, 同樣可以使用命令 csf -d IP.
然後, 重啟 csf. /etc/init.d/csf restart 或者 csf -r 都可以重啟.
 

解除安裝 csf

執行以下命令即可解除安裝 csf
#cd /etc/csf
#sh uninstall.sh