红帽官方的使用文档:

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html

常用命令

# 查看版本
[root@osboxes java]# firewall-cmd --version
0.3.
# 查看状态
[root@osboxes java]# systemctl status firewalld.service
OR
[root@osboxes java]# firewall-cmd --state
running
# 获取启用的zone
[root@osboxes java]# firewall-cmd --get-active-zones
public
interfaces: eno16777984

修改网卡的zone

firewall-cmd --permanent --zone=external --change-interface=eth0
firewall-cmd --permanent --zone=internal --change-interface=eth1

查看指定zone中开放的端口和服务

[root@osboxes java]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eno16777984
sources:
services: dhcpv6-client mdns ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:

查看系统中可用的服务

# 列出已配置好可用的服务, 位于 /usr/lib/firewalld/services/ 下
[root@osboxes java]# firewall-cmd --get-services
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 # 强制列出包含用户设置在/etc/firewalld/services/, 但尚未loaded的服务
[root@osboxes java]# firewall-cmd --get-services --permanent
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添加端口

# 不要忘记 --permanent
[root@osboxes java]# firewall-cmd --zone=public --add-port=/tcp --permanent
# OR 添加一个地址段
[root@osboxes java]# firewall-cmd --zone=public --add-port=5060-5061/udp --permanent
success
# 需要reload后才启用, 热加载
[root@osboxes java]# firewall-cmd --reload
# OR 冷加载
[root@osboxes java]# firewall-cmd --complete-reload
success
# 能看到新端口已经添加
[root@osboxes java]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eno16777984
sources:
services: dhcpv6-client mdns ssh
ports: /tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
# 删除一个端口
firewall-cmd --permanent --zone=public --remove-port=8080/tcp
firewall-cmd --permanent --zone=public --remove-port=8080/udp

添加服务(默认端口)

firewall-cmd --zone=public  --add-service=ftp --permanent

添加NAT

首先要加上ip forward

vim /etc/sysctl.conf
net.ipv4.ip_forward = 1

打开IP伪装

firewall-cmd --zone=external --add-masquerade --permanent

.内网其他机器, 要把网关配置为当前服务器

#设置网关
route add default gw 192.168.100.1 #或修改/etc/sysconf/network/network-scripts/ifcfg-网卡名

.

添加端口转发

首先要打开IP伪装

firewall-cmd --zone=external --query-masquerade # 检查是否允许伪装IP
firewall-cmd --zone=external --add-masquerade # 允许防火墙伪装IP, 记得加上 --permanent
firewall-cmd --zone=external --remove-masquerade# 禁止防火墙伪装IP

配置端口转发, 转本机端口, 转他机端口. 未填toaddr则默认本机, 未填toport则使用相同端口

# 将80端口的流量转发至8080
firewall-cmd --zone=external --add-forward-port=port=80:proto=tcp:toport=8080
# 将80端口的流量转发至
firewall-cmd --zone=external --add-forward-port=port=80:proto=tcp:toaddr=192.168.1.0.1
# 将80端口的流量转发至192.168.0.1的8080端口
firewall-cmd --zone=external --add-forward-port=port=80:proto=tcp:toaddr=192.168.0.1:toport=8080

.

Centos7的firewalld配置的更多相关文章

  1. Centos7 防火墙firewalld配置

    开启80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent  出现success表明添加成功 移除某个端口 firewall-cmd ...

  2. CentOS7使用firewalld打开关闭防火墙与端口(转载)

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...

  3. Centos7中hadoop配置

    Centos7中hadoop配置 1.下载centos7安装教程: http://jingyan.baidu.com/article/a3aad71aa180e7b1fa009676.html (注意 ...

  4. 关于学习CentOS7使用firewalld打开关闭防火墙和端口

    1.firewalld简介 firewalld是centos7的一大特点,主要有两个优点:一是支持动态更新,不需要重启服务:二就是加入了防火墙的“zone”概念. firewalld有图形界面和工具界 ...

  5. Centos7 Openldap主从配置

    转载 https://blog.csdn.net/htvxjl02/article/details/80336788 Centos7 Openldap主从配置 2018年05月16日 15:09:57 ...

  6. CentOS7安装和配置vsftpd

    (1)vsftpd基本介绍 作用:实现文件共享 1)vsftpd两种模式 主动模式 所谓主动模式,指的是FTP服务器"主动"去连接客户端的数据端口来传输数据,其过程具体来说就是:客 ...

  7. 5分钟理解Centos7防火墙firewalld

    版权声明:本内容为原创内容,转载请声明出处. 原文地址:http://www.excelib.com/article/287/show firewalld简介 Centos7中默认将原来的防火墙ipt ...

  8. CentOS7中firewalld的安装与使用详解

    一.软件环境 [root@Geeklp201 ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 二.安装firewall ...

  9. CentOS7使用firewalld防火墙

    firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status fir ...

随机推荐

  1. ProxyPattern

    代理模式是aop编程的基础,其主要作用是操作对象,并将你需要的新功能切入若干个你想要的切入点,静态代理模式比较简单,但是缺点比较大,这里就不上代码了,下面写上动态代理模式的代码(jdk方式,而不是采用 ...

  2. 1、ASP.NET MVC入门到精通——新语法

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 在学习ASP.NET MVC之前,有必要先了解一下C#3.0所带来的新的语法特性,这一点尤为重要,因为在MVC项目中我们利用C#3.0的新特 ...

  3. JSP利用Hibernate实现对数据库的CRUD ——开发环境Myeclipse与SQL Server 2008

    一.首先先建立一个Web Project 二.然后在程序根目录建立文件夹“DataBase”和“Doc”,分别存放数据库文件和保存SQL语句,建完如下所示: 三.建立数据库“dbHibernate”, ...

  4. placeholder不兼容 IE10 以下版本的解决方法

    对于密码输入框placeholder的兼容问题:HTML代码:<input type="password" id="loginPassword" plac ...

  5. Json解析,Json-lib

    网络资源参考 http://www.json.org/json-zh.html http://code.alibabatech.com/wiki/pages/viewpage.action?pageI ...

  6. Android开发1:基本UI界面设计——布局和组件

    前言 啦啦啦~本学期要开始学习Android开发啦~ 博主在开始学习前是完完全全的小白,只有在平时完成老师要求的实验的过程中一步一步学习~从此篇博文起,博主将开始发布Android开发有关的博文,希望 ...

  7. Civil 3D API二次开发学习指南

    Civil 3D构建于AutoCAD 和 Map 3D之上,在学习Civil 3D API二次开发之前,您至少需要了解AutoCAD API的二次开发,你可以参考AutoCAD .NET API二次开 ...

  8. 好用的第三方控件,Xcode插件(不断更新)

    第三方控件类:   1.提示框 MBProgressHUD: 是一款非常强大的.提供多种样式的提示框.使用起来简单.方便.可以在GitHub上查看具体的使用方法. https://github.com ...

  9. RecyclerView-------MyAdapter代码

    package com.example.administrator.recyclerview; import android.content.Context; import android.suppo ...

  10. Shou 团队诚意满满的招募 Swifter

    一.团队介绍 团队产品 VPlayer 播放器靠自增长 3 年内获得全球 4000 万用户,开发的 Vitamio 组件更是获得微博.UC.金山等知名企业授权使用.—— 团队再次起航,经历一年多我们已 ...