Note
  • Introduction
  • JS
    • JS / JQuery 代码、框架收藏
    • 用Mock.js + AngularJS来提高开发效率
    • 在JavaScript中监听 IME 键盘输入事件
    • 如何组织大型JavaScript应用中的代码?
    • 深入理解javascript原型和闭包
      • 1. 一切都是对象
      • 2. 函数和对象的关系
      • 3. prototype原型
      • 4. 隐式原型
      • 5. instanceof
      • 6. 继承
      • 7. 原型的灵活性
      • 8. 简述【执行上下文】上
      • 9. 简述【执行上下文】下
      • 10. this
      • 11. 执行上下文栈
      • 12. 简介【作用域】
      • 13. 【作用域】和【上下文环境】
      • 14. 从【自由变量】到【作用域链】
      • 15. 闭包
      • 16. 补充:上下文环境和作用域的关系
    • AngularJS
      • AngularJS开发一些经验总结
      • AngularJS Controller 间通信机制
      • AngularJS 中的一些坑
      • 如何解决AngularJs在IE下取数据总是缓存的问题
      • AngularJS之$timeout指令
      • angular 代码日记
      • AngularJS Directive 隔离 Scope 数据交互
      • 在Angular指令中使用NgModelController做数据绑定
      • AngularJS的ngTransclude
      • 使用Angularjs的ng-cloak指令避免页面乱码
      • Directive - Compile vs. Link
    • NodeJS
      • npm的配置管理及设置代理
    • Angular
      • Angular2 - Control Validation on blur
      • Angular2 - how to call component function from outside the app
  • Go
    • How to Test Local Changes with Go Mod
  • Java
    • Java中根据字体得到字符串高度和长度
    • JAVA 判断一个字符串是不是一个合法的日期格式
    • JVM上的随机数与熵池策略
    • tomcat7+jdk的keytool生成证书 配置https
    • Spring
      • SpringMVC中用@ParamVariable传递的参数包含斜杠(/)时,匹配不了报404错误的解决方案
      • SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题
      • Spring Boot 打包,分离依赖jar,配置文件
      • SpringBoot启动后 Stopping service [Tomcat]
      • spring-boot打包时排除第三方依赖
    • 第一个Eclipse插件
    • Eclipse 使用技巧
    • HighChart利用servlet导出中文PNG图片乱码问题解决
    • JDK中文字体在Linux操作系统的设置方案
    • Shiro
      • Shiro-Authentication(身份验证)
      • Shiro-Authorization(授权)
    • 详谈再论JAVA获取本机IP地址
  • Python
    • pip国内镜像源的配置
  • Linux
    • Shell脚本 bad interpreter:No such file or directory & /bin/bash^M: bad interpreter错误解决方法
    • 10个重要的Linux ps命令实战
    • Linux 下执行定时任务 crontab 命令详解
    • CentOS 7.x设置自定义开机启动,添加自定义系统服务
    • CentOS 7 下使用 Firewall
    • 在Ubuntu 12.04安装和设置SSH服务
    • 配置CENTOS YUM更新源
    • Linux下终端利器tmux
    • scp命令
    • Linux系统管理常用命令
    • 让你提升命令行效率的 Bash 快捷键 [完整版]
    • SELinux
    • Linux下 RabbitMQ的安装与配置
    • SELinux下更改mysql端口
    • centos 7 升级后yum install出现Exiting on user cancel
    • Linux Shell 通配符、元字符、转义符使用实例介绍
  • Other
    • Docker
      • Docker Proxy
    • Swagger
      • Spring MVC 集成 Swagger
    • Maven
      • maven plugin的execution出错
      • nexus repair或update index 没反应 速度慢 手动配置nexus index
      • nexus 搭建 maven 私服
      • Maven类包冲突终极解决小技若干
      • org.codehaus.plexus.archiver.jar.Manifest.merge(org.codehaus.plexus.archiver.jar.Manifest)
      • Maven 生命周期
      • wagon-maven-plugin
      • Maven中-DskipTests和-Dmaven.test.skip=true的区别
    • MySQL
      • is not allowed to connect to this MySQL server 解决办法
      • MySQL备份--mysql dump
      • MySQL启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes 的问题
      • MySQL修改root密码的多种方法
      • MySQL长事务导致的Table Metadata Lock
      • com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
      • 解决mysql插入数据时出现Incorrect string value: '\xF0\x9F...' for column 'name' at row 1的异常
    • HTTP
      • HTTP 协议中的 Transfer-Encoding
      • 四种常见的 POST 提交数据方式
      • HTTP 请求头中的 X-Forwarded-For
      • 传统轮询、长轮询、服务器发送事件与WebSocket
    • Raspberry
      • 系统安装配置
    • VIM
      • vim常用配置
      • 在vim中使用查找命令查找指定字符串
      • Vim缩进有关的设置总结
    • Git
      • github 同步一个 fork
      • Git 如何 clone 非 master 分支的代码
      • git提示error setting certificate verify locations解决办法
      • git设置和取消代理
      • How to Delete Commit History in Github
      • Windows下使用Beyond Compare作为git的比对与合并工具
    • 解决 Virtualbox 共享文件夹 cannot create symlink error 问题
    • nginx 403 forbidden 二种原因
    • VirtualBox的四种网络连接方式
    • 在Windows的CMD中如何设置支持UTF8编码?
    • nginx使用ssl模块配置HTTPS支持
    • 怎么查看WINDOWS端口被哪个程序占用
    • VMWare 随系统启动指定虚拟机
    • 使用命令行启动VirtualBox虚拟机
    • 该死的^M
    • install home-assistant mosquitto-broker and node-red on android
    • SSH原理与运用:远程登录、远程操作与端口转发
    • SVN mime-type 笔记
    • VirtualBox虚拟机网络配置(NAT + Host-only - Bridged)
    • VirtualBox绿色版的桥接网卡驱动安装
    • OAuth的改变
    • MavenActionUtil.getMavenProject(e.getDataContext()) is Null when developing a intellij plugin
    • Cygwin的安装和配置apt-cyg源
    • Zookeeper运维常用四字命令
    • svn sqlite[S11]: database disk image is malformed
Powered by GitBook
On this page
  • 一、介绍
  • 二、使用方法
  • 1. 查看规则
  • 2. 管理规则

Was this helpful?

  1. Linux

CentOS 7 下使用 Firewall

在 CentOS 7 中,引入了一个新的服务,Firewalld,下面一张图,让大家明确的了解 Firewall 与 iptables 之间的关系与区别。

安装它,只需 yum install firewalld 如果需要图形界面的话,则再安装 yum install firewall-config

一、介绍

防火墙守护 firewalld 服务引入了一个信任级别的概念来管理与之相关联的连接与接口。它支持 ipv4 与 ipv6,并支持网桥,采用 firewall-cmd (command) 或 firewall-config (gui) 来动态的管理 kernel netfilter 的临时或永久的接口规则,并实时生效而无需重启服务。

Firewall 能将不同的网络连接归类到不同的信任级别,Zone 提供了以下几个级别

  • drop: 丢弃所有进入的包,而不给出任何响应

  • block: 拒绝所有外部发起的连接,允许内部发起的连接

  • public: 允许指定的进入连接

  • external: 同上,对伪装的进入连接,一般用于路由转发

  • dmz: 允许受限制的进入连接

  • work: 允许受信任的计算机被限制的进入连接,类似 workgroup

  • home: 同上,类似 homegroup

  • internal: 同上,范围针对所有互联网用户

  • trusted: 信任所有连接

二、使用方法

# systemctl start firewalld         # 启动,
# systemctl enable firewalld        # 开机启动
# systemctl stop firewalld          # 关闭
# systemctl disable firewalld       # 取消开机启动

具体的规则管理,可以使用 firewall-cmd,具体的使用方法可以 firewall-cmd --help

1. 查看规则

查看运行状态 firewall-cmd --state 查看已被激活的 Zone 信息 firewall-cmd --get-active-zones 查看指定接口的 Zone 信息 firewall-cmd --get-zone-of-interface=eth0 查看指定级别的接口 firewall-cmd --zone=public --list-interfaces 查看指定级别的所有信息,譬如 public firewall-cmd --zone=public --list-all 查看所有级别被允许的信息 firewall-cmd --get-service 查看重启后所有 Zones 级别中被允许的服务,即永久放行的服务 firewall-cmd --get-service --permanent

2. 管理规则

# firewall-cmd --panic-on           # 丢弃
# firewall-cmd --panic-off          # 取消丢弃
$ firewall-cmd --query-panic        # 查看丢弃状态
# firewall-cmd --reload             # 更新规则,不重启服务
# firewall-cmd --complete-reload    # 更新规则,重启服务

添加某接口至某信任等级,譬如添加 eth0 至 public,再永久生效 firewall-cmd --zone=public --add-interface=eth0 --permanent 设置 public 为默认的信任级别 firewall-cmd --set-default-zone=public

a. 管理端口 列出 dmz 级别的被允许的进入端口 firewall-cmd --zome=dmz --list-ports 允许 tcp 端口 8080 至 dmz 级别 firewall-cmd --zone=dmz --add-port=8080/tcp 允许某范围的 udp 端口至 public 级别,并永久生效 firewall-cmd --zome=public --add-port=5060-5059/udp --permanent

b. 管理服务 添加 smtp 服务至 work zone firewall-cmd --zone=work --add-service=smtp 移除 work zone 中的 smtp 服务 firewall-cmd --zone=work --remove-service=smtp

c. 配置 ip 地址伪装 查看 firewall-cmd --zone=external --query-masquerade 打开伪装 firewall-cmd --zone=external --add-masquerade 关闭伪装 firewall-cmd --zone=external --remove-masquerade

d. 端口转发 要打开端口转发,则需要先 firewall-cmd --zone=external --add-masquerade 然后转发 tcp 22 端口至 3753 firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=3753 转发 22 端口数据至另一个 ip 的相同端口上 firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100 转发 22 端口数据至另一 ip 的 2055 端口上 firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100

e. IP 封禁 firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.222' reject"

以上都是一些常用方法,更多高级方法,请参考:

PreviousCentOS 7.x设置自定义开机启动,添加自定义系统服务Next在Ubuntu 12.04安装和设置SSH服务

Last updated 5 years ago

Was this helpful?

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