RHEL 7中防火墙的配置和使用

1.禁止特定IP访问特定端口
[[email protected]:/root]#firewall-cmd --permanent --zone=public --add-rich-rule ‘rule family="ipv4" source address="10.48.136.18*" port protocol="tcp" port="22" reject‘
success
2.禁止IP段访问指定端口
[[email protected]:/root]#firewall-cmd --permanent --zone=public --remove-rich-rule ‘rule family="ipv4" source address="10.48.136.0/22" port protocol="tcp" port="22" reject‘
3..禁止DMZ网段服务器访问所有端口(包括ping),设置方法如下
[[email protected]:/root]#firewall-cmd --permanent --zone=drop --add-source=10.48.136.0/22
success
[[email protected]:/root]#firewall-cmd --reload
success
4.禁止特定IP访问服务器所有端口
如下禁止10.48.136.180访问该机器
[[email protected]:/root]#firewall-cmd --permanent --zone=drop --add-source=10.48.136.180
success
[[email protected]:/root]#firewall-cmd --reload
success
firewall-cmd --permanent --zone=public --add-rich-rule ‘rule family="ipv4" source address="10.48.136.180" port="22" reject‘

----------------

RHEL7 中使用了firewalld代替了原来的iptables,操作设置和原来有点不同:
查看防火墙状态:systemctl status firewalld
启动防火墙:systemctl start firewalld
停止防火墙:systemctl stop firewalld
 
防火墙中的一切都与一个或者多个区域相关联,下面对各个区进行说明:
Zone                                    Description
-----------------------------------------------------
drop (immutable)                 Deny all incoming connections, outgoing ones are accepted.
block (immutable)                Deny all incoming connections, with ICMP host prohibited messages issued.
trusted (immutable)             Allow all network connections
public                           Public areas, do not trust other computers
external                         For computers with masquerading enabled, protecting a local network
dmz                               For computers publicly accessible with restricted access.  
work                             For trusted work areas
home                             For trusted home network connections
internal                         For internal network, restrict incoming connections
drop(丢弃)
任何接收的网络数据包都被丢弃,没有任何回复。仅能有发送出去的网络连接。
block(限制)
任何接收的网络连接都被 IPv4 的 icmp-host-prohibited 信息和 IPv6 的 icmp6-adm-prohibited 信息所拒绝。
public(公共)
在公共区域内使用,不能相信网络内的其他计算机不会对您的计算机造成危害,只能接收经过选取的连接。
external(外部)
特别是为路由器启用了伪装功能的外部网。您不能信任来自网络的其他计算,不能相信它们不会对您的计算机造成危害,只能接收经过选择的连接。
dmz(非军事区)
用于您的非军事区内的电脑,此区域内可公开访问,可以有限地进入您的内部网络,仅仅接收经过选择的连接。
work(工作)
用于工作区。您可以基本相信网络内的其他电脑不会危害您的电脑。仅仅接收经过选择的连接。
home(家庭)
用于家庭网络。您可以基本信任网络内的其他计算机不会危害您的计算机。仅仅接收经过选择的连接。
internal(内部)
用于内部网络。您可以基本上信任网络内的其他计算机不会威胁您的计算机。仅仅接受经过选择的连接。
trusted(信任)
可接受所有的网络连接。
 
 
操作防火墙的一些常用命令:
--显示防火墙状态
[[email protected] zones]# firewall-cmd --state
running
--列出当前有几个zone
[[email protected] zones]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
--取得当前活动的zones
[[email protected] zones]# firewall-cmd --get-active-zones
public
  interfaces: ens32 veth4103622
--取得默认的zone
[[email protected] zones]# firewall-cmd --get-default-zone
public
--取得当前支持service
[[email protected] zones]# firewall-cmd --get-service           
RH-Satellite-6 amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https
--检查下一次重载后将激活的服务。
[[email protected] zones]# firewall-cmd --get-service --permanent
RH-Satellite-6 amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https
--列出zone public 端口
[[email protected] zones]# firewall-cmd --zone=public --list-ports
--列出zone public当前设置
[[email protected] zones]# firewall-cmd --zone=public --list-all
public (default, active)
  interfaces: eno16777736
  sources:
  services: dhcpv6-client ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
--增加zone public开放http service
[[email protected] zones]# firewall-cmd --zone=public --add-service=http
success
[[email protected] zones]# firewall-cmd --permanent --zone=internal --add-service=http
success
--重新加载配置
[[email protected] zones]# firewall-cmd --reload
success
--增加zone internal开放443/tcp协议端口
[[email protected] zones]# firewall-cmd --zone=internal --add-port=443/tcp
success
--列出zone internal的所有service
[[email protected] zones]# firewall-cmd --zone=internal --list-services
dhcpv6-client ipp-client mdns samba-client ssh
设置黑/白名单
--增加172.28.129.0/24网段到zone trusted(信任)
[[email protected] zones]# firewall-cmd --permanent --zone=trusted --add-source=172.28.129.0/24
success
--列出zone truste的白名单
[[email protected] zones]# firewall-cmd --permanent --zone=trusted --list-sources
172.28.129.0/24
--活动的zone
[[email protected] zones]# firewall-cmd --get-active-zones
public
  interfaces: eno16777736
--添加zone truste后重新加载,然后查看--get-active-zones
[[email protected] zones]# firewall-cmd --reload          
success
[[email protected] zones]# firewall-cmd --get-active-zones
public
  interfaces: ens32 veth4103622
trusted
  sources: 172.28.129.0/24
--列出zone drop所有规则
[[email protected] zones]# firewall-cmd --zone=drop --list-all
drop
  interfaces:
  sources:
  services:
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
--添加172.28.13.0/24到zone drop
[[email protected] zones]# firewall-cmd --permanent --zone=drop --add-source=172.28.13.0/24
success
--添加后需要重新加载
[[email protected] zones]# firewall-cmd --reload
success
[[email protected] zones]# firewall-cmd --zone=drop --list-all
drop
  interfaces:
  sources: 172.28.13.0/24
  services:
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
[[email protected] zones]# firewall-cmd --reload
success
--从zone drop中删除172.28.13.0/24
[[email protected] zones]# firewall-cmd --permanent --zone=drop --remove-source=172.28.13.0/24
success
--查看所有的zones规则
[[email protected] ~]# firewall-cmd --list-all-zones
 
 
最后再提几点:
1、很多时候我们需要开放端口或开放某IP访问权限,我们需要先查看我们当前默认的zone是哪个,然后在对应的zone里面添加port和source,这样对外才会有作用。
     比如我当前的默认zone是public,我需要开放80端口对外访问,则执行如下命令:
     [[email protected] zones]# firewall-cmd --zone=public --permanent --add-port=80/tcp
     success
     [[email protected] zones]# firewall-cmd --reload
     success
2、使用命令的时候加上 --permanent 是永久生效的意思,在重启防火墙服务后依然生效。否则,只对重启服务之前有效。
3、我们执行的命令,结果其实都体现在具体的配置文件中,其实我们可以直接修改对应的配置文件即可。
      以public zone为例,对应的配置文件是/etc/firewalld/zones/public.xml,像我们刚刚添加80端口后,体现在public.xml 中的内容为:
     [[email protected] zones]# cat 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="dhcpv6-client"/>
       <service name="ssh"/>
       <port protocol="tcp" port="80"/>
     </zone>
     这个大家可自己再进一步了解下配置文件的结构后,进行自行配置,不过记得要在配置后 --reload 或重启 firewall 服务。

时间: 2024-08-05 11:13:58

RHEL 7中防火墙的配置和使用的相关文章

烂泥:FTP服务器开启防火墙相关配置

本文首发于烂泥行天下. 由于工作需要公司最近的一台服务器需要开启启用FTP服务,用来传输文件. 但是考虑到该服务器是在公网,基于安全的考虑一般都是要开启防火墙的.而公司内部的FTP服务器,一般情况下我都是关闭防火墙的. 下面我就将有关防火墙的配置流出如下: OS:windows server 2003.2008 FTP:Filezilla Server 0.9.41 首先是安装FTP服务器,在此我使用时开源FTP服务器Filezill Server.有关Filezilla Server的安装与使

Oracle10g/11g 在SUSE/RHEL上的安装与配置

在过去对众多项目的支撑过程中,Oracle作为首选数据库,其安装与配置过程成了重复性最多的工作之一.在此,我进行了总结,并分享出来,希望能对大家有所帮助.随着Oracle版本的提升,从9i ->10g ->11g,其安装与配置过程其实越来越简单,尤其到了11g,会自动检测所缺少的系统软件包,并在系统参数配置方面进行自动调优. 在Linux下Oracle的安装配置过程我认为可分为三大步:第一步 预安装的环境参数配置在Windows下没有这一步,因为已经由安装程序直接完成了,Linux下目前也有相

CentOS-7.0.中安装与配置Tomcat-7的方法

安装说明 安装环境:CentOS-7.0.1406 安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz 下载地址:http://tomcat.apache.org/download-70.cgi 安装前提 系统必须已安装配置JDK6+,安装请参考:在CentOS-6.3中安装与配置JDK-7. 安装tomcat 将apache-tomcat-7.0.29.tar.gz文件上传到/usr/local中执行以下操作: 代码如下: [plain] view plainco

firewalld防火墙的配置及应用

            防火墙(centos7)的配置及应用 1:防火墙有基本的三类 iptables.firewalld.ip6tables Systemctl   status   {firewalld,iptables,ip6tables}  查看三类的状态,这里主要介绍firewalld防火墙的配置以及基本应用功能 2:firewalld提供支持区域定义网络连接的防火墙 3:拥有运行时配置和永久性配置(临时和永久性配置) 4:之前是静态,现在是动态,不用重新启动防火墙,不用卸载防火墙的模

sqlserver2008链接服务器中执行存储过程配置过程

参考:http://www.cnblogs.com/ycsfwhh/archive/2010/12/15/1906507.html 1.双方启动MSDTC服务MSDTC(分布式交易协调器),协调跨多个数据库.消息队列.文件系统等资源管理器的事务.该服务的进程名为Msdtc.exe,该进程调用系统Microsoft Personal Web Server和Microsoft SQL Server.该服务用于管理多个服务器 .位置:控制面板--管理工具--服务--Distributed Transa

山石网科防火墙图形配置

在我公司众多的项目中都会要求配置防火墙,这篇文章将为大家简单的介绍如何通过图形化界面配置硬件防火墙,后续还会增加一些其它关于防火墙的内容.比如高可用.用命令如何配置等. 做任何事情都是讲究思路的,那么配置防火墙的思路有哪些呢?我给大家简单的梳理一下.   基本思路:接口地址.地址簿.服务簿.NAT.网关.策略   详细思路:内网接口地址.外网接口地址.地址簿.服务.服务组.源NAT.网关(路由).策略.目的NAT 1.配置接口地址 (1).外网接口地址(端口可任意) (2).内网接口地址(端口可

华为USG防火墙基本配置

USG防火墙基本配置 学习目的 掌握登陆USG防火墙的方法 掌握修改防火墙设备名的方法 掌握对防火墙的时间.时区进行修改的方法 掌握修改防火墙登陆标语信息的方法 掌握修改防火墙登陆密码的方法 掌握查看.保存和删除防火墙配置的方法 掌握在防火墙上配置vlan.地址接口.测试基本连通性的方法 拓扑图 学习任务 步骤一.登陆缺省配置的防火墙并修改防火墙的名称 防火墙和路由器一样,有一个Console接口.使用console线缆将console接口和计算机的com口连接在一块.使用windows操作系统

Eclipse中Maven的配置

Maven 的配置 1. 安装配置Maven: 1.1 从Apache网站 http://maven.apache.org/ 下载并且解压缩安装Apache Maven 1.2 配置 Maven 的conf文件夹中配置文件settings.xml. 1.3 修改settings.xml,添加镜像服务器设置: 阿里云Maven镜像服务器配置: 修改settings.xml文件, 添加阿里云镜像服务器配置信息: 2. Eclipse中Maven的配置: 最新版的Eclipse已经内嵌了Mevne插件

RHEL系列多个bond配置区分

1.  RHEL4多bond配置 系统版本:Red Hat Enterprise Linux AS release 4 (Nahant Update 6) 网卡数量:4块 添加两个bond配置文件(以bond0为例): [[email protected]~]# cd /etc/sysconfig/network-scripts/ [[email protected]]# cp ifcfg-eth0 ifcfg-bond0 [[email protected]]# vim ifcfg-bond0