在 CentOS 上配置 Apache(httpd) 的防火墙,通常使用的是 firewalld(CentOS 7 及以上默认)。下面按常见场景说明。
systemctl status firewalld
如果未运行:
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
systemctl start httpd
systemctl enable httpd
测试访问:
http://服务器IP
例如 Apache 监听 8080:
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
firewall-cmd --list-all
示例输出中应包含:
services: http https
或
ports: 8080/tcp
如果你用的是 CentOS 6:
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
service iptables restart
检查:
netstat -tunlp | grep httpd
getenforce
若为 Enforcing,可临时关闭测试:setenforce 0
如果你能告诉我:
我可以给你更精确的配置命令。