配置标记规则
标记规则包括一个或多个term语句,用于标识在 中的term条件匹配时要执行的 HTTP 扩充作。您必须在 的term子句中then配置至少一个tag标记,并且可以配置多个标记。
按配置顺序评估术语。如果数据包符合 中的语句term中的所有from条件,则应用 的term语句中then指定的作。如果语from句未识别任何条件,则所有流量都匹配。数据包与术语匹配后,不再评估其他术语。如果没有匹配的术语,则不会扩充 HTTP 标头。
要配置标记规则,请执行以下作:
- 配置可在标记规则中使用的标记属性列表。
[edit services hcm] user@host# set tag-attribute tag-attr-name
自适应服务当前支持的标记属性是
apn、ggsnipv4、ipv4addrmsisdnggsnipv6imeiimsiipv6addr和 。要配置多个标记属性,请将它们包含在方括号 ([ ]) 中。从 Junos 20.2R1 版开始,MX240、MX480 和 MX960 上的新一代服务支持用于 HTTP 标头扩充的 IPv4 和 IPv6 标记。此版本中的新一代服务不支持其他标记。例如:
[edit services hcm] user@host# set tag-attribute [msisdn apn]
- 为标记规则配置名称。
[edit services hcm] user@host# set tag-rule rule-name
例如:
[edit services hcm] user@host# set tag-rule rule1
- 为标记规则配置术语。
[edit services hcm set tag-rule rule-name] user@host# set term term-number
注意:term参数必须具有数值。例如:
[edit services hcm set tag-rule rule1] user@host# set term 1
- (可选)指定 HTTP 请求目标 IP 地址必须匹配的前缀。
[edit services hcm tag-rule rule-name term term-number from] user@host# set destination-address prefix
例如:
[edit services hcm tag-rule rule1 term 1 from] user@host# set destination-address 192.0.2.0/24
您还可以指定要匹配的地址类型:
[edit services hcm tag-rule rule-name term term-number from] user@host# set destination-address (any-ipv4 | any-ipv6 | any-unicast)
您可以通过多次包含
destination-address语句来指定多个前缀或地址类型。 - (可选)指定 HTTP 请求目标 IP 地址必须匹配的 IP 地址范围。
[edit services hcm tag-rule rule-name term term-number from] user@host# set destination-address-range low address high address
例如:
[edit services hcm tag-rule rule1 term 1 from] user@host# set destination-address-range low 10.10.10.1 high 10.10.10.255
您可以通过多次包含
destination-address-range该语句来指定多个地址范围。 - (可选)指定 HTTP 请求目标 IP 地址必须匹配的目标前缀列表。前缀列表必须已在层次结构级别定义
[edit policy-options prefix-list]。[edit services hcm tag-rule rule-name term term-number from] user@host# set destination-prefix-list prefix-name
例如:
[edit services hcm tag-rule rule1 term 1 from] user@host# set destination-prefix-list customer1
您可以通过多次包含
destination-prefix-list语句来指定多个前缀列表。 - (可选)指定要排除的任何地址,使其无法将 HTTP 请求目标 IP 地址与语句匹配
except。要排除地址,还必须在层次结构级别配置[edit services hcm tag-rule rule-name term term-number from]在 、destination-address-range或destination-prefix-list语句中destination-address匹配的地址。例如:
[edit services hcm tag-rule rule1 term 1 from] user@host# set destination-address-range low 10.10.10.1 high 10.10.10.255 user@host# set destination-address 10.10.10.9/32 except
这匹配目标范围内除 10.10.10.9 之外的所有地址。
您可以在
except层次结构级别的[edit services hcm tag-rule rule-name term term-number from]以下语句中使用:destination-address { any-ipv4 except; any-ipv6 except; any-unicast except; prefix except; } destination-address-range { high address low address except; } destination-prefix-list { prefix-name except; } - (可选)指定 HTTP 请求目标端口号必须匹配的端口范围。
[edit services hcm tag-rule rule-name term term-number from] user@host# set destination-port-range high port-number low port-number
您可以通过多次包含
destination-port-range语句来指定多个端口范围。注意:如果未指定任何要匹配的端口或端口范围,则所有端口都将匹配。
- (可选)指定必须匹配的 HTTP 请求目标端口号。
[edit services hcm tag-rule rule-name term term-number from] user@host# set destination-ports value
您可以通过多次包含
destination-ports该语句来指定多个端口。 - (可选)指定您希望将标记规则语句中
then指定的所有 HTTP 标头扩充作应用于所有 HTTP 请求,方法是在语句中from不包含任何匹配条件。您必须在每个term标记规则中包含一个from语句。[edit services hcm tag-rule rule-name term term-number ] user@host# set from
例如:
[edit services hcm tag-rule rule2 term 1] user@host# set from [edit services hcm tag-rule rule2 term 1] user@host# set then count
- 为标记配置名称。
[edit services hcm tag-rule rule-name term term-number then] user@host# set tag tag-name
例如:
[edit services hcm tag-rule rule1 term 1 then] user@host# set tag msisdn-tag
- 配置标记应用于 HTTP 标头的标记标头。
[edit services hcm tag-rule rule-name term term-number then tag tag-name] user@host# set tag-header header
例如:
[edit services hcm tag-rule rule1 term 1 then tag msisdn-tag] user@host# set tag-header X_MSISDN
您最多可以配置 16 个唯一标记头。
这些header值不能是 、
proxy-authorizationhostif-matchif-unmodified-sinceif-rangemax-forwardsif-none-matchrefereruser-agentaccept-charsetaccept-languagex-mozaccept-encodingauthorizationexpectif-modified-sinceaccept这些标头值是保留的;您无法对其进行配置。 - 指定标记应用于 HTTP 标头的标记属性。要一次指定多个属性,请将属性包含在方括号 ([]) 中。
[edit services hcm tag-rule rule-name term term-number then tag tag-name] user@host# set tag-attribute [tag-attr-name]
注意:标记属性必须列在步骤 1 中配置的标记属性中。
例如:
[edit services hcm tag-rule rule1 term 1 then tag msisdn-tag] user@host# set tag-attribute msisdn
- 指定标记在 HTTP 标头中使用的分隔符。
[edit services hcm tag-rule rule-name term term-number then tag tag-name] user@host# set tag-separator separator
例如:
[edit services hcm tag-rule rule1 term 1 then tag msisdn-tag] user@host# set tag-separator /
- (可选)指定用于在 HTTP 标头中插入标记的哈希方法和前缀键。
[edit services hcm tag-rule rule-name term term-number then tag tag-name encrypt] user@host# set hash algorithm prefix hash-prefix
目前仅
md5支持哈希方法。例如:
[edit services hcm tag-rule rule1 term 1 then tag msisdn-tag encrypt] user@host# set hash md5 prefix gatewaykey1
- (可选)为标记规则启用 HTTP 标头扩充的统计信息收集。
[edit services hcm tag-rule rule-name term term-number then user@host# set count
- (可选)配置标记如何将 IPv4 或 IPv6 用户地址的某个字节替换为 HTTP 报头中的其他值。
[edit services hcm tag-rule rule-name term term-number then tag tag-name] user@host# set (ipv4-mask ipv4-mask | ipv6-mask ipv6-mask) (ipv4-or-value ipv4-or-value | ipv6-or-value ipv6-or-value)
要识别要替换的字节,请在 or 的
ipv4-maskipv6-mask相应字节中输入 255 for IPv4 或 ff for IPv6,并在其他字节中输入 0。要为该字节指定新值,请在 或
ipv4-or-value的ipv6-or-value对应字节中输入该值,并在其他字节中输入零。例如,以下内容将 IPv4 用户地址的第一个字节替换为值 168:
[edit services hcm tag-rule tag1 term term1 then tag subscip4] user@host# set ipv4-mask 255.0.0.0 ipv4-or-value 168.0.0.0
- 如果要为
then术语中的语句配置更多标记,请重复步骤 11 到步骤 17。 - 如果要为标记规则配置其他
term语句,请重复步骤 3 到步骤 18。
变更历史表
是否支持某项功能取决于您使用的平台和版本。使用 功能资源管理器 确定您的平台是否支持某个功能。