技术:iptables浅谈使用(二)

本文涉及的产品
云防火墙,500元 1000GB
简介: 防火墙技术是通过有机结合各类用于安全管理与筛选的软件和硬件设备,帮助计算机网络于其内、外网之间构建一道相对隔绝的保护屏障,以保护用户资料与信息安全性的一种技术。防火墙技术的功能主要在于及时发现并处理计算机网络运行时可能存在的安全风险、数据传输等问题,其中处理措施包括隔离与保护,同时可对计算机网络安全当中的各项操作实施记录与检测,以确保计算机网络运行的安全性,保障用户资料与信息的完整性,为用户提供更好、更安全的计算机网络使用体验。

引言

1 概述

防火墙技术是通过有机结合各类用于安全管理与筛选的软件和硬件设备,帮助计算机网络于其内、外网之间构建一道相对隔绝的保护屏障,以保护用户资料与信息安全性的一种技术。

防火墙技术的功能主要在于及时发现并处理计算机网络运行时可能存在的安全风险、数据传输等问题,其中处理措施包括隔离与保护,同时可对计算机网络安全当中的各项操作实施记录与检测,以确保计算机网络运行的安全性,保障用户资料与信息的完整性,为用户提供更好、更安全的计算机网络使用体验。


2 iptables

2.1 关于iptables

iptables是netfilter的一个子项目,iptables本身一个通用的防火墙软件,允许定义规则集。IP 表中的每条规则都由许多分类器(iptables 匹配)和一个连接的操作(iptables 目标)组成。


在与Linux内核集成时,版本对应如下:

• Linux 2.0.X内核对应ipfwadm

• Linux 2.2.X内核对应ipchains

• Linux2.4.X内核对应iptables


iptables的官方地址:https://www.netfilter.org/projects/iptables/index.html

iptables版本更改日志记录:https://git.netfilter.org/iptables/

iptables各个版本下载地址:https://www.netfilter.org/pub/iptables/


2.2 iptables工作原理

iptables是采用数据包过滤机制工作的,所以它会对请求的数据包的包头进行分析,并根据我们预先设定的规则进行匹配来决定是否可以进入主机。


  1. 防火墙是一层一层过滤的。实际是按照配置规则的顺序从上到下,从前到后进行过滤的;
  2. 如果匹配上规则,即明确表明阻止还是通过,此时数据包就不再向下匹配新规则了;
  3. 如果所有规则中没有明确表明是阻止还是通过这个数据包,也就是没有匹配上规则,则按照默认策略进行处理;
  4. 防火墙的默认规则是对应的链的所有的规则执行完成后才会执行的;


2.3 iptables的规则链

iptables的规则链是NetFilter规定的五个规则链,任何一个数据包,只要经过本机,必将经过这五个链中的其中一个链。

  • PREROUTING (路由前)
  • INPUT (数据包流入口)
  • FORWARD (转发管卡)    
  • OUTPUT(数据包出口)    
  • POSTROUTING(路由后)

image.png

2.4 iptables策略

防火墙策略一般分为两种,一种叫“通”策略,一种叫“堵”策略。

通策略

默认门是关着的,必须要定义谁能进。

堵策略

大门是洞开的,但是你必须有身份认证,否则不能进。

我们现在用的比较多个功能有3个,

  • filter  
  • 定义允许或者不允许的
  • INPUT ,FORWARD ,OUTPUT
  • nat
  • 定义地址转换的
  • PREROUTING ,OUTPUT ,POSTROUTING
  • mangle
  • 功能管理,修改报文原数据
  • PREROUTING,INPUT,FORWARD,OUTPUT,POSTROUTING


3 iptables使用规则

先使用命令iptables -V在机器上面查看是否安装,以及安装的版本。从下面的命令来看,我机器已经安装了iptables,而且安装的版本为v1.4.21。在官网,截止到目前为止,我们看到的最新版本为v1.8.8 。

[root@nto2 ~]# iptables -Viptables v1.4.21


关于使用,可以使用iptables --help来查看具体的使用规则。

[root@nto2 ~]# iptables --helpiptables v1.4.21
Usage: iptables -[ACD] chain rule-specification [options]
       iptables -I chain [rulenum] rule-specification [options]
       iptables -R chain rulenum rule-specification [options]
       iptables -D chain rulenum [options]
       iptables -[LS] [chain [rulenum]] [options]
       iptables -[FZ] [chain] [options]
       iptables -[NX] chain
       iptables -E old-chain-name new-chain-name
       iptables -P chain target [options]
       iptables -h (print this help information)
Commands:
Either long or short options are allowed.
--append-A chain  Append to chain
--check-C chain  Check for the existence of a rule
--delete-D chain  Delete matching rule from chain
--delete-D chain rulenum
    Delete rule rulenum (1 = first) from chain
--insert-I chain [rulenum]
    Insert in chain as rulenum (default 1=first)
--replace-R chain rulenum
    Replace rule rulenum (1 = first) in chain
--list-L [chain [rulenum]]
    List the rules in a chain or all chains
--list-rules-S [chain [rulenum]]
    Print the rules in a chain or all chains
--flush-F [chain]  Delete all rules in  chain or all chains
--zero-Z [chain [rulenum]]
    Zero counters in chain or all chains
--new-N chain  Create a new user-defined chain
--delete-chain-X [chain]  Delete a user-defined chain
--policy-P chain target
    Change policy on chain to target
--rename-chain-E old-chain new-chain
    Change chain name, (moving any references)
Options:
--ipv4-4  Nothing (line is ignored by ip6tables-restore)
--ipv6-6  Error (line is ignored by iptables-restore)
[!] --protocol-p proto  protocol: by number or name, eg. `tcp'[!] --source  -s address[/mask][...]    source specification[!] --destination -d address[/mask][...]    destination specification[!] --in-interface -i input name[+]    network interface name ([+] for wildcard) --jump -j target    target for rule (may load target extension)  --goto      -g chain                              jump to chain with no return  --match -m match    extended match (may load extension)  --numeric -n  numeric output of addresses and ports[!] --out-interface -o output name[+]    network interface name ([+] for wildcard)  --table -t table  table to manipulate (default: `filter')  --verbose -v  verbose mode  --wait  -w [seconds]  maximum wait to acquire xtables lock before give up  --wait-interval -W [usecs]  wait time to try to acquire xtables lock    default is 1 second  --line-numbers  print line numbers when listing  --exact -x  expand numbers (display exact values)[!] --fragment  -f  match second or further fragments only  --modprobe=<command>  try to insert modules using this command  --set-counters PKTS BYTES set the counter during insert/append[!] --version -V  print package version.
相关文章
|
传感器 安全
光学雨量计红外雨量传感器的工作原理是基于光学传感技术
光学雨量计红外雨量传感器的工作原理是基于光学传感技术
光学雨量计红外雨量传感器的工作原理是基于光学传感技术
|
机器学习/深度学习 前端开发 PyTorch
【轻量化:蒸馏】都2023年了,你还不会蒸馏操作,难怪你面试不通过!
【轻量化:蒸馏】都2023年了,你还不会蒸馏操作,难怪你面试不通过!
271 0
【轻量化:蒸馏】都2023年了,你还不会蒸馏操作,难怪你面试不通过!
|
SQL 存储 关系型数据库
OBCP第四章 SQL调优-分区
OBCP第四章 SQL调优-分区
382 0
|
机器学习/深度学习 算法 PyTorch
论文阅读笔记 | 目标检测算法——DETR
论文阅读笔记 | 目标检测算法——DETR
1327 0
论文阅读笔记 | 目标检测算法——DETR
发布宝贝提示“亲,您未通过食品资质备案所以无法新发商品”如何解决
亲,您未通过食品资质备案所以无法新发商品!根据《中华人民共和国食品安全法》要求,经营该类目下商品(食用农产品除外)需提供食品经营或食品生产资质,<a href='https://t.tb.cn/5CSyQjdLA5q33HBQElFNGd' target='_blank'>点击查看资质要求学习链接</a>,<a href='https://scportal.taobao.com/quali/portal.htm?source=taobao' target='_blank'>点击立即上传资质</a>,经营不同类型的食品,提交资质时,请您注意“经营范围”的选择。
|
存储 监控 安全
网络安全法中的 ISO 27001 和 CIA
【8月更文挑战第19天】
555 0
|
10月前
|
人工智能 自然语言处理 前端开发
100个降噪蓝牙耳机免费领,用通义灵码从 0 开始打造一个完整APP
打开手机,录制下你完成的代码效果,发布到你的社交媒体,前 100 个@玺哥超Carry、@通义灵码的粉丝,可以免费获得一个降噪蓝牙耳机。
6582 16
|
存储 Kubernetes 负载均衡
CentOS 7.9二进制部署K8S 1.28.3+集群实战
本文详细介绍了在CentOS 7.9上通过二进制方式部署Kubernetes 1.28.3+集群的全过程,包括环境准备、组件安装、证书生成、高可用配置以及网络插件部署等关键步骤。
1617 4
CentOS 7.9二进制部署K8S 1.28.3+集群实战
|
传感器 人工智能 网络协议
:嵌入式 Linux 及其用途
【8月更文挑战第24天】
509 0

热门文章

最新文章