CSF(ConfigServer Security & Firewall)是一套優秀的 Linux 伺服器防火牆方案,本質上是基於狀態封包檢測的 iptables 前端,同時整合登入與入侵偵測。它設定直接靈活,具備漏洞偵測、IP 封鎖、帳號異動追蹤、IDS 與安全檢查等功能,並提供 cPanel、DirectAdmin、Webmin 的管理介面。
官方提供安裝腳本,流程很直截了當:
# rm -fv csf.tgz
# wget https://www.configserver.com/free/csf.tgz
# tar -xzf csf.tgz
# cd csf
# sh install.sh
# perl /usr/local/csf/bin/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 ipt_owner/xt_owner... OK
Testing iptable_nat/ipt_REDIRECT... OK
RESULT: csf should function on this server
只要沒有致命錯誤,功能大致都能用。但使用前必須停用其他 iptables 設定腳本以免衝突,例如先前用過 APF 與 BFD 就先移除:
# sh /usr/local/csf/bin/remove_apf_bfd.sh
可直接編輯 /etc/csf/csf.conf,或從面板修改。對 cPanel 與 DirectAdmin 主機,CSF 預設在標準埠運作;若 SSH 使用非 22 埠,它會自動偵測;安裝時的來源 IP 也會自動加入白名單。
另外請確認 klogd 處於啟動狀態,RedHat/CentOS 5.x 的 VPS 常把內核日誌守護停用,可檢查 /etc/init.d/syslog 是否有被註解掉的行,修改後重啟 syslog。
先照上述方式裝好 CSF,接著進入 Webmin 頁面 → Webmin Configuration → Webmin Modules → From local file,選擇 /usr/local/csf/csfwebmin.tgz 後 Install Module。
cd /etc/csf
sh uninstall.sh
要產出統計圖表需安裝 Perl 的 GD 模組:
# yum install perl-GDGraph #RedHat/CentOS/CloudLinux
# apt-get install libgd-graph-perl #Debian v6
或從 CPAN 安裝:
# perl -MCPAN -e shell
cpan> install GD::Graph