什么是脑脊液?
CSF 或 Config Server Firewall 是 APF 的替代防火墙。
CSF 通常被认为是一种更高级的防火墙,因为与其他防火墙相比,它有更多的配置选项,同时安装和配置仍然足够简单,即使是新手管理员也可以使用它。 本文将为您提供有关如何在云 vps 服务器或专用服务器上安装和配置 CSF 及其安全插件 LFD(登录失败守护程序)的简单概述。
注意:本文假设您熟悉 SSH 和基本的命令行导航。 这些说明主要适用于拥有 VPS 或专用服务器的客户。 如果您没有对您的服务器帐户的根级别访问权限,您将无法进行这些更改。
删除您当前的防火墙
为防止操作中的任何冲突,我们将需要删除您当前的防火墙。 我们专用服务器上最常见的软件防火墙是 APF 和 CSF,因此我们在下面提供了有关如何删除 APF 的说明。 如果您使用的是不同的软件防火墙,请务必在继续之前遵循该程序的卸载说明。 完成卸载后,继续下面的 CSF 安装。
使用 Yum 删除 APF
如果它很可能是通过 yum 安装的,那么您首先需要确定 APF 包的名称:
rpm -qa |grep -i apf
在这种情况下:
[root@host ~]# rpm -qa | grep apf
apf-9.6_5-1
要删除该软件包,并让您的服务器为 CSF 安装做好准备,请运行以下命令:
[root@host ~]# rpm -e apf-9.6_5-1
如果你看到这个:
[root@host ~ ]# rpm -e apf-9.6_5-1
error: Failed dependencies:
apf >= 9.6_5-1 is needed by (installed) bfd-1.2-1.noarch
这意味着您已安装 BFD,需要先将其删除,然后才能继续删除 APF:
[root@host ~ ]# rpm -e bfd-1.2-1.noarch
然后再次尝试删除 apf:
[root@host ~ ]# rpm -e apf-9.6_5-1
删除源安装的 APF
这可能有点棘手,如果您不确定自己在做什么,您可能需要向我们的支持团队提交票证。 如果您有信心并希望继续,您会在下面找到一个命令列表,如果 APF 安装在最常见的 CentOS 目录中,您可以使用这些命令来删除它。
停止 APF 和 iptables 会清除防火墙中的所有规则,并确保删除 APF 安装不会导致访问问题:
[root@host ~ ]# /etc/init.d/iptables stop
[root@host ~ ]# /etc/init.d/apf stop
删除所有 APF 相关文件:
[root@host ~ ]# rm -Rfv /etc/apf
[root@host ~ ]# rm -fv /etc/cron.daily/fw
[root@host ~ ]# rm -fv /etc/init.d/apf
从启动时启动的程序列表中删除 APF:
[root@host ~ ]# chkconfig apf off
如果您在任何不理解的命令中遇到错误,请向我们的支持团队开票,我们将竭尽所能为您提供帮助。
安装 CSF
安装 CSF 应该像将源文件下载到服务器并进行安装一样简单。 下面的所有命令都应该通过 SSH 在您的服务器上执行,而不是在您的本地计算机上。
无论是 cPanel 服务器还是非 cPanel 服务器,安装的前几个步骤都是相同的。
取回包
从源代码安装任何软件时的最佳实践:在有足够空间的分区上使用临时目录。
在我们专用的 cPanel 服务器上,您已经有一个我们通常用于在主分区上称为“temp”的目录:
[root@host ~ ]# cd /home/temp/
在继续之前检查您的磁盘空间使用情况是个好主意,以确保有足够的可用空间:
[root@host ~ ]# df -h
采用 ‘wget’ 检索 CSF 安装代码:
[root@host ~ ]# wget https://www.configserver.com/free/csf.tgz
下载完成后,您将看到类似以下内容,并再次收到命令提示符:
14:53:02 (410.05 KB/s) - `csf.tgz' saved [487272/487272]
下一步:解压 CSF 安装文件并将目录更改为新创建的“csf”目录:
[root@host ~ ]# tar zxvf csf.tgz
[root@host ~ ]# cd csf
这是路径分歧的地方:cPanel 服务器或非 cPanel 服务器。
[root@host /home/temp/csf/ ]# ./install.cpanel.sh
如果您运行的是非 cpanel redhat 服务器:
[root@host /home/temp/csf/ ]# ./install.sh
无论哪种方式,您都可以在脚本运行时查看它的输出,它会告诉您它所做的一切。 最后,您将看到类似于以下内容的内容:
TCP ports currently listening for incoming connections:
21,22,25,53,80,110,143,443,465,993,995,2077,2078,2082,2083,2086,
2087,2095,2096,3306
UDP ports currently listening for incoming connections:
53,123
Note: The port details above are for information only, csf hasn't
been auto-configured.
Don't forget to:
1. Configure the TCP_IN, TCP_OUT, UDP_IN and UDP_OUT options in
the csf configuration to suite your server
2. Restart csf and lfd
3. Set TESTING to 0 once you're happy with the firewall
Adding current SSH session IP address to the csf whitelist in csf.allow:
Adding 10.30.6.17 to csf.allow only while in TESTING
mode (not iptables ACCEPT)
*WARNING* TESTING mode is enabled
- do not forget to disable it in the configuration
Installation Completed
要开始测试 CSF,请启动它:
[root@host ~ ]# /etc/init.d/csf restart
完成测试后,请务必通过更改 csf.conf 中的标志使 CSF 退出测试模式:
使用您喜欢的编辑器编辑配置,在这种情况下,我们将使用 vi:
[root@host ~ ]# vi /etc/csf/csf.conf
在配置文件顶部附近找到此文本块:
# Testing flag - enables a CRON job that clears iptables in case of
# configuration problems when you start csf. This should be enabled until you
# are sure that the firewall works - i.e. in-case you get locked out of your
# server! Then do remember to set it to 0 and restart csf when you're sure
# everything is OK. Stopping csf will remove the line from /etc/crontab
TESTING = "1"
编辑该文本块的最后一行,使其反映测试被禁用:
TESTING = "0"
最后,重启 CSF:
[root@host ~ ]# /etc/init.d/csf restart
您的 CSF 防火墙已启动并正在运行! 恭喜!
常见安装错误
如果您看到有关未安装 libwww 的错误,您可以使用 yum 或 cpan 安装它:
yum install perl-libwww-perl
或者
perl -MCPAN -e 'install Bundle::LWP'
开始 CSF:使用命令行进行更改。
使用命令行界面更新 CSF 在设计上很简单!
以下是您将使用的最常见的命令:
csf -d IP地址 将拒绝 IP。
csf -a IPADDRESS 将允许IP。
脑脊液 -r 将重新加载所有规则。
如果您忘记了要查找的命令,只需键入 ‘脑脊液‘ 在命令行上,您将收到所有选项的列表:
[root@host ~ ]# csf
ConfigServer Security & Firewall (https://www.configserver.com/cp/csf/)
csf: v4.17
(c)2006, Way to the Web Limited (https://www.waytotheweb.com)
Usage: /usr/sbin/csf [option] [value]
Option Meaning
-h, --help Show this message
-l, --status List/Show iptables configuration
-s, --start Start firewall rules
-f, --stop Flush/Stop firewall rules
-r, --restart Restart firewall rules
-a, --add ip Add an IP address to be whitelisted to /etc/csf.allow
-d, --deny ip Add an IP address to be blocked to /etc/csf.deny
-dr, --denyrm ip Remove and unblock an IP address in /etc/csf.deny
-c, --check Checks for updates to csf+lfd but does not perform an upgrade
-g, --grep ip Search the iptables rules for an IP match (incl. CIDR)
-t, --temp Displays the current list of temporary IP bans and their TTL
-tr, --temprm ip Remove an IP address from the temporary IP ban list
-td, --tempdeny ip ttl [-p port] [-d direction]
Add an IP address to the temporary IP ban list. ttl is how
long to blocks for in seconds. Optional port. Optional
direction of block can be one of in, out or inout. Default
is in
-tf, --tempf Flush all IP addresses from the temporary IP ban list
-u, --update Checks for updates to csf+lfd and performs an upgrade if
available
-x, --disable Disable csf and lfd
-e, --enable Enable csf and lfd if previously disabled
-v, --version Show csf version
CSF 是某些服务器上现有防火墙的一种越来越流行的替代方案。 如果您需要任何其他帮助或对 CSF 有任何疑问,请向我们的支持团队开票。 您可以登录到您的 管理 帐户随时,或者您也可以访问 CSF主页 您可以在其中找到其他文档和常见问题解答。