在CentOS系統中,使用firewalld作為默認的防火墻管理工具。要在CentOS LAMP環境中設置防火墻規則,請按照以下步驟操作:
sudo yum install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo firewall-cmd --list-all
使用以下命令為這些端口開放防火墻:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --permanent --zone=public --add-service=mysql
sudo firewall-cmd --permanent --zone=public --add-service=ftp
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
現在,您的CentOS LAMP環境應該已經配置了防火墻規則,允許外部訪問HTTP、HTTPS、MySQL和FTP服務。如果需要開放其他端口,只需將上述命令中的端口號替換為所需端口號即可。