<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>网络技术 on HiDa</title><link>https://www.0niu.cn/categories/%E7%BD%91%E7%BB%9C%E6%8A%80%E6%9C%AF/</link><description>Recent content in 网络技术 on HiDa</description><generator>Hugo -- gohugo.io</generator><language>zh</language><lastBuildDate>Wed, 11 Mar 2026 00:04:00 +0800</lastBuildDate><atom:link href="https://www.0niu.cn/categories/%E7%BD%91%E7%BB%9C%E6%8A%80%E6%9C%AF/index.xml" rel="self" type="application/rss+xml"/><item><title>FRR OSPF Route-MAP 配置指南</title><link>https://www.0niu.cn/posts/frr-ospf-route-map/</link><pubDate>Wed, 11 Mar 2026 00:04:00 +0800</pubDate><guid>https://www.0niu.cn/posts/frr-ospf-route-map/</guid><description>&lt;h2 id="概述">概述&lt;/h2>
&lt;p>Route-Map 是 FRR (FRRouting) 中强大的路由策略工具，用于控制 OSPF 路由的发布和接收。通过 Route-Map，可以实现：&lt;/p>
&lt;ul>
&lt;li>路由过滤&lt;/li>
&lt;li>路由属性修改&lt;/li>
&lt;li>条件路由发布&lt;/li>
&lt;/ul>
&lt;h2 id="基本概念">基本概念&lt;/h2>
&lt;h3 id="route-map-结构">Route-Map 结构&lt;/h3>
&lt;p>Route-Map 由一条或多条 &lt;strong>sequence&lt;/strong> 组成，每个 sequence 有：&lt;/p>
&lt;ul>
&lt;li>&lt;strong>匹配条件 (match)&lt;/strong>：定义哪些路由会被处理&lt;/li>
&lt;li>&lt;strong>动作 (action)&lt;/strong>：&lt;code>permit&lt;/code>（允许）或 &lt;code>deny&lt;/code>（拒绝）&lt;/li>
&lt;li>&lt;strong>设置语句 (set)&lt;/strong>：修改路由属性&lt;/li>
&lt;/ul>
&lt;h3 id="顺序执行">顺序执行&lt;/h3>
&lt;p>Route-Map 按序列号从小到大依次执行：&lt;/p>
&lt;ul>
&lt;li>一旦匹配成功，执行对应动作并停止&lt;/li>
&lt;li>如果所有 sequence 都未匹配，默认拒绝&lt;/li>
&lt;/ul>
&lt;h3 id="常用匹配条件">常用匹配条件&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>匹配类型&lt;/th>
&lt;th>说明&lt;/th>
&lt;th>示例&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>ip address&lt;/code>&lt;/td>
&lt;td>匹配 IP 地址/前缀&lt;/td>
&lt;td>&lt;code>match ip address prefix-list LIST&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>interface&lt;/code>&lt;/td>
&lt;td>匹配出接口&lt;/td>
&lt;td>&lt;code>match interface eth0&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>metric&lt;/code>&lt;/td>
&lt;td>匹配路由开销&lt;/td>
&lt;td>&lt;code>match metric 100&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>protocol&lt;/code>&lt;/td>
&lt;td>匹配路由协议类型&lt;/td>
&lt;td>&lt;code>match protocol ospf&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>next-hop&lt;/code>&lt;/td>
&lt;td>匹配下一跳地址&lt;/td>
&lt;td>&lt;code>match ip next-hop A.B.C.D&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>tag&lt;/code>&lt;/td>
&lt;td>匹配路由标签&lt;/td>
&lt;td>&lt;code>match tag 100&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>as-path&lt;/code>&lt;/td>
&lt;td>匹配 AS 路径（BGP）&lt;/td>
&lt;td>&lt;code>match as-path 100&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="支持的协议类型">支持的协议类型&lt;/h3>
&lt;ul>
&lt;li>&lt;code>ospf&lt;/code> - OSPF 路由&lt;/li>
&lt;li>&lt;code>static&lt;/code> - 静态路由&lt;/li>
&lt;li>&lt;code>connected&lt;/code> - 直连路由&lt;/li>
&lt;li>&lt;code>kernel&lt;/code> - 内核路由&lt;/li>
&lt;li>&lt;code>rip&lt;/code> - RIP 路由&lt;/li>
&lt;li>&lt;code>bgp&lt;/code> - BGP 路由&lt;/li>
&lt;li>&lt;code>isis&lt;/code> - IS-IS 路由&lt;/li>
&lt;li>&lt;code>pim&lt;/code> - PIM 路由&lt;/li>
&lt;/ul>
&lt;h2 id="配置示例">配置示例&lt;/h2>
&lt;h3 id="1-基本路由过滤">1. 基本路由过滤&lt;/h3>
&lt;h4 id="场景只允许特定网段的路由进入-ospf">场景：只允许特定网段的路由进入 OSPF&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e"># 定义前缀列表&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ip prefix-list INTERNAL_NETS seq &lt;span style="color:#ae81ff">5&lt;/span> permit 10.0.0.0/8 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ip prefix-list INTERNAL_NETS seq &lt;span style="color:#ae81ff">10&lt;/span> permit 172.16.0.0/12 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ip prefix-list INTERNAL_NETS seq &lt;span style="color:#ae81ff">15&lt;/span> permit 192.168.0.0/16 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ip prefix-list INTERNAL_NETS seq &lt;span style="color:#ae81ff">20&lt;/span> deny any
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e"># 应用到路由重分发&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute connected route-map FILTER_CONNECTED
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 定义 route-map&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_CONNECTED permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list INTERNAL_NETS
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景过滤掉特定路由">场景：过滤掉特定路由&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 定义要过滤的网段&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list BLOCK_NETS seq &lt;span style="color:#ae81ff">5&lt;/span> deny 192.168.100.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list BLOCK_NETS seq &lt;span style="color:#ae81ff">10&lt;/span> permit any
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 应用到路由注入&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> default-information originate route-map FILTER_DEFAULT
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_DEFAULT permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list BLOCK_NETS
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-修改路由属性">2. 修改路由属性&lt;/h3>
&lt;h4 id="场景修改路由开销值">场景：修改路由开销值&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>route-map SET_METRIC permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map SET_METRIC permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list SPECIAL_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">50&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 应用&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute static route-map SET_METRIC
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景根据路由类型设置不同开销">场景：根据路由类型设置不同开销&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>route-map METRIC_BY_TYPE permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list CRITICAL_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map METRIC_BY_TYPE permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list NORMAL_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-条件路由发布">3. 条件路由发布&lt;/h3>
&lt;h4 id="场景只在有特定路由时发布默认路由">场景：只在有特定路由时发布默认路由&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 定义匹配条件&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list ISP_ROUTE seq &lt;span style="color:#ae81ff">5&lt;/span> permit 0.0.0.0/0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map CONDITIONAL_DEFAULT permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list ISP_ROUTE
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> default-information originate route-map CONDITIONAL_DEFAULT always
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="4-重分发控制">4. 重分发控制&lt;/h3>
&lt;h4 id="场景从-bgp-重分发到-ospf-时过滤路由">场景：从 BGP 重分发到 OSPF 时过滤路由&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 只允许特定 BGP 路由进入 OSPF&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list FROM_BGP seq &lt;span style="color:#ae81ff">5&lt;/span> permit 203.0.113.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list FROM_BGP seq &lt;span style="color:#ae81ff">10&lt;/span> permit 198.51.100.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list FROM_BGP seq &lt;span style="color:#ae81ff">15&lt;/span> deny any
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map BGP_TO_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list FROM_BGP
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">50&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric-type type-1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute bgp route-map BGP_TO_OSPF
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景不同协议间重分发">场景：不同协议间重分发&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 静态路由重分发&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map STATIC_TO_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list STATIC_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 直连路由重分发&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map CONNECTED_TO_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match interface eth0 eth1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute connected route-map CONNECTED_TO_OSPF
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute static route-map STATIC_TO_OSPF
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="5-基于-ospf-协议的匹配">5. 基于 OSPF 协议的匹配&lt;/h3>
&lt;h4 id="场景只处理-ospf-协议的路由">场景：只处理 OSPF 协议的路由&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 匹配所有 OSPF 路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map ONLY_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">50&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 在重分发时应用&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute connected route-map ONLY_OSPF
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景排除-ospf-路由处理其他协议">场景：排除 OSPF 路由，处理其他协议&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 排除 OSPF 路由，只允许其他协议的路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXCLUDE_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol static
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol connected
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol kernel
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXCLUDE_OSPF deny &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 或者使用更简洁的方式&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_PROTOCOL permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol static
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">30&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>!
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_PROTOCOL permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol connected
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>!
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 默认拒绝其他协议（包括 ospf）&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景根据-ospf-路由类型处理">场景：根据 OSPF 路由类型处理&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 区分 OSPF 内部路由和外部路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map OSPF_INTERNAL permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list INTERNAL_PREFIX
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map OSPF_EXTERNAL permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute ospf route-map OSPF_EXTERNAL
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="6-区域间路由控制">6. 区域间路由控制&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 区域间路由过滤&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> area &lt;span style="color:#ae81ff">1&lt;/span> filter-list prefix IN_AREA1 in
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> area &lt;span style="color:#ae81ff">1&lt;/span> filter-list prefix OUT_AREA1 out
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list IN_AREA1 seq &lt;span style="color:#ae81ff">5&lt;/span> deny 192.168.10.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list IN_AREA1 seq &lt;span style="color:#ae81ff">10&lt;/span> permit 10.0.0.0/8 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list IN_AREA1 seq &lt;span style="color:#ae81ff">15&lt;/span> permit 172.16.0.0/12 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list IN_AREA1 seq &lt;span style="color:#ae81ff">20&lt;/span> permit 192.168.0.0/16 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="常用命令">常用命令&lt;/h2>
&lt;h3 id="查看配置">查看配置&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示 route-map 配置&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show route-map
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示前缀列表&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip prefix-list
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示 OSPF 路由表&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip ospf route
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示 OSPF 数据库&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip ospf database
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示 route-map 统计信息&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip protocols ospf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="调试命令">调试命令&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 启用 OSPF 调试&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>debug ospf lsa
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>debug ospf zebra
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看路由重分发情况&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip ospf redistribute
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看各协议路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route static
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route connected
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route bgp
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看 route-map 匹配统计&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route-map detail
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="最佳实践">最佳实践&lt;/h2>
&lt;h3 id="1-命名规范">1. 命名规范&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 使用描述性的名称&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_EXTERNAL_STATIC permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map SET_METRIC_INTERNAL permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map BGP_TO_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-序列号规划">2. 序列号规划&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 使用 10 的倍数，方便插入新规则&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">30&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 后续可以在 10 和 20 之间插入&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">15&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-默认拒绝策略">3. 默认拒绝策略&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 总是添加最后的拒绝规则&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list ALLOW_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>!
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE deny &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>!
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 隐含的 deny any 在最后&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="4-测试配置">4. 测试配置&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 临时设置为 permit 观察效果&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map TEMP_DEBUG permit &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">999&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 确认无误后调整&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>no route-map TEMP_DEBUG permit &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content>&lt;h2 id="概述">概述&lt;/h2>
&lt;p>Route-Map 是 FRR (FRRouting) 中强大的路由策略工具，用于控制 OSPF 路由的发布和接收。通过 Route-Map，可以实现：&lt;/p>
&lt;ul>
&lt;li>路由过滤&lt;/li>
&lt;li>路由属性修改&lt;/li>
&lt;li>条件路由发布&lt;/li>
&lt;/ul>
&lt;h2 id="基本概念">基本概念&lt;/h2>
&lt;h3 id="route-map-结构">Route-Map 结构&lt;/h3>
&lt;p>Route-Map 由一条或多条 &lt;strong>sequence&lt;/strong> 组成，每个 sequence 有：&lt;/p>
&lt;ul>
&lt;li>&lt;strong>匹配条件 (match)&lt;/strong>：定义哪些路由会被处理&lt;/li>
&lt;li>&lt;strong>动作 (action)&lt;/strong>：&lt;code>permit&lt;/code>（允许）或 &lt;code>deny&lt;/code>（拒绝）&lt;/li>
&lt;li>&lt;strong>设置语句 (set)&lt;/strong>：修改路由属性&lt;/li>
&lt;/ul>
&lt;h3 id="顺序执行">顺序执行&lt;/h3>
&lt;p>Route-Map 按序列号从小到大依次执行：&lt;/p>
&lt;ul>
&lt;li>一旦匹配成功，执行对应动作并停止&lt;/li>
&lt;li>如果所有 sequence 都未匹配，默认拒绝&lt;/li>
&lt;/ul>
&lt;h3 id="常用匹配条件">常用匹配条件&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>匹配类型&lt;/th>
&lt;th>说明&lt;/th>
&lt;th>示例&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>ip address&lt;/code>&lt;/td>
&lt;td>匹配 IP 地址/前缀&lt;/td>
&lt;td>&lt;code>match ip address prefix-list LIST&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>interface&lt;/code>&lt;/td>
&lt;td>匹配出接口&lt;/td>
&lt;td>&lt;code>match interface eth0&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>metric&lt;/code>&lt;/td>
&lt;td>匹配路由开销&lt;/td>
&lt;td>&lt;code>match metric 100&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>protocol&lt;/code>&lt;/td>
&lt;td>匹配路由协议类型&lt;/td>
&lt;td>&lt;code>match protocol ospf&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>next-hop&lt;/code>&lt;/td>
&lt;td>匹配下一跳地址&lt;/td>
&lt;td>&lt;code>match ip next-hop A.B.C.D&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>tag&lt;/code>&lt;/td>
&lt;td>匹配路由标签&lt;/td>
&lt;td>&lt;code>match tag 100&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>as-path&lt;/code>&lt;/td>
&lt;td>匹配 AS 路径（BGP）&lt;/td>
&lt;td>&lt;code>match as-path 100&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="支持的协议类型">支持的协议类型&lt;/h3>
&lt;ul>
&lt;li>&lt;code>ospf&lt;/code> - OSPF 路由&lt;/li>
&lt;li>&lt;code>static&lt;/code> - 静态路由&lt;/li>
&lt;li>&lt;code>connected&lt;/code> - 直连路由&lt;/li>
&lt;li>&lt;code>kernel&lt;/code> - 内核路由&lt;/li>
&lt;li>&lt;code>rip&lt;/code> - RIP 路由&lt;/li>
&lt;li>&lt;code>bgp&lt;/code> - BGP 路由&lt;/li>
&lt;li>&lt;code>isis&lt;/code> - IS-IS 路由&lt;/li>
&lt;li>&lt;code>pim&lt;/code> - PIM 路由&lt;/li>
&lt;/ul>
&lt;h2 id="配置示例">配置示例&lt;/h2>
&lt;h3 id="1-基本路由过滤">1. 基本路由过滤&lt;/h3>
&lt;h4 id="场景只允许特定网段的路由进入-ospf">场景：只允许特定网段的路由进入 OSPF&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e"># 定义前缀列表&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ip prefix-list INTERNAL_NETS seq &lt;span style="color:#ae81ff">5&lt;/span> permit 10.0.0.0/8 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ip prefix-list INTERNAL_NETS seq &lt;span style="color:#ae81ff">10&lt;/span> permit 172.16.0.0/12 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ip prefix-list INTERNAL_NETS seq &lt;span style="color:#ae81ff">15&lt;/span> permit 192.168.0.0/16 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ip prefix-list INTERNAL_NETS seq &lt;span style="color:#ae81ff">20&lt;/span> deny any
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e"># 应用到路由重分发&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute connected route-map FILTER_CONNECTED
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 定义 route-map&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_CONNECTED permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list INTERNAL_NETS
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景过滤掉特定路由">场景：过滤掉特定路由&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 定义要过滤的网段&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list BLOCK_NETS seq &lt;span style="color:#ae81ff">5&lt;/span> deny 192.168.100.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list BLOCK_NETS seq &lt;span style="color:#ae81ff">10&lt;/span> permit any
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 应用到路由注入&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> default-information originate route-map FILTER_DEFAULT
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_DEFAULT permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list BLOCK_NETS
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-修改路由属性">2. 修改路由属性&lt;/h3>
&lt;h4 id="场景修改路由开销值">场景：修改路由开销值&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>route-map SET_METRIC permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map SET_METRIC permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list SPECIAL_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">50&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 应用&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute static route-map SET_METRIC
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景根据路由类型设置不同开销">场景：根据路由类型设置不同开销&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>route-map METRIC_BY_TYPE permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list CRITICAL_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map METRIC_BY_TYPE permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list NORMAL_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-条件路由发布">3. 条件路由发布&lt;/h3>
&lt;h4 id="场景只在有特定路由时发布默认路由">场景：只在有特定路由时发布默认路由&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 定义匹配条件&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list ISP_ROUTE seq &lt;span style="color:#ae81ff">5&lt;/span> permit 0.0.0.0/0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map CONDITIONAL_DEFAULT permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list ISP_ROUTE
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> default-information originate route-map CONDITIONAL_DEFAULT always
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="4-重分发控制">4. 重分发控制&lt;/h3>
&lt;h4 id="场景从-bgp-重分发到-ospf-时过滤路由">场景：从 BGP 重分发到 OSPF 时过滤路由&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 只允许特定 BGP 路由进入 OSPF&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list FROM_BGP seq &lt;span style="color:#ae81ff">5&lt;/span> permit 203.0.113.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list FROM_BGP seq &lt;span style="color:#ae81ff">10&lt;/span> permit 198.51.100.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list FROM_BGP seq &lt;span style="color:#ae81ff">15&lt;/span> deny any
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map BGP_TO_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list FROM_BGP
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">50&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric-type type-1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute bgp route-map BGP_TO_OSPF
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景不同协议间重分发">场景：不同协议间重分发&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 静态路由重分发&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map STATIC_TO_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list STATIC_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 直连路由重分发&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map CONNECTED_TO_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match interface eth0 eth1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute connected route-map CONNECTED_TO_OSPF
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute static route-map STATIC_TO_OSPF
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="5-基于-ospf-协议的匹配">5. 基于 OSPF 协议的匹配&lt;/h3>
&lt;h4 id="场景只处理-ospf-协议的路由">场景：只处理 OSPF 协议的路由&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 匹配所有 OSPF 路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map ONLY_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">50&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 在重分发时应用&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute connected route-map ONLY_OSPF
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景排除-ospf-路由处理其他协议">场景：排除 OSPF 路由，处理其他协议&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 排除 OSPF 路由，只允许其他协议的路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXCLUDE_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol static
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol connected
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol kernel
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXCLUDE_OSPF deny &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 或者使用更简洁的方式&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_PROTOCOL permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol static
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">30&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>!
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_PROTOCOL permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol connected
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>!
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 默认拒绝其他协议（包括 ospf）&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="场景根据-ospf-路由类型处理">场景：根据 OSPF 路由类型处理&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 区分 OSPF 内部路由和外部路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map OSPF_INTERNAL permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list INTERNAL_PREFIX
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map OSPF_EXTERNAL permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match protocol ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute ospf route-map OSPF_EXTERNAL
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="6-区域间路由控制">6. 区域间路由控制&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 区域间路由过滤&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> area &lt;span style="color:#ae81ff">1&lt;/span> filter-list prefix IN_AREA1 in
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> area &lt;span style="color:#ae81ff">1&lt;/span> filter-list prefix OUT_AREA1 out
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list IN_AREA1 seq &lt;span style="color:#ae81ff">5&lt;/span> deny 192.168.10.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list IN_AREA1 seq &lt;span style="color:#ae81ff">10&lt;/span> permit 10.0.0.0/8 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list IN_AREA1 seq &lt;span style="color:#ae81ff">15&lt;/span> permit 172.16.0.0/12 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list IN_AREA1 seq &lt;span style="color:#ae81ff">20&lt;/span> permit 192.168.0.0/16 le &lt;span style="color:#ae81ff">24&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="常用命令">常用命令&lt;/h2>
&lt;h3 id="查看配置">查看配置&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示 route-map 配置&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show route-map
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示前缀列表&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip prefix-list
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示 OSPF 路由表&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip ospf route
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示 OSPF 数据库&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip ospf database
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 显示 route-map 统计信息&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip protocols ospf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="调试命令">调试命令&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 启用 OSPF 调试&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>debug ospf lsa
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>debug ospf zebra
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看路由重分发情况&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip ospf redistribute
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看各协议路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route static
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route connected
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route bgp
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看 route-map 匹配统计&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route-map detail
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="最佳实践">最佳实践&lt;/h2>
&lt;h3 id="1-命名规范">1. 命名规范&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 使用描述性的名称&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map FILTER_EXTERNAL_STATIC permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map SET_METRIC_INTERNAL permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map BGP_TO_OSPF permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-序列号规划">2. 序列号规划&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 使用 10 的倍数，方便插入新规则&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">30&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 后续可以在 10 和 20 之间插入&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">15&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-默认拒绝策略">3. 默认拒绝策略&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 总是添加最后的拒绝规则&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list ALLOW_NETS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>!
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE deny &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>!
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 隐含的 deny any 在最后&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="4-测试配置">4. 测试配置&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 临时设置为 permit 观察效果&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map TEMP_DEBUG permit &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">999&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 确认无误后调整&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>no route-map TEMP_DEBUG permit &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="故障排查">故障排查&lt;/h2>
&lt;h3 id="问题-1路由未按预期发布">问题 1：路由未按预期发布&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查 route-map 配置&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show route-map
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查前缀列表匹配&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip prefix-list
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查 OSPF 进程&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show running-config | section router ospf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="问题-2路由开销未生效">问题 2：路由开销未生效&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查 route-map 是否正确应用&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip protocols ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 验证 set 语句&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show route-map &amp;lt;name&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查路由表&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route ospf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="问题-3所有路由都被过滤">问题 3：所有路由都被过滤&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查是否忘记 permit 规则&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show route-map
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 确认最后一条规则&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map EXAMPLE permit &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="问题-4协议匹配不生效">问题 4：协议匹配不生效&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查路由协议类型&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 确认 route-map 中的 protocol 匹配&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show route-map
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show running-config | section route-map
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 验证特定协议的路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route static
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route connected
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查匹配统计&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>show ip route-map detail
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="实战案例">实战案例&lt;/h2>
&lt;h3 id="案例多出口路由选路">案例：多出口路由选路&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 定义 ISP1 的路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list ISP1_ROUTES seq &lt;span style="color:#ae81ff">5&lt;/span> permit 203.0.113.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 定义 ISP2 的路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip prefix-list ISP2_ROUTES seq &lt;span style="color:#ae81ff">5&lt;/span> permit 198.51.100.0/24
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 修改 ISP1 路由开销&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map PREFER_ISP1 permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list ISP1_ROUTES
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map PREFER_ISP1 permit &lt;span style="color:#ae81ff">20&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> match ip address prefix-list ISP2_ROUTES
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">100&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute static route-map PREFER_ISP1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="案例路由聚合">案例：路由聚合&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 创建聚合路由&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ip route 10.0.0.0/8 Null0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 控制聚合路由发布&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>route-map AGGREGATE_ROUTE permit &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric &lt;span style="color:#ae81ff">50&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> set metric-type type-1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>router ospf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> redistribute static route-map AGGREGATE_ROUTE
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="还有一条命令全局过滤prefix-list-blocknet中匹配的路由条目">还有一条命令，全局过滤prefix-list BLOCKNET中匹配的路由条目&lt;/h3>
&lt;p>&lt;code>ip protocol ospf route-map BLOCKNET&lt;/code>&lt;/p>
&lt;h2 id="参考资源">参考资源&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://docs.frrouting.org/">FRR 官方文档&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://tools.ietf.org/html/rfc2328">OSPF 协议 RFC 2328&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.frrouting.org/en/latest/routemap.html">Route-Map 配置参考&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr></content></item></channel></rss>