博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
liux7防火墙管理20201209
阅读量:4172 次
发布时间:2019-05-26

本文共 3570 字,大约阅读时间需要 11 分钟。

liux7防火墙管理

概述

Redhat Enterprise Linux7已经默认使用firewalld作为防火墙,其使用方式已经变化。基于iptables的防火墙被默认不启动,但仍然可以继续使用。

RHEL7中有几种防火墙共存:firewalld、iptables、ebtables等,默认使用firewalld作为防火墙,管理工具是firewall-cmd。RHEL7的内核版本是3.10,在此版本的内核里防火墙的包过滤机制是firewalld,使用firewalld来管理netfilter,不过底层调用的命令仍然是iptables等。因为这几种daemon是冲突的,所以建议禁用其他几种服务

一 iptables

CentOS7默认的防火墙不是iptables,而是firewalle.

1.1查看iptables 是否启用

[root@pg12m ~]# systemctl status iptables

Unit iptables.service could not be found.

vi /etc/sysconfig/iptables 文件是空的

 

安装iptables

命令:yum install iptables-services

安装完iptales以后

 

[root@pg12m ~]# cat /etc/sysconfig/iptables

# sample configuration for iptables service

# you can edit this manually or use system-config-firewall

# please do not ask us 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 -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

 

[root@pg12m init.d]# systemctl status iptables

● iptables.service - IPv4 firewall with iptables

   Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)

   Active: inactive (dead)

 

 

systemctl start iptables.service #启动

systemctl status iptables.service #查看运行状态

systemctl restart iptables.service #重启

systemctl stop iptables.service #停止

systemctl enable iptables.service #设置开机启动

systemctl disable iptables.service #禁止开机启动

 

二 firewalld

开启firewalld防火墙以后,默认就是出局不受控制,入局受控制。

1 查看防火墙状态

systemctl status firewalld
2 开启与关闭防火墙
systemctl stop firewalld
systemctl start firewalld
3 开启启动与关闭防火墙
systemctl disable firewalld

systemctl enable firewalld

 

4 生效写入配置文件

firewall-cmd --reload  

 

5 查看策略

firewall-cmd --list-all

 

6 添加与移除服务

firewall-cmd --permanent --remove-service=dhcpv6-client

success

permanent ##永久

firewall-cmd –permanent --add-service=dhcpv6-client

success

7   firewall-cmd --set-default-zone=drop  不要使用没有弄明白

firewall-cmd --permanent --zone=drop --change-interface=ens32

是拒绝一切吧 没有确认过

使用之前

firewall-cmd --list-all

public (active)

  target: default

使用之后

firewall-cmd --list-all

drop (active)

  target: DROP

2.1 firewall策略实施

开启防火墙以后查看,目前是开启了允许ssh和 dhcpv6-client服务,

firewall-cmd --list-all

  services: ssh dhcpv6-client

 

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.247.1" port protocol="tcp" port="22" accept"

 

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.247.1" port protocol="tcp" port="5432" accept"

 

firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.31.100" port protocol="tcp" port="22" accept"

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.31.100" port protocol="tcp" port="22" accept"

 

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.247.0/24" port protocol="tcp" port="22" accept"

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.247.0/24" port protocol="tcp" port="5432" accept"

 

firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.247.0/24" port protocol="tcp" port="22" accept"

firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.247.0/24" port protocol="tcp" port="5432" accept"

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

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

 

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

 

 

转载地址:http://uabai.baihongyu.com/

你可能感兴趣的文章
多研究些架构,少谈些框架(2)-- 微服务和充血模型
查看>>
多研究些架构,少谈些框架(3)-- 微服务和事件驱动
查看>>
SQL性能优化梳理
查看>>
微服务架构技术栈
查看>>
想面试进BAT,不得不看的分布式锁,面试题都在这里了!!
查看>>
Redis最常被问到知识点总结
查看>>
这才是微服务拆分的正确姿势,值得学习!
查看>>
MySQL中一条SQL是如何执行的?
查看>>
MySQL的索引是什么?怎么优化?
查看>>
2万字长文包教包会 JVM 内存结构
查看>>
不懂 spring 就彻底放弃 Java 吧!
查看>>
从MySQL高可用架构看高可用架构设计
查看>>
可以秒杀全场的SpringCloud微服务电商实战项目,文档贼全!
查看>>
java架构之路(多线程)synchronized详解以及锁的膨胀升级过程
查看>>
java架构之路(多线程)AQS之ReetrantLock显示锁的使用和底层源码解读
查看>>
百度现场面试:JVM+算法+Redis+数据库!(三面)
查看>>
java架构之路(多线程)JMM和volatile关键字
查看>>
创业感悟:技术兄弟为什么一直没有起来
查看>>
打破技术的认知边界
查看>>
IntelliJ IDEA导入Zookeeper源码
查看>>