firewalld命令记录

0、 引言

今天配置服务器的ftp,被这个防火墙命令困扰半天,想不起来,特此整理下。
centos7 默认的防火墙是 firewall,替代了以前的 iptables。
参考资料 : https://blog.csdn.net/wangmx1993328/article/details/80738012

1、安装

  • 查看版本
firewall-cmd --version

有些服务器已经自带了 firewall ,但是查看版本没有找到,也可以直接通过yum安装。

  • 安装
yum -y install firewalld

2、服务管理

和其他服务一样,通过systemctl 管理。

systemctl status firewalld		//查看防火墙状态
systemctl stop firewalld		//关闭防火墙	
systemctl start firewalld		//开启防火墙
systemctl restart firewalld		//重启防火墙	
systemctl is-enabled firewalld	//查看 firewall 服务是否开机启动	
systemctl enable firewalld		//开机时自动启动
systemctl disable firewalld		//开机时自动禁用

3、防火墙管理

3.1 firewall-cmd 命令
  • 查看状态
firewall-cmd --state
  • 查看打开的所有端口
firewall-cmd --zone=public --list-ports
  • 开启指定端口
    –permanent 永久开放
firewall-cmd --zone=public --add-port=80/tcp --permanent	//永久开放80端口
firewall-cmd --zone=public --add-port=3000-4000/tcp --permanent	//永久开放3000到4000端口
  • 关闭指定端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent
  • 重新加载
    对端口的所有修改,必须重新加载才能生效
firewall-cmd --reload
3.2 public.xml 文件

firewall-cmd对端口的操作,如开放端口等信息,都在 public.xml 文件中
文件目录 /etc/firewalld/zones/public.xml

vim /etc/firewalld/zones/public.xml

<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <port protocol="tcp" port="21"/>
  <port protocol="tcp" port="4500-5000"/>
</zone>

修改后 :wq
firewall-cmd --reload

4、相关问题

  • 如果你的服务器是在阿里云,就需要去阿里云配置安全组,只开启防火墙,或者 只开启安全策略,是不生效的。
  • 修改安全策略,不需要重启服务器
  • 修改防火墙配置,必须重启防火墙

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值