当前位置: 移动技术网 > 科技>操作系统>Linux > Centos7 关于防火墙的一些简单配置

Centos7 关于防火墙的一些简单配置

2018年10月13日  | 移动技术网科技  | 我要评论

聚乙二醇2000,菲律宾暴力禁毒运动,恋爱大赢家演员表

近期安装了linux系统centos7,接触下来发现了与原来的centos6.5有一些差别,这里主要记录下来我的一些关于centos7防火墙的了解。

一、firewall简介

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

 

在centos中的图形化界面打开的firewall界面如上所示,可以看到在其中有“区域”、“服务”、“ipsets”,在“区域”下面有“block”、“dmz”....一些,这些每一个又有图上的右面“服务”,“端口”,“协议”.....

the dynamic firewall daemon firewalld provides a dynamically managed firewall with support for network “zones” to assign a level of trust to a network and its associated connections and interfaces. it has support for ipv4 and ipv6 firewall settings. it supports ethernet bridges and has a separation of runtime and permanent configuration options. it also has an interface for services or applications to add firewall rules directly.
网络区域定义了网络连接的可信等级,具体的请参考官网。

二、firewall配置

  1.系统配置目录

 

/usr/lib/firewalld/ 

[root@localhost firewalld]# ls
helpers icmptypes ipsets services xmlschema zones

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

  2.用户配置目录

 

/etc/firewalld/

  

  3.1自定义配置端口开放

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

 

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

  #注意重新加载firewall
  firewall-cmd --reload

  参数的介绍:

  1、firewall-cmd:是linux提供的操作firewall的一个工具;
  2、--permanent:表示设置为持久;
  3、--add-port:标识添加的端口;

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

  firewall-cmd --zone=public --permanent --add-port=8010/tcp
  --zone=public:指定的zone为public;

  添加之后在 vim /etc/firewalld/zones/public.xml  中的结果如下所示:

如果–zone=dmz 这样设置的话,会在dmz.xml文件中新增所配置的端口。

3.2修改配置文件的方式配置端口开放

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <zone>
 3   <short>public</short>
 4   <description>for use in public areas.</description>
 5   <rule family="ipv4">
 6     <source address="122.10.70.234"/>
 7     <port protocol="udp" port="514"/>
 8     <accept/>
 9   </rule>
10   <rule family="ipv4">
11     <source address="123.60.255.14"/>
12     <port protocol="tcp" port="10050-10051"/>
13     <accept/>
14   </rule>
15  <rule family="ipv4">
16     <source address="192.249.87.114"/> 放通指定ip,指定端口、协议
17     <port protocol="tcp" port="80"/>
18     <accept/>
19   </rule>
20 <rule family="ipv4"> 放通任意ip访问服务器的9527端口
21     <port protocol="tcp" port="9527"/>
22     <accept/>
23   </rule>
24 </zone>

  上面的配置文件理解为:

1、添加需要的规则,开放通源ip为122.10.70.234,端口514,协议udp; 
2、开放通源ip为123.60.255.14,端口10050-10051,协议tcp;
3、开放通源ip为192.249.87.144,端口为80,洗衣为tcp;与上一个相同;
4、开放通源ip为任意,端口9527,协议tcp;

  三、firewall常用命令

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

service firewalld restart 重启
service firewalld start 开启
service firewalld stop 关闭

  2、查看firewall服务状态

  systemctl status firewall 

 

3、查看firewall的状态

  firewall-cmd --state

4、查看防火墙规则

  firewall-cmd --list-all 

   5、查询、开放、关闭端口

# 查询端口是否开放
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:表示添加的端口;

 

 

 


本文参考:

https://blog.csdn.net/xlgen157387/article/details/52672988

https://www.cnblogs.com/xxoome/p/7115614.html

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网