美文网首页
centos7防火墙

centos7防火墙

作者: 芒果奶油卷 | 来源:发表于2020-08-16 22:08 被阅读0次

centos对firewall的文档

1.firewall介绍

CentOS 7中防火墙是一个非常的强大的功能,在CentOS 6.5中在iptables防火墙中进行了升级了。

什么是区域Zone:

网络区域定义了网络连接的可信等级。这是一个 一对多的关系,这意味着一次连接可以仅仅是一个区域的一部分,而一个区域可以用于很多连接。

哪个区域可用?

由firewalld 提供的区域按照从不信任到信任的顺序排序。

区域的分类?

drop;block;public;external;dmz;work;home;internal;trusted

2.firewall配置

firewalld 的操作只有重启之后才有效:service firewalld restart 重启

系统配置目录

/usr/lib/firewalld/services

目录中存放定义好的网络服务和端口参数,系统参数,不能修改。

用户配置目录

/etc/firewalld/

3.自定义添加端口

用户可以通过修改配置文件的方式添加端口,也可以通过命令的方式添加端口,修改的内容会在/etc/firewalld/目录下的配置文件中还体现

命令的方式添加端口

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

1、firewall-cmd:是Linux提供的操作firewall的一个工具;

2、--permanent:表示设置为持久;

3、--add-port:标识添加的端口;

firewall中有Zone的概念,可以将具体的端口制定到具体的zone配置文件中。

例如:添加8010端口

firewall-cmd   --zone=public  --permanent   --add-port=8010/tcp

--zone=public:指定的zone为public;

修改配置文件的方式添加端口

<?xml version="1.0" encoding="utf-8"?>

<zone>

  <short>Public</short>

  <description>For use in public areas.</description>

  <rule family="ipv4">

    <source address="122.10.70.234"/>

    <port protocol="udp" port="514"/>

    <accept/>

  </rule>

  <rule family="ipv4">

    <source address="123.60.255.14"/>

    <port protocol="tcp" port="10050-10051"/>

    <accept/>

  </rule>

<rule family="ipv4">

    <source address="192.249.87.114"/> 放通指定ip,指定端口、协议

    <port protocol="tcp" port="80"/>

    <accept/>

  </rule>

<rule family="ipv4"> 放通任意ip访问服务器的9527端口

    <port protocol="tcp" port="9527"/>

    <accept/>

  </rule>

</zone>

1、添加需要的规则,开放通源ip为122.10.70.234,端口514,协议tcp;

2、开放通源ip为123.60.255.14,端口10050-10051,协议tcp;/3、开放通源ip为任意,端口9527,协议tcp;

修改完后

systemctl restart firewalld.service   #重启

firewall-cmd --reload;    #命令重载

4.firewall常用命令

重启、关闭、开启firewalld.service服务

servicefirewalld restart 重启

servicefirewalld start 开启

servicefirewalld stop 关闭

查看firewall服务状态

systemctl status firewall

查看firewall的状态

firewall-cmd--state

查看防火墙规则

firewall-cmd  --list-all

5.CentOS切换为iptables防火墙

切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务

关闭firewall

service firewalld stop    

systemctl disable firewalld.service#禁止firewall开机启动

停止并屏蔽firewalld服务

systemctl stop firewalld

systemctl mask firewalld  锁定服务

安装iptables防火墙

yum  install   iptables-services#安装

启用iptables服务

systemctl enable iptables

启动iptables服务

systemctl start iptables

编辑iptables防火墙配置

vim    /etc/sysconfig/iptables #编辑防火墙配置文件

Firewall configuration written by system-config-firewall

Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

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

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT   新加的内容

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

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

COMMIT

保存防火墙规则

service iptables save

/usr/libexec/iptables/iptables.init save

停止、启动,重启防火墙

systemctl [stop|start|restart] iptables

service iptables start #开启

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

重启一下防火墙 

 systemctl restart iptables 

 或者 

 service iptables restart

查看防火墙端口情况

iptables -L -n

6.其他

查看对外开放的端口状态

netstat -anp

查询指定端口是否已开 

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

移除指定端口:

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

7.端口配置实战

#放行8080端口

firewall-cmd  --zone=public  --add-port=8080/tcp  --permanent

#重启防火墙

firewall-cmd  --reload

相关文章

  • linux命令

    centos7启动防火墙 centos7停止防火墙/关闭防火墙 centos7重启防火墙 注意:新增/删除操作需要...

  • CentOS7防火墙设置

    CentOS7 与之前版本在防火墙配置上不同,防火墙从iptables变成了firewalld Centos7默认...

  • Linux常用命令

    CentOS7 防火墙增加端口

  • Linux使用-FAQ

    CentOS7 关闭防火墙 参考:CentOS7 关闭防火墙 在我的虚拟机下启动服务 进程管理 文件管理 查看日志...

  • centos7关闭防火墙

    centos7 默认防火墙是firewalld 所以查看防火墙状态命令:systemctl status ...

  • linux防火墙查看状态firewall、iptable

    CentOS7 的防火墙配置跟以前版本有很大区别,CentOS7这个版本的防火墙默认使用的是firewall,与之...

  • CentOS 7.2 关闭防火墙

    CentOS7 的防火墙配置跟以前版本有很大区别,CentOS7这个版本的防火墙默认使用的是firewall,与之...

  • Linux防火墙命令

    CentOS7 的防火墙配置跟以前版本有很大区别,CentOS7这个版本的防火墙默认使用的是firewall,与之...

  • centos7和centos6的防火墙关闭命令

    CentOS7的防火墙配置跟以前版本有很大区别,CentOS7这个版本的防火墙默认使用的是firewall,与之前...

  • linux服务器常用

    Centos7 打开80端口防火墙命令

网友评论

      本文标题:centos7防火墙

      本文链接:https://www.haomeiwen.com/subject/ctvxjktx.html