共计 1636 个字符,预计需要花费 5 分钟才能阅读完成。
导读 | 刚安装完 Lnmp 访问正常,重启 Fedora 28 系统之后,发现 web 无法访问了,重启 lnmp 一切正常,所有服务都是运行状态,网上查了一下,怀疑是防火墙问题,关闭 iptables,原来 Fedora 服务器版本里面的防火墙原来是 firewall,关闭之后正常。 |
关闭 firewall 命令:
systemctl stop firewalld.service
再次访问 WEB 服务,正常工作了。
Fedora28,无法使用 iptables 控制 Linuxs 的端口,而使用 firewalld 代替了原来的 iptables。下面记录如何使用 firewalld 开放 Linux 端口, 开启端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
–zone | |
–add-port=80/tcp | |
–permanent |
重启防火墙
firewall-cmd --reload
文中本是已增加了 80 端口只是没有进行重启,经过一次停用和启用,防火墙的设置生效。
详细信息可以参考以下资料:
http://stackoverflow.com/questions/24729024/centos-7-open-firewall-port
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html
如果还是不行只要卸载 firewall,安装 iptables 就可以了。
yum remove firewall
安装 iptables:
yum install iptables-services
编辑配置文件:
vi /etc/sysconfig/iptables
添加下面两行
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许 80 端口通过防火墙)-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允许 3306 端口通过防火墙)
特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的 22 端口这条规则的下面
添加好之后防火墙规则如下所示:
# Firewall configuration written by system-config-firewall | |
# Manual customization of this file is not recommended. | |
*filter | |
:INPUT ACCEPT [0:0] | |
:FORWARD ACCEPT [0:0] | |
:OUTPUT ACCEPT [0:0] | |
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT | |
-A INPUT -p icmp -j ACCEPT | |
-A INPUT -i lo -j ACCEPT | |
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT | |
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT | |
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT | |
-A INPUT -j REJECT –reject-with icmp-host-prohibited | |
-A FORWARD -j REJECT –reject-with icmp-host-prohibited | |
COMMIT |
重启服务:
systemctl restart iptables.service
跟随系统启动:
systemctl enable iptables.service
正文完
星哥玩云-微信公众号
