firewalld


FirewallD 使用服务service 和区域zone来代替 iptables 的规则rule和链chain,默认情况下,有以下的区域zone可用:

  1. drop – 丢弃所有传入的网络数据包并且无回应,只有传出网络连接可用。
  2. block — 拒绝所有传入网络数据包并回应一条主机禁止的 ICMP 消息,只有传出网络连接可用。
  3. public — 只接受被选择的传入网络连接,用于公共区域。
  4. external — 用于启用了地址伪装的外部网络,只接受选定的传入网络连接。
  5. dmz — DMZ 隔离区,外部受限地访问内部网络,只接受选定的传入网络连接。
  6. work — 对于处在你工作区域内的计算机,只接受被选择的传入网络连接。
  7. home — 对于处在你家庭区域内的计算机,只接受被选择的传入网络连接。
  8. internal — 对于处在你内部网络的计算机,只接受被选择的传入网络连接。
  9. trusted — 所有网络连接都接受。

   列出默认的区

firewall-cmd --get-default-zone
public

  改变默认的区

 firewall-cmd --set-default-zone=dmz

   为 dmz 区添加持久性的 HTTP 和 HTTPS 规则:

 firewall-cmd --zone=dmz --add-service=http --permanent

firewall-cmd --zone=dmz --add-service=https --permanent

  为 dmz 区添加持久性的 HTTP 和 HTTPS 规则:

firewall-cmd --zone=dmz --add-service=http --permanent

firewall-cmd --zone=dmz --add-service=https --permanent  

  开启端口 25 (SMTP) 和端口 465 (SMTPS) :

firewall-cmd --zone=dmz --add-service=smtp --permanent

firewall-cmd --zone=dmz --add-service=smtps --permanent

  开启 IMAP、IMAPS、POP3 和 POP3S 端口:

firewall-cmd --zone=dmz --add-service=imap --permanent
firewall-cmd --zone=dmz --add-service=imaps --permanent
firewall-cmd --zone=dmz --add-service=pop3 --permanent
firewall-cmd --zone=dmz --add-service=pop3s --permanent

  因为将 SSH 端口改到了 7022,所以要移除 ssh 服务(端口 22),开启端口 7022:

firewall-cmd --remove-service=ssh --permanent

firewall-cmd --add-port=7022/tcp --permanent

  重新加载防火墙,列出规则

firewall-cmd --reload

firewall-cmd –list-all

Via :  CentOS 7 上的 FirewallD 简明指南

iptables


用如下命令备份及恢复配置文件:

/sbin/iptables-save > /root/iptables-works-`date +%F`

/sbin/iptables-restore < /root/iptables-works-2018-09-11

ln –s /root/iptables-works-`date +%F` /root/iptables-works-latest

免在策略顶部使用如下的一些通用规则:

iptables -A INPUT -p tcp --dport 22 –s 10.0.0.0/8 –d 192.168.100.101 -j DROP

这是一个有效地避免封锁自己的设置,在策略规则顶部将你的 IP 列入白名单:

iptables -I INPUT -s <your IP> -j ACCEPT

限制 IP 地址范围:

iptables -A OUTPUT -p tcp -i eth0 –o eth1 –d 31.13.64.0/18 -j DROP

按时间规定做限制 - 场景1

iptables –A OUTPUT -p tcp -mmultiport --dport http,https -i eth0 -o eth1 -m time --timestart 12:00 –timestop 13:00 –d 31.13.64.0/18 -j ACCEPT

按时间规定做限制 - 场景

iptables -A INPUT -p tcp -m time --timestart 02:00 --timestop 03:00 -j DROP
iptables -A INPUT -p udp -m time --timestart 02:00 --timestop 03:00 -j DROP

限制连接数量

iptables –A INPUT –p tcp –syn -m multiport -–dport http,https –m connlimit -–connlimit-above 20 –j REJECT -–reject-with-tcp-reset

查看规则被访问了多少次:

iptables -L -v -n –line-numbers

删除不必要的规则

iptables -nvL | grep -v "0     0"    #注意:两个数字 0 之间不是 Tab 键,而是 5 个空格

将用户完成工作所需的最少量服务设置为允许:

# Set a default policy of DROP
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
# Accept any related or established connections
-I INPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT
-I OUTPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT
# Allow all traffic on the loopback interface
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
# Allow outbound DHCP request
-A OUTPUT –o eth0 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
# Allow inbound SSH
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -j ACCEPT
# Allow outbound email
-A OUTPUT -i eth0 -p tcp -m tcp --dport 25 -m state --state NEW -j ACCEPT
# Outbound DNS lookups
-A OUTPUT -o eth0 -p udp -m udp --dport 53 -j ACCEPT
# Outbound PING requests
-A OUTPUT –o eth0 -p icmp -j ACCEPT
# Outbound Network Time Protocol (NTP) requests
-A OUTPUT –o eth0 -p udp --dport 123 --sport 123 -j ACCEPT
# Outbound HTTP
-A OUTPUT -o eth0 -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT
COMMIT

via:系统管理员需知的 16 个 iptables 使用技巧


PS:

iptables 四表五链

CentOS7 防火墙(firewall)的操作命令

防火墙 firewall iptables的更多相关文章

  1. Linux防火墙配置(iptables, firewalld)

    netfilter和底层实现 iptables firealld Linux中的防火墙 RHEL中有几种防火墙共存: iptables firewalld ip6tables ebtables 这些软 ...

  2. 实用防火墙(Iptables)脚本分析

    实用防火墙(Iptables)脚本分析 --Redhat,CentOS,Ubuntu等常见Linux发行版中都会预装Iptables防火墙,大多数初学者设置起来由于对这款软件比较陌生,设置起来比较困难 ...

  3. 企业防火墙之iptables

    1.1 企业中安全优化配置原则 尽可能不给服务器配置外网ip ,可以通过代理转发或者通过防火墙映射.并发不是特别大情况有外网ip,可以开启防火墙服务. 大并发的情况,不能开iptables,影响性能, ...

  4. Linux防火墙简介 – iptables配置策略

    Linux防火墙简介 – iptables配置策略 Netfilter/iptables简介 要想真正掌握Linux防火墙体系,首先要搞清楚Netfilter和iptables的关系,Netfilte ...

  5. Linux防火墙:iptables禁IP与解封IP常用命令

    在Linux服务器被攻击的时候,有的时候会有几个主力IP.如果能拒绝掉这几个IP的攻击的话,会大大减轻服务器的压力,说不定服务器就能恢复正常了. 在Linux下封停IP,有封杀网段和封杀单个IP两种形 ...

  6. linux防火墙相关 iptables

    1. root用户查看防火墙状态(非root用户无权限查看) 查看防火墙状态: service iptables status 2.开启和关闭防火墙 //开启防火墙: service iptables ...

  7. 防火墙firewall的设置和查看

    systemctl start firewalld.service # 开启防火墙firewallsystemctl stop firewalld.service # 停止防火墙firewall sy ...

  8. linux防火墙之iptables

    linux防火墙之iptables 1.1.1 关于iptables简介 IPTABLES 是与最新的 3.5 版本 Linux 内核集成的 IP 信息包过滤系统.如果 Linux 系统连接到因特网或 ...

  9. Linux防火墙(iptables/firewalld)

    Linux防火墙(iptables/firewalld) 目录 Linux防火墙(iptables/firewalld) 一.iptables 1. iptables概述 2. netfilter和i ...

随机推荐

  1. 2.EL表达式&JSTL标签库常用方法

    1.EL表达式 Expression Language表达式语言,主要是代替jsp页面中的表达式脚本在jsp页面中进行数据的输出. 格式为${表达式} EL表达式输出Bean的普通属性.数组属性.Li ...

  2. 全网最清楚的:MySQL的insert buffer和change buffer 串讲

    目录 一.前言 二.问题引入 2.1.聚簇索引 2.2.普通索引 三.change buffer存在的意义 四.再看change buffer 五.change buffer 的限制 六.change ...

  3. 解决Docker MySQL无法被宿主机访问的问题

    1 问题描述 Docker启动MySQL容器后,创建一个localhost访问的用户: create user test@localhost identified by 'test'; 但是在宿主机中 ...

  4. JavaCV 视频滤镜(LOGO、滚动字幕、画中画、NxN宫格)

    其实,在JavaCV中除了FFmpegFrameGrabber和FFmpegFrameRecorder之外,还有一个重要的类,那就是FFmpegFrameFilter. FFmpegFrameFilt ...

  5. MySQL 储存引擎知识点

    一:MySQL 存储引擎概述 1.1 什么是存储引擎: '''MySQL中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛 ...

  6. RandomForestClassifier参数

    [RandomForestClassifier] 参数 n_estimators : 随机森林中树的个数,即学习器的个数. max_features : 划分叶子节点,选择的最大特征数目 n_feat ...

  7. CentOS7 基本概念以及安装注意事项

    什么是Linux发行版?发行版是什么意思? Linux本质上是操作系统内核,类似Chrome浏览器内核一样,Linux发行版CentOS.Redhat.Ubuntu等等都是基于Linux内核开发出来的 ...

  8. PAT归纳总结——关于模拟类问题的一些总结

    关于时间的模拟问题 在刷题的过程中碰到了一些关于时间先后顺序的模拟题目,刚开始做的时候确实挺麻烦的,今天把这类问题的解题思路来整理一下. 比较典型的有: 1017 Queueing at Bank 1 ...

  9. 从苏宁电器到卡巴斯基第24篇:难忘的三年硕士时光 II

    没办法,还是先打好基础吧 其实在我知道自己面试失败后,第一个想法就是将面试官问我的问题都总结出来,然后通过查权威的资料,找出所有问题的答案,背下所有的答案,大概过一到两个月吧,再面试金山.当时我是这么 ...

  10. Shiro反序列化漏洞复现

    Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API,可以快速.轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和企 ...