在 Centos 7 或 RHEL 7 或 Fedora 中防火墙由 firewalld 来管理,而不是 iptables。
一、firewalld 防火墙语法命令如下:启用区域端口和协议组合
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]此举将启用端口和协议的组合。
端口可以是一个单独的端口 <port> 或者是一个端口范围 <port>-<port>。
协议可以是 tcp 或 udp。
查看 firewalld 状态
systemctl status firewalld开启 firewalld
systemctl start firewalld
开放端口
重新载入
查看
删除
也可以还原传统的管理方式使用 iptables
systemctl stop firewalld systemctl mask firewalld安装 iptables-services
yum install iptables-services设置开机启动
systemctl enable iptables操作命令
systemctl stop iptables systemctl start iptables systemctl restart iptables systemctl reload iptables保存设置
service iptables save开放某个端口 在 /etc/sysconfig/iptables 里添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT