【Linux】iptables之防火墙概述及规则匹配+实例(1)

资讯 2024-06-25 阅读:26 评论:0
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

在这里插入图片描述

insert picture description

网络中的防火墙,是一种将内部网络和外部网络分开的方法,是一种隔离技术。防火墙在内网与外网通信时进行访问控制,依据所设置的规则对数据包作出判断,最大限度地阻止网络中的黑客破坏企业网络,从而加强企业网络安全。

The firewall in the network is a way to separate internal and external networks and is a technology of isolation. The firewall provides access control when communicating with the outer network, judges the data packages according to the rules in place and maximizes the ability of hackers in the network to disrupt the enterprise network and thereby enhances the safety of the enterprise network.

主要是网络层,针对IP数据包,体现对包内的IP地址、端口等信息的处理上。

It is mainly a network layer, for IP data packs, reflecting the processing of IP addresses, ports, etc. in the package.

表中存放的是链,链中存放的是规则

四表:优先级:filter<nat<mangle<raw

Table IV: Priority: Filter< nat< mangle<raw

raw表 确定是否对该数据包进行状态跟踪;有限级最高,设置raw是一般是为了不在iptables做数据包的链接跟踪处理,提高性能
mangle表 为数据包设置标记;负责对数据包进行修改和追踪
NAT表 修改数据包中的源、目标IP地址或端口;负责地址转发
filter表 确定是否被放行该数据包(过滤);负责包过滤(默认)

链表结构关系图:

在这里插入图片描述

insert picture description

五链:

小写
INPUT 处理入站数据包 input
OUTPUT 处理出站数据包 output
FORWARD 处理转发数据包 forward
PREROUTING 在进行路由选择前处理数据包 prerouting
POSTROUTING 在进行路由选择后处理数据包 postrouting

规则链之间的顺序:

Order between the rules chain:

入站: PREROUTING→INPUT ? ? ? ? ? ? ? ? ? 路由选择前→入站
出站:OUTPUT→POSTROUTING ? ? ? ? ? ? ? ?出站→路由选择后
转发:PREROUTING→FORWARD→POSTROUTING ?路由选择前→转发→路由选择后

不管是路由入站还是转发,都要选择路由选择前
不管是路由出站还是转发,都要选择路由选择后

注意事项:
不指定表名时,默认指filter表
不指定链名时,默认指表内的所有链
除非设置链的默认策略,否则必须指定匹配条件
选项、链名、控制类型使用大写字母,其余均为小写

Note: When
does not specify a name, the default refers to the file form
does not specify a chain name, and the default refers to all chains in the table
unless the default strategy for setting the chain is the default, the matching condition

数据包的常见控制类型/动作类型:-j

Common control/action type for the data package: -j

类型 解析
ACCEPT 允许通过
DROP 直接丢弃,不给出任何回应
REJECT 拒绝通过,必要时会给出提示
LOG 记录日志信息,然后传给下一条规则继续匹配

选项及参数:

选项&参数 解析
-t 指定表,默认filter
-A 追加一条规则 -A 链名 [序号] 匹配条件 -j 动作
-I 插入一条规则 -I 链名 [序号] 匹配条件 -j 动作;默认第一行(也可以自己指定序号)
-R 修改规则 -R 链名 序号 匹配条件 -j 动作
-D 删除指定规则 -D 链名 序号
-P 设置默认规则 -P 链名 动作(ACCEPT,DROP,REJECT,LOG)
-p 指定协议 TCP,UDP,ICMP;--sport 指定源端口 ;--dport 指定目标端口
-L 查看防火墙规则,后可以指定链
-F 清空防火墙规则;也可以指定清空某一个表的所有规则
-v 以更详细的方式显示规则信息
-n 以数字形式显示;要和-L配合看
--line-numbers或--line 显示规则编号;要和-L配合看
-s 指定源地址
-d 指定目标地址
-i 指定网卡
-m 指定模块,没有指定模块,默认使用与-p选项同名的模块

实例:

1、-t:指定查看raw表

1.-t: Specified view raw table


2、-A \-s\-j:追加一条规则,使192.168.2.2禁止访问

2,-A \-s\-j: add a rule to prohibit access to 192.168.2.2


3、-I\-s\-j:插入一条规则,允许访问192.168.2.2

3,-I\-s\-j: insert a rule allowing access to 192.168.2.2


4、-R\-s\-j:第一条规则,修改为丢弃192.168.2.2;将第二条prot的udp改为icmp并且开放

4,-R\-s\-j: Rule 1, amended to discard 192.168.2.2; article 2, prot read icmp and open


5、-D:删除一条指定的规则

5.-D: delete a designated rule


6、-L:查看防火墙规则,后可以指定链

6.-L: View firewall rules and then specify chains


7、-F:清空防火墙规则 ;也可以指定清空某一个表的所有规则

7,-F: Clear firewall rules; all rules for emptying a watch can also be specified


8、-n:以数字形式显示;要和-L配合看

8.-n: in digital form; read in conjunction with -L


9、-v:已更详细的方式查看规则信息

9.-v: Rule information is viewed in more detail


10、--line-numbers或--line:显示规则编号;要和-L配合看

10, --line-numbers or --line: show rule numbers; read in conjunction with-L




1、通用匹配
可直接使用,不依赖与其他条件或扩展
包括网络协议、IP地址、网络接口等条件

Universal matching
can be used directly, without relying on other conditions or extensions
including network protocols, IP addresses, network interfaces, etc.

2、隐含匹配
要求以特定的协议匹配作为前提
包含端口、TCP标记、ICMP类型等条件

2. Implicit matching
requires specific agreement matching as a precondition
to include conditions such as ports, TCP tags, ICMP type

3、显式匹配
要求以“-m扩展模块”的形式明确指出类型
包括多端口、MAC地址、IP范围、数据包状态等条件

3. A visible match
requires that the type
be specified in the form of an "-m-extension module" and include conditions such as multiple ports, MAC addresses, IP ranges, data package status
br>

常用管理选项汇总表:

Summary of common management options:

在这里插入图片描述

insert picture description

在这里插入图片描述

insert picture description


常见的通用匹配条件:
协议匹配:-p 协议名
地址匹配:-s 源地址、-d 目的地址
接口匹配:-i 入站网卡、-o 出站网卡

协议匹配:-p 协议名

protocol match: -p protocol name

允许所有的TCP协议进入

allows all TCPs to enter


在这里插入图片描述

insert picture description

除了icmp协议其他协议都丢弃

all agreements except the icmp's


在这里插入图片描述

insert picture description

地址匹配:-s 源地址、-d 目的地址

Address Match: -s source, -d destination

允许访问ip地址192.168.2.2

allows access to ip addresses 192.168.2.2


在这里插入图片描述

insert picture description

丢弃192.168.1.0/24网段的ip

discards

in net segment 192.168.1.0/24


在这里插入图片描述

insert picture description

访问地址将地址转发到目标地址“192.168.2.22”并且开放

visit address to target address “192.168.2.22” and open to


在这里插入图片描述

insert picture description

接口匹配:-i 入站网卡、-o 出站网卡

interface match: -i access card, -o exit card

将eth1的网卡在入站时丢弃

Throws >......................................................................................................


在这里插入图片描述

 Insert picture description

将eth1的网卡在出站时丢弃

Throws Eth1's netcard out of the station


在这里插入图片描述

insert picture description

常见的隐含匹配条件:
端口匹配:-p来指定,--sport 源端口、--dport目的端口
TCP匹配:--tcp-flags 检查范围 被设置的标记
ICMP匹配:--icmp-type ICMP类型

端口匹配:-p来指定,--sport 源端口、--dport目的端口

port matching: -p to specify, - port source, - port port port

将源网段设置为udp协议且目标端口为53,并开启地址转发
将目标网段设置为udp协议且源端口为53,并开启地址转发

sets the source section to the udp protocol and the target port to 53, and opens the address to
to the target section to udp protocol and the source port to 53 and the address to
to


在这里插入图片描述

insert picture description

将源网段“192.16.2.0/24”设置为tcp协议且目标端口为53,并开启地址转发
将目标网段“192.16.2.0/24”设置为tcp协议且源端口为53,并开启地址转发

Set the source section "192.16.2.0/24" to the tcp protocol and target port 53, and open the address to
to Set the target section "192.16.2.0/24" to the tcp protocol and the source port to 53 and the address to to


在这里插入图片描述

insert picture description

开放TCP协议且目标端口为22,允许进入
开放TCP协议且目标端口为20-21,允许进入

with a target port of 22, access to
, access to >, access to
>, access to the target port of >


在这里插入图片描述

 Insert picture description

TCP匹配:--tcp-flags 检查范围 被设置的标记

TCP matching: -- tcp-flags check range set tag

指定eth1网卡,port设置为tcp协议,检查范围为SYN、RST、ACK,监测到的都丢弃

designates the Eth1 net card, the port is set to the tcp protocol, the scope of which is SYN, RST, ACK, and everything monitored is discarded

指定eth1网卡,port设置为tcp协议,除了检查范围中的SYN、RST、ACK,其他都可以进入

designates the Eth1 net card, the port is set to tcp, and all but SYN, RST, ACK in the range of inspections can be accessed


在这里插入图片描述

 Insert picture description

ICMP匹配:--icmp-type ICMP类型

ICMP matching: -icmp-type ICMPtype

常见的 icmp 类型
8? Echo request——回显请求(Ping 请求)
0 ?Echo Reply——回显应答(Ping 应答)
3 ?错误回显

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

 Insert picture description"https://uccc.alicdn.com/images/user-upload-01/3a2377d2fc304a9b8c7ac7efcd3c751c.png" alt=" Insert picture description "title= Inserting picture" Loading="lazy" >

获取帮助:iptables -p icmp -h

Get help:

常见的显式匹配条件:
多端口匹配:-m multiport --sports | --dports 端口列表
IP范围匹配:-m iprange --src-range IP范围
MAC地址匹配:-m mac --mac-source MAC地址
状态匹配:-m state --state 连接状态

多端口匹配:-m multiport --sports | --dports 端口列表

multiport matching: -m multiport-ports-dports port list

允许22、25、80、110、143端口进入并开启tcp协议

allows ports 22, 25, 80, 110, 143 to enter and open tcp


在这里插入图片描述

 Insert picture description

IP范围匹配:-m iprange --src-range IP范围

IP range matching: -m iprange --src-range IP range

允许192.168.1.100-192.168.1.110这个范围的ip进入并设置tcp协议

allows the entry and setting up of tcp protocol within the scope of 192.168.1.100-192.168.1.110


在这里插入图片描述

insert picture description

MAC地址匹配:-m mac --mac-source MAC地址

MAC Address Match: -m Mac-mac-source MAC Address

只要mac地址是00:0c:29:c2:83:32的都丢弃

all if the Mac address is 00:0c:29:c2:8332


在这里插入图片描述

insert picture description

状态匹配:-m state --state 连接状态

state matching: -m state --state connection

常见的连接状态:
NEW:新连接,与任何连接无关
ESTABLISHED:响应请求或已建立连接的
RELATED:与已连接有相关性的,如 FTP 数据连接

在这里插入图片描述

insert picture description

【Linux】iptables之防火墙概述及规则匹配+实例(1)


【Linux】iptables之防火墙的应用及案例、策略、备份与还原(2)


【Linux】firewall-cmd之防火墙简介及常用命令+实例

在这里插入图片描述

insert picture description

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
热门文章
  • 0.00003374个比特币等于多少人民币/美金

    0.00003374个比特币等于多少人民币/美金
    0.00003374比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00003374比特币等于2.2826 1222美元/16.5261124728人民币。比特币(BTC)美元(USDT)人民币(CNY)0.00003374克洛克-0/22216.5261124728比特币对人民币的最新汇率为:489807.72 CNY(1比特币=489807.72人民币)(1美元=7.24人民币)(0.00003374USDT=0.0002442776 CNY)。汇率更新于2024...
  • 134 USD toBTC Calculator -

    134                            USD                        toBTC                        Calculator -
    For the week (7 days) Date Day 134 USD to BTC Changes Changes % June...
  • 0.00006694个比特币等于多少人民币/美金

    0.00006694个比特币等于多少人民币/美金
    0.00006694比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00006694比特币等于4.53424784美元/32.5436 16人民币。比特币(BTC)美元(USDT)人民币(CNY)0.000066944.53424784【比特币密码】32.82795436 16比特币对人民币的最新汇率为:490408.64 CNY(1比特币=490408.64人民币)(1美元=7.24人民币)(0.00006694USDT=0.0004846456 CNY)汇率更新时...
  • 12年怎么购买比特币?比特币投资,轻松掌控

    12年怎么购买比特币?比特币投资,轻松掌控
    12年怎么购买比特币?买卖比特币可以通过以下交易所进行购买,分别是:欧易官网平台、ZG交易所、艾戴克斯交易所、C2CX交易软件、BaseFEX交易APP、波网交易平台、安银交易所、BitMart交易软件、紫牛币交所交易APP和澳网(AOMEX)交易平台等等十大平台下载,高效安全的数字货币交易平台。How do you buy bitcoins in 12 years? Bitcoins can be purchased through ten major platforms...
  • 0.00015693个比特币等于多少人民币/美金

    0.00015693个比特币等于多少人民币/美金
    0.000 15693比特币等于多少人民币?根据比特币对人民币的最新汇率,0.000 15693比特币等于10.6 1678529美元/76.86554996人民币。比特币(BTC)【比特币价格翻倍】美元(USDT)人民币(CNY)0.000/克洛克-0/5693【数字货币矿机】10.6 167852976.8655254996比特币对人民币的最新汇率为:489,807.72 CNY(1比特币= 489,807.72人民币)(1美元=7.24人民币)(0.00015693 U...
标签列表