红帽官方的使用文档:

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. iOS--使用UIImageView进行GIF动图播放

    大家好,好久没有跟新了.其实也就昨天到今天的时间. 前言:实际上,GIF动图文件中包含了一组图片及其信息数组,这些信息数据记录着这一组图片中各张图片的播放时长等信息,我们可以将图片和这些信息或取出来, ...

  2. hdu-1179-二分图最大匹配

    Ollivanders: Makers of Fine Wands since 382 BC. Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  3. 股指的趋势持续研究(Hurst指数)

    只贴基本的适合小白的Matlab实现代码,深入的研究除了需要改进算法,我建议好好研究一下混沌与分形,不说让你抓住趋势,至少不会大亏,这个资金盈亏回调我以前研究过. function [line_H,R ...

  4. 缓存、队列(Memcached,Redis,rabbitMQ)

    一.Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的 ...

  5. iOS 怎么设置 UITabBarController 的第n个item为第一响应者?

    iOS 怎么设置 UITabBarController 的第n个item为第一响应者? UITabBarController 里面有个属性:selectedIndex @property(nonato ...

  6. 在Linux上使用Nginx为Solr集群做负载均衡

    在Linux上使用Nginx为Solr集群做负载均衡 在Linux上搭建solr集群时需要用到负载均衡,但测试环境下没有F5 Big-IP负载均衡交换机可以用,于是先后试了weblogic的proxy ...

  7. 【代码笔记】iOS-可以向左(右)滑动

    一,效果图. 二,代码. RootViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional se ...

  8. Linux配置环境报“/usr/local/develop-tools/apache-maven-3.3.9/bin: 是一个目录“的解决方案

    安装Maven中 配置系统环境变量: # vi + profile M2_HOME=/usr/local/develop-tools/apache-maven- export M2_HOME PATH ...

  9. TNS-12518 & Linux Error:32:Broken pipe

    最近一周,有一台ORACLE数据库服务器的监听服务在凌晨2点过几分的时间点突然崩溃,以前从没有出现过此类情况,但是最近一周出现了两次这种情况,检查时发现了如下一些信息: $ lsnrctl servi ...

  10. 服务器文件上传下载(XShell+Xftp)

    1.下载XShell安装包+Xftp安装包.百度网盘(XShell):https://pan.baidu.com/s/1eR4PFpS 百度网盘(Xftp):https://pan.baidu.com ...