在 AlmaLinux 9 上安装 CSF
首先,您需要使用以下命令更新本地包索引:
sudo dnf update -y
然后,您需要使用以下命令在 AlmaLinux 9 上安装一些依赖项:
sudo dnf install wget vim perl -y
接下来,切换到您的 src 目录:
cd /usr/src
此时,使用 wget 命令在 AlmaLinux 9 上下载 CSF 安装程序脚本:
sudo wget https://download.configserver.com/csf.tgz
解压下载的文件:
sudo tar xzf csf.tgz
移至 CSF 目录:
cd csf
最后,使用以下命令运行 CSF 安装程序脚本:
sudo sh install.sh
安装完成后,测试您是否具有所需的 iptables 模块:
sudo perl /usr/local/csf/bin/csftest.pl
在输出中,您将看到:
Output
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
在 AlmaLinux 9 上配置 CSF
此时,您的服务器上安装了 CSF,您需要编辑 CSF 配置文件。
使用您喜欢的文本编辑器打开文件,这里我们使用 vi:
sudo vi /etc/csf/csf.conf
找到 Testing 行并将其值更改为 0。
TESTING = "0"
完成后,保存并关闭文件。
现在使用以下命令在 AlmaLinux 9 上启动并启用 CSF 和 LFD:
#sudo systemctl restart csf && sudo systemctl restart lfd
#sudo systemctl enable csf && sudo systemctl enable lfd
使用以下命令验证您的 CSF 和 LFD 是否处于活动状态并在您的服务器上运行:
sudo systemctl status csf && sudo systemctl status lfd
Output
● csf.service - ConfigServer Firewall & Security - csf
Loaded: loaded (/usr/lib/systemd/system/csf.service; enabled; vendor preset: disabled)
Active: active (exited) since Thu 2022-09-22 09:26:14 EDT; 31s ago
Main PID: 11375 (code=exited, status=0/SUCCESS)
CPU: 505ms
...
Output
● lfd.service - ConfigServer Firewall & Security - lfd
Loaded: loaded (/usr/lib/systemd/system/lfd.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2022-09-22 09:26:23 EDT; 39s ago
Main PID: 11421 (lfd - sleeping)
Tasks: 1 (limit: 23609)
Memory: 138.9M
CPU: 4.233s
CGroup: /system.slice/lfd.service
...
您可以使用以下命令在 AlmaLinux 9 上检查您的 CSF 防火墙版本:
csf -v
Output
csf: v14.17 (generic)
如果要允许来自 IP 地址的传入连接,可以使用以下语法:
csf -a [IP Address]
否则,如果要拒绝来自 IP 地址的传入连接,可以使用以下语法:
csf -d [IP Address]
删除 ConfigServer 防火墙
此外,如果你想从你的 AlmaLinux 9 中卸载 CSF 防火墙,你可以使用以下命令:
# cd /etc/csf
# sh uninstall.sh