iptables匹配iprange
iprange匹配帮助信息如下。
iprange match options:
[!] --src-range ip[-ip] Match source IP in the specified range
[!] --dst-range ip[-ip] Match destination IP in the specified range
配置如下策略,丢弃源地址在区间:[192.168.1.90 - 192.168.1.110]中的报文。
# iptables -A INPUT -m iprange --src-range 192.168.1.90-192.168.1.110 -j DROP
#
# iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target prot opt in out source destination 0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 source IP range 192.168.1.90-192.168.1.110
iprange匹配
函数xt_register_matches注册匹配结构iprange_mt_reg。
static struct xt_match iprange_mt_reg[] __read_mostly = {{.name = "iprange",.revision = 1,.family = NFPROTO_IPV4,.match = iprange_mt4,.matchsize = sizeof(struct xt_iprange_mtinfo),.me = THIS_MODULE,},{.name = "iprange",.revision = 1,.family = NFPROTO_IPV6,.match = iprange_mt6,.matchsize = sizeof(struct xt_iprange_mtinfo),.me = THIS_MODULE,},
};
static int __init iprange_mt_init(void)
{return xt_register_matches(iprange_mt_reg, ARRAY_SIZE(iprange_mt_reg));
对于IPv4协议,规则参数src-range对应于标志IPRANGE_SRC;参数dst-range对应于标志IPRANGE_DST,分别判断报文IP头部的源和目的地址,是否位于配置的区间之外,为真返回false,否则,返回true。
static bool
iprange_mt4(const struct sk_buff *skb, struct xt_action_param *par)
{const struct xt_iprange_mtinfo *info = par->matchinfo;const struct iphdr *iph = ip_hdr(skb);if (info->flags & IPRANGE_SRC) {m = ntohl(iph->saddr) < ntohl(info->src_min.ip);m |= ntohl(iph->saddr) > ntohl(info->src_max.ip);m ^= !!(info->flags & IPRANGE_SRC_INV);if (m)return false;}if (info->flags & IPRANGE_DST) {m = ntohl(iph->daddr) < ntohl(info->dst_min.ip);m |= ntohl(iph->daddr) > ntohl(info->dst_max.ip);m ^= !!(info->flags & IPRANGE_DST_INV);if (m)return false;}return true;
对于IPv6协议,由函数iprange_ipv6_lt比较两个地址的大小。
static inline int
iprange_ipv6_lt(const struct in6_addr *a, const struct in6_addr *b)
{unsigned int i; for (i = 0; i < 4; ++i) {if (a->s6_addr32[i] != b->s6_addr32[i])return ntohl(a->s6_addr32[i]) < ntohl(b->s6_addr32[i]);} return 0;
将报文头部的IPv6地址,与配置的区间进行比较。
static bool
iprange_mt6(const struct sk_buff *skb, struct xt_action_param *par)
{ const struct xt_iprange_mtinfo *info = par->matchinfo;const struct ipv6hdr *iph = ipv6_hdr(skb);bool m;if (info->flags & IPRANGE_SRC) {m = iprange_ipv6_lt(&iph->saddr, &info->src_min.in6);m |= iprange_ipv6_lt(&info->src_max.in6, &iph->saddr);m ^= !!(info->flags & IPRANGE_SRC_INV);if (m)return false;}if (info->flags & IPRANGE_DST) {m = iprange_ipv6_lt(&iph->daddr, &info->dst_min.in6);m |= iprange_ipv6_lt(&info->dst_max.in6, &iph->daddr);m ^= !!(info->flags & IPRANGE_DST_INV);if (m)return false;}return true;
内核版本 5.10
iptables匹配iprange相关推荐
- Iptables防火墙iprange模块扩展匹配规则
Iptables防火墙iprange模块扩展匹配规则 iprange模块可以同时设置多个IP或者设置IP的某一段连续的范围,通过iprange模块可以对多个来源地址同时设置策略. iprange模块的 ...
- 防火墙 之 iptables 匹配条件讲解
1 概述 iptables命令中,需要根据匹配的条件作出相应的动作,本文将结合例子,讲解匹配条件 匹配条件分为基本和扩展的条件 基本:通用的,PARAMETERS,无需加载模块,由iptables ...
- iptables匹配multiport
multiport匹配帮助信息如下.multiport有三个选项.其中,–source-port(简写–sports)用于指定源端口,多个源端口使用逗号分隔,当指定源端口范围时,使用分号表示区间(po ...
- iptables匹配功能length
用于匹配报文特定长度,或者范围,这里的报文长度指的是4层数据的长度,如TCP/UDP/ICMP等.以下仅允许数据包小于100字节的ping请求数据进入. # iptables -I INPUT -p ...
- iptables匹配connlimit限制并发连接数量
以下规则将每个IP的最大并发连接数量控制在5个,使用connlimit-above或者connlimit-upto都可实现. # iptables -I INPUT -p tcp --syn --dp ...
- iptables(四)iptables匹配条件总结之一
经过前文的总结,我们已经能够熟练的管理规则了,但是我们使用过的"匹配条件"少得可怜,之前的示例中,我们只使用过一种匹配条件,就是将"源地址"作为匹配条件. 那么 ...
- iptables匹配quota
quota匹配帮助信息如下. # iptables -m quota -h quota match options: [!] --quota quota quota (bytes) 如下,当主机192 ...
- iptables匹配ttl
TTL匹配帮助信息如下,可判断相等,大于和小于三种关系. # iptables --match ttl -h ttl match options: [!] --ttl-eq value Match t ...
- netfilter/iptables模块功能中文介绍
功能介绍 (每个info和help本是英文的,为方便阅读我把它翻译成中文,由于水平有限,如果有误请有经验者来信指正) 获取最新patch-o-matic-ng的地址:[url]ftp://ftp.ne ...
最新文章
- 实现php实现价格的排序,PHP实现二维数组排序(按照数组中的某个字段)
- 平面设计师如何掌握色彩心理学(实用技巧)
- android开发中的 Activity 与 Context 区别与联系
- 招聘:兼职ASP.NET 开发工程师
- 前端开发工程师和美工 知识需求的区别
- skywalking与pinpoint全链路追踪方案对比
- python中使用连续关系运算符_解释一下Python中的关系运算符
- 腾讯看点基于 Flink 的实时数仓及多维实时数据分析实践
- Tensorspace一款神奇的神经网络可视化应用
- 微信公众号支付开发全过程
- 分享四个黑科技app,每一个都让你好用到停不下来
- python的模块和包
- Relative Orientation 与fundamental essential matrix
- android 仿微信视频压缩上传,iOS视频压缩(仿微信录像)
- 使用HTML实现一个静态页面(含源码)
- 固定资产管理系统如何简化固定资产管理和盘点工作?
- mstsc远程桌面连接失败,提示CredSSP加密Oracel修正
- lucene spatial 6.1搜索附近的饭店
- C语言 实现 最长名字输出
- fc安卓模拟器_面对悠长假期,GPD WIN2掌机让我畅玩模拟器游戏