Linux防火墙(centos7新特性)

Liunx的防火墙

引入

今天在给Linux配置防火墙时,发现Redhat Enterprise Linux7已经默认使用firewalld作为防火墙,其使用方式已经变化。基于iptables的防火墙被默认不启动,但仍然可以继续使用。
RHEL7中有几种防火墙共存:firewalld、iptables、ebtables等,默认使用firewalld作为防火墙,管理工具是firewall-cmd。
RHEL7的内核版本是3.10,在此版本的内核里防火墙的包过滤机制是firewalld,使用firewalld来管理netfilter,不过底层调用的命令仍然是iptables等。
因为这几种daemon是冲突的,所以建议禁用其他几种服务。

一、机制

防火墙是整个数据包进入主机前的第一道关卡。防火墙主要通过Netfilter与TCPwrappers两个机制来管理的。

  1. Netfilter:数据包过滤机制
    关于数据包过滤机制有两个软件:firewalld与iptables
  2. TCP Wrappers:程序管理机制

二、数据过滤

对于firewalld和iptables service之间最本质的区别是:

  1. iptable service 在/etc/sysconfig/iptables中存储配置,而firewalld将配置存储/usr/lib/firewalld 和 /etc/firewalld中的各种XML文件里
  2. 使用iptable service每一个单独更改意味着清除所有旧有的规则,并且从/etc/sysconfig/iptables里读取所有的新的规则。然而在使用firewalld不会再创建任何新有的规则。
  3. 总之,他们的区别运行规则的不同,所以firewalld可以在运行时间内改变设置而不丢失现有连接。

三、iptables的终端命令

查看防火墙状态

service iptables status

安装iptables

yum -y install iptables iptables-services

停止防火墙

service iptables stop

启动防火墙

service iptables start

重启防火墙

service iptables restart

永久关闭防火墙

chkconfig iptables off

永久关闭后重启

chkconfig iptables on

开启80端口

  1. vim /etc/sysconfig/iptables
  2. 加入如下代码
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
  1. 保存退出后重启防火墙
service iptables restart

四、firewalld的终端命令

查看firewall服务状态

systemctl status firewalld

出现Active: active (running)切高亮显示则表示是启动状态。

出现 Active: inactive (dead)灰色表示停止。

查看firewall的状态

firewall-cmd --state

开启firewalld.service服务

service firewalld start

重启firewalld.service服务

service firewalld restart

关闭firewalld.service服务

service firewalld stop

查看防火墙规则

firewall-cmd --list-all

查询端口是否开放

firewall-cmd --query-port=8080/tcp

开放80端口

firewall-cmd --permanent --add-port=80/tcp

移除端口

firewall-cmd --permanent --remove-port=8080/tcp

重启防火墙(修改配置后要重启防火墙)

firewall-cmd --reload

参数解释
  1. firwall-cmd:是Linux提供的操作firewall的一个工具;
  2. –permanent:表示设置为持久;
  3. –add-port:标识添加的端口;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值