Centos7防火墙

Centos7 firewall 命令:

  • 查看已经开放的端口
firewall-cmd --list-ports
  • 开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
  • 重启防火墙
firewall-cmd --reload   #重启firewall
  • 关闭防火墙
systemctl stop firewalld.service   #停止firewall
systemctl disable firewalld.service   #禁止firewall开机启动

iptables

  • 编辑防火墙配置文件
vi /etc/sysconfig/iptables 
# sampleconfiguration for iptables service
# you can edit thismanually or use system-config-firewall
# please do not askus to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT[0:0]
:OUTPUT ACCEPT[0:0]
-A INPUT -m state--state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -jACCEPT
-A INPUT -i lo -jACCEPT
-A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT
-A INPUT -j REJECT--reject-with icmp-host-prohibited
-A FORWARD -jREJECT --reject-with icmp-host-prohibited
COMMIT

添加端口:-A INPUT -p tcp -m state --state NEW -m tcp--dport 9090 -j ACCEPT

systemctlrestart iptables.service   #最后重启防火墙使配置生效
systemctlenable iptables.service   #设置防火墙开机启动

你可能感兴趣的:(Centos7防火墙)