<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh"><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://blog.luoqing.org/feed.xml" rel="self" type="application/atom+xml" /><link href="https://blog.luoqing.org/" rel="alternate" type="text/html" hreflang="zh" /><updated>2026-05-09T17:39:50+08:00</updated><id>https://blog.luoqing.org/feed.xml</id><title type="html">王宇涛的博客</title><subtitle>Yutao&apos;s Site | 王宇涛的小站
</subtitle><author><name>王宇涛</name></author><entry><title type="html">CCNA-ACL访问控制</title><link href="https://blog.luoqing.org/blog/2023/09/18/CCNA-ACL%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6.html" rel="alternate" type="text/html" title="CCNA-ACL访问控制" /><published>2023-09-18T00:00:00+08:00</published><updated>2023-09-18T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/18/CCNA-ACL%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/18/CCNA-ACL%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6.html"><![CDATA[<p><strong>ACL</strong>（Access Control List，访问控制列表），是一种用于控制网络设备或操作系统中资源的访问权限的机制。</p>
<ul>
  <li>面向数据层面的控制</li>
  <li>
    <h2 id="面向路由层面的控制">面向路由层面的控制</h2>
    <p><strong>数据层面</strong></p>
  </li>
</ul>

<p>根据限制数据的多少、范围的多少分为</p>
<ul>
  <li>标准ACL–只针对源IP地址做限制，1-99之间</li>
  <li>扩展ACL–针对源IP、目的IP、源端口、目的端口、协议号，100-199之间</li>
</ul>

<p>行为上有两种行为，允许permit，拒绝deny。
网络设备内–代表一个策略、代表一项功能
一条接口只能写一个ACL编号</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#R2针对R1（192.168.1.1）标准访问控制</span>
access-list 1 deny host 192.168.1.1
access-list 1 permit any  <span class="c">#因为有默认的最后一条，所以要设置这一条放行</span>
access list 1 deny any  <span class="c">#(默认隐藏在最后一条的，不显示，自上而下检查)</span>
interface f1/0
ip access-group 1 <span class="k">in
</span>show access-list
</code></pre></div></div>
<p>U.U.U 代表Unreachable不可达
… 代表请求超时</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#R2针对R1（192.168.1.1）扩展访问控制，禁ping</span>
interface f1/0
no ip access-group 1 <span class="k">in</span> <span class="c">#取消1访问控制</span>
no access-list 1
conf t
access-list 100 deny icmp host 192.268.1.1 host 192.168.1.2
access-list 100 permit ip any any
interface f1/0
ip access-group 100 <span class="k">in</span>
<span class="c">##这样是收发ping包都被拒绝</span>
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>no access-list 100
access-list 100 deny icmp host 192.268.1.1 host 192.168.1.2 <span class="nb">echo
</span>access-list 100 permit ip any any
conf t
interface f1/0
ip access-group 100 <span class="k">in</span> <span class="c">##挂接到接口</span>
<span class="c">##只拒绝R1发到R2的echo包</span>
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>access-list 100 deny tcp host 192.168.1.1 host 192.168.1.2 eq telnet <span class="c">##eq=equal,拒绝telnet</span>
access-list 100 deny tcp host 192.168.1.1 host 192.168.1.2 eq 23 <span class="c">##和上面一样</span>
access-list 100 permit ip any any
conf t
interface f1/0
ip access-group 100 <span class="k">in</span> 
</code></pre></div></div>

<p>如果想添加条目</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>show access-lists <span class="c">##查看ACL列表</span>
conf t
ip access-list extended 100 <span class="c">##进入ACL，如果是标准访问控制，ip access-list standard  1</span>
15 deny icmp host 192.268.1.1 host 192.168.1.2 <span class="nb">echo</span> <span class="c">#15是插入子编号，acl列表有子编号10和20之间</span>
</code></pre></div></div>
<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/40c51ac0-8fc0-4b6c-b7f0-c7e88fe73ce5" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>no 15  <span class="c">#把15子编号条目去掉</span>
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>access-list 100 permit tcp host 192.168.1.1 host 192.168.1.2 eq 80 <span class="c">##允许192.168.1.1访问192.168.1.2的http网页</span>
access-list 100 permit tcp host 192.168.1.1 host 192.168.1.2 eq 443 <span class="c">##允许192.168.1.1访问192.168.1.2的https网页</span>
access-list 100 permit udp host 192.168.1.1 host 192.168.1.2 eq 53 <span class="c">##允许192.168.1.1访问192.168.1.2的DNS服务</span>
</code></pre></div></div>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[ACL（Access Control List，访问控制列表），是一种用于控制网络设备或操作系统中资源的访问权限的机制。 面向数据层面的控制 面向路由层面的控制 数据层面]]></summary></entry><entry><title type="html">CCNA-EIGRP协议</title><link href="https://blog.luoqing.org/blog/2023/09/18/CCNA-EIGRP%E5%8D%8F%E8%AE%AE.html" rel="alternate" type="text/html" title="CCNA-EIGRP协议" /><published>2023-09-18T00:00:00+08:00</published><updated>2023-09-18T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/18/CCNA-EIGRP%E5%8D%8F%E8%AE%AE</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/18/CCNA-EIGRP%E5%8D%8F%E8%AE%AE.html"><![CDATA[<h2 id="eigrp">EIGRP</h2>
<p><strong>EIGRP—思科私有</strong></p>

<p>协议好坏：路由切换速度；计算路由准确度</p>

<p><strong>三张表</strong></p>
<ul>
  <li>路由表—最终选路标准</li>
  <li>拓扑表—R1将路由表发送给R2，R2暂存到拓扑表，计算拓扑表最优的，更新路由表</li>
  <li>邻居表—EIGRP有邻居概念，如果邻居中断（hello包检测），那么就会删除该邻居的路由表。</li>
</ul>

<p><strong>EIGRP特点</strong></p>
<ul>
  <li>采用不定期触发更新，即只在路由器改变计量标准成拓扑出现变化时发送部分更新路由</li>
  <li>更新条目中包含掩码，支持VLSM（RIPV2也支持）</li>
  <li>具有相同的自治系统号的EIGRP和IGRP之间，可无缝交换路由信息。</li>
</ul>

<p><strong>EIGRP主要功能</strong></p>
<ul>
  <li>通过协议相关模块支持IP IPX,Apple Tallk</li>
  <li>支持<strong>VLSM</strong>（可变长子网掩码）和CIDR（超网，支持更新类似192.0.0.0的网段）</li>
  <li>有效邻居发现</li>
  <li>基于可靠传输协议( RTP）的通信</li>
  <li>基于弥散更新算法(DUAL）的最佳路径的</li>
</ul>

<p><strong>邻居发现</strong></p>

<p>EIGRP路由器彼此交换路由必须是邻居，建立邻居关系要满足以下三点：</p>

<ul>
  <li>收到hello或ACK（5s发送一次hello包，15s没收到邻居中断）</li>
  <li>匹配AS号 (router eigrp xxx，这个xxx就说AS自治系统号）</li>
  <li>相同度量（不同方向接收到了相同的路由条目来自相同协议，比较度量值：带宽、延迟、可靠性、负载、MTU，默认参考带宽和延迟），要有相同的参考度量</li>
</ul>

<p><strong>术语</strong>：</p>
<ul>
  <li>可行距离（FD）：当前设备到达目标网段的全程距离</li>
  <li>被报告距离值（AD）：邻居设备到达目标网段的全程距离</li>
  <li>继任者：最优线路的下一跳设备</li>
  <li>可行继任者：备份线路下一跳设备</li>
  <li>可靠传输协议（RTP）：是用来管理EIGRP数据包的发送和接受的协议。发送路由器将更新信息发送到组播IP地址224.0.0.10，每一个接收可靠组播数据包的邻居都会发送一个单播的确认数据包。如果EIGRP没有从某个邻居那里得到应答，它将使用单播来重发同样的数据，如果在16次单播尝试后，它仍然没有应答，则此邻居将被宣告消失。</li>
  <li>弥散更新算法（DUAL）：EIGRP确定最佳无环路径和无环备用路径的方法，找邻居扩散消息(找备胎)。</li>
</ul>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>router eigrp 100  <span class="c">#100是AS</span>
no auto summary <span class="c">#关闭自动汇总网段，自动汇总会导致黑洞</span>
network 192.168.1.0 0.0.0.255 <span class="c">#反掩码，用255.255.255.255减去它</span>
show ip eigrp neighbors <span class="c">#查看邻居表</span>
show ip eigrp topology <span class="c">#查看拓扑表</span>
show ip route eigrp <span class="c">#只查看eigrp的路由表,显示出来的[管理距离/度量值（FD可行距离）]</span>
show ip protocols <span class="c">#查看本地运行的协议</span>
</code></pre></div></div>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[EIGRP EIGRP—思科私有]]></summary></entry><entry><title type="html">CCNA-OSPF协议</title><link href="https://blog.luoqing.org/blog/2023/09/18/CCNA-OSPF%E5%8D%8F%E8%AE%AE.html" rel="alternate" type="text/html" title="CCNA-OSPF协议" /><published>2023-09-18T00:00:00+08:00</published><updated>2023-09-18T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/18/CCNA-OSPF%E5%8D%8F%E8%AE%AE</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/18/CCNA-OSPF%E5%8D%8F%E8%AE%AE.html"><![CDATA[<h2 id="ospf">OSPF</h2>
<p>OSPF–Open shortest path first–开放式最短路径优先协议</p>

<p>链路状态协议—LSA更新—链路状态通告更新</p>

<p>OSPF度量值—10^8/带宽=cost</p>

<p>触发更新，周期更新（1800s）</p>

<p><strong>OSPF的优点</strong></p>
<ul>
  <li>对网络发生的变化快速响应</li>
  <li>对网络发生的变化发送触发更新</li>
  <li>支持VLSM</li>
  <li>方便管理</li>
</ul>

<p><strong>三张表</strong></p>
<ul>
  <li>邻居表—show ip ospf neighbor</li>
  <li>链路状态数据库—show  ip ospf database—R1将数据库发送给R2，收到存放到自己数据库，计算最优的，放入路由表</li>
  <li>路由表—show ip route ospf</li>
</ul>

<p><strong>OSPF 邻居邻接关系</strong></p>

<ul>
  <li>邻居—2-way状态—只发送hello包，不发送路由更新LSA</li>
  <li>邻接—Full状态—既发送hello包，又发送路由更新LSA
邻居hello包进行检测（10s发送一次hello包，40s未收到邻居中断）</li>
</ul>

<p>为什么要有不同的邻居关系？
不同网络环境，例如MA多路访问网络环境。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/ebece000-b515-4ff5-8dd5-7640f0dd2b3e" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>router ospf 100  <span class="c">#&lt;1-65535&gt; 进程号</span>
<span class="c">#EIGRP：R1和R2运行的EIGRP自治系统号必须一致</span>
<span class="c">#ospf：进程号可以不一致</span>
router-id 1.1.1.1 <span class="c">#手动唯一标识</span>
network 192.168.1.0  0.0.0.255 area 0 <span class="c">#area 0 骨干区域</span>
network 1.1.1.0  0.0.0.255 area 0
show ip ospf neighbor <span class="c"># 查看接口邻居信息，显示的对端id就是router-id</span>
show ip ospf interface  <span class="c">#查看区域号相关信息</span>
show ip ospf database  <span class="c">#查看ospf的数据库信息</span>
show ip protocols <span class="c">#查看本地运行的路由协议</span>
</code></pre></div></div>
<p>router id不手动配置的选举机制</p>
<ul>
  <li>本地回环接口的IP最大的，选举成router-id</li>
  <li>本地物理接口的IP最大的，选举成router-id</li>
</ul>

<p><strong>DR BDR DROEHERS</strong>选举机制</p>

<p>大哥 二哥 小弟</p>
<ul>
  <li>先比较优先级–越大成为DR–默认为1</li>
  <li>再比较router-id–越大成为DR</li>
</ul>

<p>实际环境中先启动ospf的设备为DR</p>

<p><strong>组播更新</strong></p>

<p>RIPV2—组播地址–224.0.0.9
EIGRP–组播地址–224.0.0.10
OSPF–组播地址–224.0.0.5/224.0.0.6
所有的路由器彼此之间交换hello包的时候通过224.0.0.5
DR BDR监听224.0.0.6，DROEHERS一旦有LSA路由更新发送到224.0.0.6
DROEHERS监听224.0.0.5，DR BDR一旦有LSA路由更新发送到224.0.0.5</p>

<p><strong>OSPF算法</strong>：SPF算法，最短路径优先算法</p>

<p><strong>五种OSPF信息类型</strong></p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/c3b4c637-2426-4d3e-86f4-909d54a9f591" alt="image" /></p>

<p>HELLO包：建立维系邻居关系
DBD包：数据库描述信息包，路由更新的镜像摘要
LSR包：链路状态请求包，对照DBD请求没有重复的路由更新
LSU包：路由更新
LSACK包：链路状态确认信息包</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/e31fb498-e11a-4a5c-8cf9-de4c3399ef75" alt="image" /></p>

<p>OSPF 刚刚启动，down状态；一旦发送hello包进入init状态，一旦接收到hello包，进入2-way状态；交换hello包，比较router-id进入exstart状态，开始交换DBD包，进入exchange状态；开始交换LSR、LSU、LSACK进入Loading状态；交换完毕进入full状态。</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>interface f0/0
ip ospf priority 100 <span class="c">#修改端口优先值，重启dr/bdr生效</span>
</code></pre></div></div>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[OSPF OSPF–Open shortest path first–开放式最短路径优先协议]]></summary></entry><entry><title type="html">CCNA-RIP协议</title><link href="https://blog.luoqing.org/blog/2023/09/18/CCNA-RIP%E5%8D%8F%E8%AE%AE.html" rel="alternate" type="text/html" title="CCNA-RIP协议" /><published>2023-09-18T00:00:00+08:00</published><updated>2023-09-18T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/18/CCNA-RIP%E5%8D%8F%E8%AE%AE</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/18/CCNA-RIP%E5%8D%8F%E8%AE%AE.html"><![CDATA[<p><strong>动态路由协议</strong></p>
<ul>
  <li>距离矢量协议(distance vector)主要有：RIP IGRP BGP</li>
  <li>链路状态协议(Link state)有：OSPF IS-IS</li>
  <li>混合型(hybrid)有：EIGRP</li>
</ul>

<p><strong>DV路由协议的特征</strong></p>
<ul>
  <li>采用周期性的完全更新(发送整个路由表)和触发
更新结合的路由更新方式（RIPV1没有触发更新，RIPV2才有触发更新的）</li>
  <li>采用广播方式进行路由更新（RTPV2采用的是组播）</li>
  <li>DV的路由协议有RIPV1, RIPv2,IGRP</li>
  <li>EIGRP和BGP属于高级的DV协议，他们学习路径的方式更多的趋近于DV，但是他们具备很多的<strong>LS特征</strong>（比如触发更新，组播更新等）</li>
</ul>

<p><strong>距离矢量协议</strong>– RIP EIGRP BGP：依照传闻选择路径 ，传递路由表，自己路由表发给你直接用，如果自己的路由表本身就是错的就会都错。
<strong>链路状态协议</strong>– OSPF ISIS：传递的链路状态信息，自己判断</p>

<p><strong>实用性协议排名</strong>：</p>
<ol>
  <li>EIGRP</li>
  <li>OSPF</li>
  <li>BGP</li>
</ol>

<p>IGP—RIP EIGRP OSPF 通常用在企业内部
EGP–BGP EGP  ISIS 通常用在运营商和数据中心之间</p>

<p><strong>为什么用动态路由协议</strong></p>
<ol>
  <li>方便更新 不需要手动配置</li>
  <li>冗余备份</li>
</ol>

<p>RIP协议中—没有邻居关系的概念—没有hello包检测
RIP协议—周期更新—30s更新一次，收到条目设置一个180s的死亡倒计时，down掉，60s之后删除该路由条目</p>

<p><strong>路由器选择路径</strong></p>

<ol>
  <li>管理距离—不同方向接收到不同路由协议固定的数值</li>
  <li>度量值–跳数</li>
</ol>

<p><strong>环路</strong>：从一个接口收到的数据又从这个接口发出去，来回反复。</p>

<p>水平分割：从一个接口收到的数据不会从这个接口发出去</p>

<p>毒性逆转的水平分割：从一个接口收到的数据会从这个接口发出去。但是将这条路由标记为16跳，然后不可达。</p>

<p><strong>解决环路的办法</strong></p>
<ul>
  <li>水平分割</li>
  <li>毒性逆转</li>
  <li>触发更新</li>
  <li>最大跳数</li>
</ul>

<p><strong>RIP缺点</strong></p>
<ul>
  <li>周期更新，浪费带宽</li>
  <li>计量标准，以跳数为标准不准确</li>
  <li>收敛速度，缓慢</li>
</ul>

<p><strong>收敛时间</strong>：网络拓扑发生变化到网络中所有路由器知道这个变化的时间。</p>

<p>RIPV1没有触发更新，RIPV2才有触发更新的</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>router rip
version 2
no auto summary 关闭自动汇总网段，自动汇总会导致黑洞
network 192.168.1.0 宣告网段

</code></pre></div></div>

<p><strong>RIPV1和RIPV2区别</strong></p>

<p>1.RIPv1是有类 路由协议,RIPv2是 无类路由协议 2.RIPv1不能支持VLSM,RIPv2可以支持VLSM 3.RIPv1没有认证的功能,RIPv2可以支持认证,并且有明文和MD5两种认证 4.RIPv1没有手工汇总的功能,RIPv2可以在关闭自动汇总的前提下,进行手工汇总 5.RIPv1是广播更新,RIPv2是组播更新。</p>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[动态路由协议 距离矢量协议(distance vector)主要有：RIP IGRP BGP 链路状态协议(Link state)有：OSPF IS-IS 混合型(hybrid)有：EIGRP]]></summary></entry><entry><title type="html">CCNA-STP生成树协议</title><link href="https://blog.luoqing.org/blog/2023/09/18/CCNA-STP%E7%94%9F%E6%88%90%E6%A0%91%E5%8D%8F%E8%AE%AE.html" rel="alternate" type="text/html" title="CCNA-STP生成树协议" /><published>2023-09-18T00:00:00+08:00</published><updated>2023-09-18T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/18/CCNA-STP%E7%94%9F%E6%88%90%E6%A0%91%E5%8D%8F%E8%AE%AE</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/18/CCNA-STP%E7%94%9F%E6%88%90%E6%A0%91%E5%8D%8F%E8%AE%AE.html"><![CDATA[<p><strong>STP</strong>：生成树协议 802.1D/PVST/RSTP/MST等</p>

<p><strong>生成树目的</strong>：实现一个无环的冗余的网络环境；实现负载均衡效果；实现最小化的交换机的运算</p>

<p><strong>选举机制</strong>：断哪个交换机的接口？根桥和非根桥，根桥上的所有接口都不能block掉；</p>

<p><strong>如何选举根桥？</strong></p>
<ul>
  <li>BID（BridgeID）= 桥ID</li>
  <li>Bridge Priority = 桥优先级–默认出厂数值32768–可以手动调整，越小越好，但数值必须是4096的倍数</li>
  <li>Bridge MAC address–用于自动选择–基本MAC地址=标准MAC地址=背板MAC地址（理解成主板上的MAC地址）越小越好</li>
</ul>

<p><strong>非根桥的接口断哪个</strong>？</p>
<ul>
  <li>path cost=通过带宽对应出来的一个数值，断path cost大的，带宽小的。</li>
</ul>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/ac72199f-374f-4593-8738-825f7d1d4229" alt="image" /></p>

<ul>
  <li>带宽一样比较PID—Port ID：Port priority = 128 端口优先级，越小越好（16的倍数），可人为修改。Port num：端口号  （对端根桥端口号越小越好，断对端端口号大的，例如f0/1和f0/2，断f0/2）</li>
</ul>

<p>非根桥连接根桥的那个活着的端口叫做<strong>根端口</strong>
被断掉的端口叫做<strong>非指派端口</strong>
根桥上的所有接口又称之为<strong>指派端口</strong></p>

<p>通过BPDU信息进行选举，网桥协议数据单元(BPDU,Bridge Protocol Data Unit)</p>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[STP：生成树协议 802.1D/PVST/RSTP/MST等]]></summary></entry><entry><title type="html">CCNA-交换VLAN</title><link href="https://blog.luoqing.org/blog/2023/09/18/CCNA-%E4%BA%A4%E6%8D%A2VLAN.html" rel="alternate" type="text/html" title="CCNA-交换VLAN" /><published>2023-09-18T00:00:00+08:00</published><updated>2023-09-18T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/18/CCNA-%E4%BA%A4%E6%8D%A2VLAN</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/18/CCNA-%E4%BA%A4%E6%8D%A2VLAN.html"><![CDATA[<p>局域网：通过一台交换机进行互联，组成网络，将相同IP地址段的数据进行转发。</p>

<p><strong>VLAN</strong>：虚拟局域网，virtual lan，把一个物理交换机，人为划分成N个逻辑子交换机。二层隔离广播。</p>

<p><strong>VLAN特点</strong>：分段、灵活性、安全性。</p>

<p><strong>VLAN模式</strong>：1.access接入模式—下游路由器或者PC。2.trunk模式—干道模式—对端连接交换机。默认情况下交换机接口是动态模式，手动配置不要成为动态。</p>

<p><strong>跨交换机的相同VLAN可以互通，相同交换机的不同VLAN不互通。</strong></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>interface e0/1
switchport mode access
switchport access vlan 10
<span class="nb">exit

</span>interface e0/2
switchport mode access
switchport access vlan 20
<span class="nb">exit
</span>show vlan brief
</code></pre></div></div>
<p>干道模式：</p>
<ul>
  <li>ISL干道模式—思科私有；
封装性标签</li>
  <li>802.1q干道模式—公有模式（dotiq）
插入式标签</li>
</ul>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>interface e0/0
switchport trunk encapaulation dotiq <span class="c">#较早的交换机可能需要先确定使用的模式</span>
switchport mode trunk <span class="c">#修改trunk模式</span>
show interface trunk <span class="c"># 查看trunk接口模式</span>
</code></pre></div></div>

<p>替代VLAN的方法：端口隔离</p>

<p>解决VLAN跳跃攻击</p>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[局域网：通过一台交换机进行互联，组成网络，将相同IP地址段的数据进行转发。]]></summary></entry><entry><title type="html">CCNA-静态路由</title><link href="https://blog.luoqing.org/blog/2023/09/18/CCNA-%E9%9D%99%E6%80%81%E8%B7%AF%E7%94%B1.html" rel="alternate" type="text/html" title="CCNA-静态路由" /><published>2023-09-18T00:00:00+08:00</published><updated>2023-09-18T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/18/CCNA-%E9%9D%99%E6%80%81%E8%B7%AF%E7%94%B1</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/18/CCNA-%E9%9D%99%E6%80%81%E8%B7%AF%E7%94%B1.html"><![CDATA[<h2 id="路由">路由</h2>
<p><strong>为什么要路由</strong></p>

<p>路由器—转发数据—通过路由表（地图）—接收到数据从下一个口出去—的中转设备</p>

<p>路由器作用：跨网段转发</p>

<p>要实现路由，路由器必须知道：目的地址、源地址、所有可能的路由路径、最佳路由路径、管理路由信息（比较单位）</p>

<p><strong>路由表怎么形成</strong>
各种各样的路由协议—查表转发—逐跳查询—逐跳转发
跳—路由器—防火墙设备
每一台路由器查询 查询路由表 每一台路由器转发 转发下一跳 多么大型的网络都是查询转发
<strong>地图</strong>=<strong>路由表</strong>=正确的（各种各样的路由协议构建路由表）=保存的路由条目
可以把<strong>每一台路由器=快递站点</strong>
目的地：长沙
邮寄地址：上海
汇总起来一跳一跳下发：上海，杭州，南昌，长沙</p>

<p><strong>路由表</strong>
路由表以网段的形式表示
类型：S  O  B通过各种各样的路由协议形成，D是EIGRP，E是EGP</p>

<p>被路由协议—OSI模型第三层 TCP/IP协议（IP IPX APPLETALK）
路由协议—OSI模型第四层 构建起来的路由表（RIP EIGRP OSPF）
路由协议基于被路由协议形成</p>

<p><strong>静态路由</strong>：每一条都是手动写上去的
<strong>动态路由</strong>：路由器和路由器彼此之间互相学习形成表，彼此自己知道的地告诉对方就说路由同步，发送更新，根据网络结构流量变化自动调整</p>

<p><strong>静态路由优缺点</strong>：
优点：对路由器CPU没有管理性开销；在路由器间没有带窝占用；增加安全性
缺点：必须真正了解网络；对于新添网络配賈繁琐；对于大型网络工作量巨大</p>

<p>管理距离：路由协议优先级
动态路由协议适用于大型的网络环境</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/fedba78d-8c55-4481-b1e1-72a43bd36b1a" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">enable
</span>conf t
host R1
interface f0/0
ip add 192.168.1.1 255.255.255.0
show ip interface brief
ip route 192.168.2.2 255.255.255.255 192.168.1.2
</code></pre></div></div>
<p>缺省路由：又网络地址和掩码都是全0，可匹配任意目的网络前缀,比较特殊的静态路由。</p>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[路由 为什么要路由]]></summary></entry><entry><title type="html">SLA-BFD故障检测</title><link href="https://blog.luoqing.org/blog/2023/09/13/SLA-BFD%E6%95%85%E9%9A%9C%E6%A3%80%E6%B5%8B.html" rel="alternate" type="text/html" title="SLA-BFD故障检测" /><published>2023-09-13T00:00:00+08:00</published><updated>2023-09-13T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/13/SLA-BFD%E6%95%85%E9%9A%9C%E6%A3%80%E6%B5%8B</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/13/SLA-BFD%E6%95%85%E9%9A%9C%E6%A3%80%E6%B5%8B.html"><![CDATA[<h2 id="浮动路由">浮动路由</h2>

<p>浮动路由又称为路由备份，两条或多条链路组成浮动路由，相同的目的地址，不同的下一跳地址，另一条下一跳的优先级低</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/59aff1ff-00fc-4d23-a3d1-c0ec2fc2a57f" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router1 F0/0 &lt;<span class="nt">----</span><span class="o">&gt;</span> Router2 F1/0 
Router2 F0/0 &lt;<span class="nt">----</span><span class="o">&gt;</span> Router3 F1/0 
Router3 F0/0 &lt;<span class="nt">----</span><span class="o">&gt;</span> Router4 F1/0 
</code></pre></div></div>

<p>SLA是秒级检测，BFD是毫秒级检测
BFD是公有的，SLA是思科私有的，所以在华为上没有SLA</p>

<h2 id="静态路由sla故障检测">静态路由+SLA故障检测</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GW<span class="o">(</span>config<span class="o">)</span><span class="c">#ip sla monitor 123 </span>
GW<span class="o">(</span>config-sla-monitor<span class="o">)</span><span class="c">#type e</span>
GW<span class="o">(</span>config-sla-monitor<span class="o">)</span><span class="c">#type echo pro</span>
GW<span class="o">(</span>config-sla-monitor<span class="o">)</span><span class="c">#type echo protocol ipi</span>
GW<span class="o">(</span>config-sla-monitor<span class="o">)</span><span class="c">#type echo protocol ipicmpEcho 100.1.1.1</span>
GW<span class="o">(</span>config-sla-monitor-echo<span class="o">)</span><span class="c">#freq</span>
GW<span class="o">(</span>config-sla-monitor-echo<span class="o">)</span><span class="c">#frequency 5</span>
GW<span class="o">(</span>config-sla-monitor-echo<span class="o">)</span><span class="c">#end           </span>
GW#show run         
Building configuration...

Current configuration : 723 bytes
<span class="o">!</span>
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
<span class="o">!</span>
<span class="nb">hostname </span>GW
<span class="o">!</span>
boot-start-marker
boot-end-marker
<span class="o">!</span>
<span class="o">!</span>
no aaa new-model
memory-size iomem 5
<span class="o">!</span>
<span class="o">!</span>
ip cef
<span class="o">!</span>
<span class="o">!</span>
ip sla monitor 123
 <span class="nb">type echo </span>protocol ipIcmpEcho 100.1.1.1

GW<span class="o">(</span>config<span class="o">)</span><span class="c">#ip sla monitor schedule 123 start-time now life forever </span>
GW<span class="o">(</span>config<span class="o">)</span><span class="c">#track 321 rtr 123</span>
GW<span class="o">(</span>config-track<span class="o">)</span><span class="c">#end</span>
GW#
<span class="k">*</span>Mar  1 04:07:23.926: %SYS-5-CONFIG_I: Configured from console by console
GW#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
GW<span class="o">(</span>config<span class="o">)</span><span class="c">#no ip route 0.0.0.0 0.0.0.0 100.1.1.1</span>
GW<span class="o">(</span>config<span class="o">)</span><span class="c">#ip route 0.0.0.0 0.0.0.0 100.1.1.1 track 321</span>

GW#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external <span class="nb">type </span>1, N2 - OSPF NSSA external <span class="nb">type </span>2
       E1 - OSPF external <span class="nb">type </span>1, E2 - OSPF external <span class="nb">type </span>2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, <span class="k">*</span> - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is 100.1.1.1 to network 0.0.0.0

     100.0.0.0/24 is subnetted, 1 subnets
C       100.1.1.0 is directly connected, FastEthernet1/0
C    200.1.1.0/24 is directly connected, FastEthernet0/0
S<span class="k">*</span>   0.0.0.0/0 <span class="o">[</span>1/0] via 100.1.1.1

GW#ping 123.1.1.1 repeat 500
</code></pre></div></div>
<p>ping 的同时在 Telecom路由器down掉接口观察效果，再up接口</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Telecom#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Telecom<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Telecom<span class="o">(</span>config-if<span class="o">)</span><span class="c">#sh</span>
Telecom<span class="o">(</span>config-if<span class="o">)</span><span class="c">#</span>
<span class="k">*</span>Mar  1 04:18:04.726: %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
<span class="k">*</span>Mar  1 04:18:05.726: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
Telecom<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no sh</span>
Telecom<span class="o">(</span>config-if<span class="o">)</span><span class="c">#</span>
<span class="k">*</span>Mar  1 04:19:30.486: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
<span class="k">*</span>Mar  1 04:19:31.486: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Telecom<span class="o">(</span>config-if<span class="o">)</span><span class="c">#</span>
</code></pre></div></div>
<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/4ad9bba7-9193-429b-9715-b9d27de8178c" alt="image" /></p>

<p>CEF表—cisco express forwarding	思科快速转发 //show ip cef
CEF基于路由表</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/fae3ff0f-f741-4466-b730-3b8c2180155c" alt="image" /></p>

<h2 id="静态路由bfd故障检测">静态路由+BFD故障检测</h2>

<p>按需路由选择<strong>ODR</strong>（On Demand Routing），ODR基于Cisco发现协议<strong>CDP</strong>（Cisco discovery protocol），检测设备与设备之间的互联。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/f57ed26d-9a86-442f-96f9-a9b58e8d5409" alt="image" /></p>

<p>CDP可以发现相连的对端设备</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GW#show cdp neighbors detail 
<span class="nt">-------------------------</span>
Device ID: Unicom
Entry address<span class="o">(</span>es<span class="o">)</span>: 
  IP address: 200.1.1.1
Platform: Cisco 3640,  Capabilities: Router Switch IGMP 
Interface: FastEthernet0/0,  Port ID <span class="o">(</span>outgoing port<span class="o">)</span>: FastEthernet1/0
Holdtime : 127 sec

Version :
Cisco IOS Software, 3600 Software <span class="o">(</span>C3640-IK9O3S-M<span class="o">)</span>, Version 12.4<span class="o">(</span>10<span class="o">)</span>, RELEASE SOFTWARE <span class="o">(</span>fc1<span class="o">)</span>
Technical Support: http://www.cisco.com/techsupport
Copyright <span class="o">(</span>c<span class="o">)</span> 1986-2006 by Cisco Systems, Inc.
Compiled Wed 16-Aug-06 04:04 by prod_rel_team

advertisement version: 2
VTP Management Domain: <span class="s1">''</span>
Duplex: full

<span class="nt">-------------------------</span>
Device ID: Telecom
Entry address<span class="o">(</span>es<span class="o">)</span>: 
  IP address: 100.1.1.1
Platform: Cisco 3640,  Capabilities: Router Switch IGMP 
Interface: FastEthernet1/0,  Port ID <span class="o">(</span>outgoing port<span class="o">)</span>: FastEthernet0/0
Holdtime : 134 sec
          
Version : 
Cisco IOS Software, 3600 Software <span class="o">(</span>C3640-IK9O3S-M<span class="o">)</span>, Version 12.4<span class="o">(</span>10<span class="o">)</span>, RELEASE SOFTWARE <span class="o">(</span>fc1<span class="o">)</span>
Technical Support: http://www.cisco.com/techsupport
Copyright <span class="o">(</span>c<span class="o">)</span> 1986-2006 by Cisco Systems, Inc.
Compiled Wed 16-Aug-06 04:04 by prod_rel_team
          
advertisement version: 2
VTP Management Domain: <span class="s1">''</span>
Duplex: full
</code></pre></div></div>
<p>ODR</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/f09423cb-4215-4594-8e0a-72a93018228e" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GW<span class="o">(</span>config<span class="o">)</span><span class="c">#router odr  ##在核心设备出口开启odr，就可以给下层设备下发odr路由，就不用在下层设备配置默认路由。</span>
</code></pre></div></div>
<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/e1f10f9e-8ac1-4b61-af85-f94132628617" alt="image" /></p>

<p><strong>华为</strong></p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/e0e54942-fd53-4b29-b67d-e85a4c7367dd" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;Huawei&gt;sys
<span class="o">[</span>Huawei]sys Telecom
<span class="o">[</span>Telecom]int e0/0/0
<span class="o">[</span>Telecom-Ethernet0/0/0]ip add 100.1.1.1 255.255.255.0
<span class="o">[</span>Telecom-Ethernet0/0/0]q
<span class="o">[</span>Telecom]interface LoopBack 0
<span class="o">[</span>Telecom-LoopBack0]ip add 123.1.1.1 255.255.255.0
<span class="o">[</span>Telecom-LoopBack0] q
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>Huawei]sys 
<span class="o">[</span>Huawei]sys Unicom
<span class="o">[</span>Unicom]int e0/0/0
<span class="o">[</span>Unicom-Ethernet0/0/0]ip add 200.1.1.1 255.255.255.0
<span class="o">[</span>Unicom-Ethernet0/0/0]q
<span class="o">[</span>Unicom]interface LoopBack 0
<span class="o">[</span>Unicom-LoopBack0] ip add 123.1.1.1 255.255.255.0
<span class="o">[</span>Telecom-LoopBack0] q
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;Huawei&gt;sys
<span class="o">[</span>Huawei]sys GW
<span class="o">[</span>GW]int e0/0/0
<span class="o">[</span>GW-Ethernet0/0/0]ip add 100.1.1.2 255.255.255.0
<span class="o">[</span>GW-Ethernet0/0/0]q
<span class="o">[</span>GW]int e0/0/1
<span class="o">[</span>GW-Ethernet0/0/1]ip add 200.1.1.2 255.255.255.0
<span class="o">[</span>GW-Ethernet0/0/1]q
<span class="o">[</span>GW]ip route-static 0.0.0.0 0.0.0.0 100.1.1.1     <span class="c">##华为默认路由是60，而思科是1</span>
<span class="o">[</span>GW]ip route-static 0.0.0.0 0.0.0.0 200.1.1.1 preference 70

<span class="o">[</span>GW]display ip routing-table 
Route Flags: R - relay, D - download to fib
<span class="nt">------------------------------------------------------------------------------</span>
Routing Tables: Public
         Destinations : 7        Routes : 7        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        0.0.0.0/0   Static  60   0          RD   100.1.1.1       Ethernet0/0/0
      100.1.1.0/24  Direct  0    0           D   100.1.1.2       Ethernet0/0/0
      100.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/0
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
      200.1.1.0/24  Direct  0    0           D   200.1.1.2       Ethernet0/0/1
      200.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/1

<span class="o">[</span>GW]int e0/0/0
<span class="o">[</span>GW-Ethernet0/0/0]shutdown 
<span class="o">[</span>GW-Ethernet0/0/0]display ip routing-table 
Route Flags: R - relay, D - download to fib
<span class="nt">------------------------------------------------------------------------------</span>
Routing Tables: Public
         Destinations : 5        Routes : 5        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        0.0.0.0/0   Static  70   0          RD   200.1.1.1       Ethernet0/0/1
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
      200.1.1.0/24  Direct  0    0           D   200.1.1.2       Ethernet0/0/1
      200.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/1

<span class="o">[</span>GW-Ethernet0/0/0]undo shutdown 
<span class="o">[</span>GW-Ethernet0/0/0]display ip routing-table 
Route Flags: R - relay, D - download to fib
<span class="nt">------------------------------------------------------------------------------</span>
Routing Tables: Public
         Destinations : 7        Routes : 7        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        0.0.0.0/0   Static  60   0          RD   100.1.1.1       Ethernet0/0/0
      100.1.1.0/24  Direct  0    0           D   100.1.1.2       Ethernet0/0/0
      100.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/0
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
      200.1.1.0/24  Direct  0    0           D   200.1.1.2       Ethernet0/0/1
      200.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/1

</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>GW-Ethernet0/0/0]ping <span class="nt">-c</span> 20 123.1.1.1
</code></pre></div></div>
<p>电信接口模拟down，发现无法故障切换路由</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>Telecom]int e0/0/0
<span class="o">[</span>Telecom-Ethernet0/0/0]shutdown 
</code></pre></div></div>
<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/e3437fb0-ccb3-4d4c-ad80-2508de252532" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>Telecom-Ethernet0/0/0]undo shutdown
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>GW-Ethernet0/0/0]q
<span class="o">[</span>GW]bfd <span class="c">##全局开启bfd</span>
<span class="o">[</span>GW-bfd]q
<span class="o">[</span>GW]bfd CCIE <span class="nb">bind </span>peer-ip 100.1.1.1 interface e0/0/0 one-arm-echo  <span class="c">##开启bfd，网关e0/0/0接口检测对端100.1.1.1，单臂回声模式</span>
<span class="o">[</span>GW-bfd-session-CCIE]min-echo-rx-interval 100  <span class="c">##100ms</span>
<span class="o">[</span>GW-bfd-session-CCIE]discriminator <span class="nb">local </span>123  <span class="c">##本地回声标识符</span>
<span class="o">[</span>GW-bfd-session-CCIE]commit <span class="c">##生效开启</span>
<span class="o">[</span>GW-bfd-session-CCIE]q
<span class="o">[</span>GW]undo ip route-static 0.0.0.0 0.0.0.0 100.1.1.1 <span class="c">##取消静态路由</span>
<span class="o">[</span>GW]ip route-static 0.0.0.0 0.0.0.0 100.1.1.1 track bfd-session CCIE <span class="c">##重新设置静态路由挂接bfd</span>
<span class="o">[</span>GW]ping <span class="nt">-c</span> 20 123.1.1.1
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>Telecom]int e0/0/0
<span class="o">[</span>Telecom-Ethernet0/0/0]shutdown
</code></pre></div></div>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/cba8550d-06ab-474a-9b79-97e2cd0b4e1e" alt="image" /></p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/f6361cbd-6f5f-49ed-8e91-4a2aea70fb09" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>Telecom]int e0/0/0
<span class="o">[</span>Telecom-Ethernet0/0/0]undo shutdown 
</code></pre></div></div>

<h2 id="动态路由bfd故障检测">动态路由+BFD故障检测</h2>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/69bd4e76-ab10-479e-a862-25aed89f543a" alt="image" /></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>GW]undo ip route-static 0.0.0.0 0.0.0.0 200.1.1.1 preference 70
<span class="o">[</span>GW]undo ip route-static 0.0.0.0 0.0.0.0 100.1.1.1 track bfd-session 
<span class="o">[</span>GW]undo bfd
Warning: All BFD capability on the device will be deleted. Continue? <span class="o">[</span>Y/N]y
<span class="o">[</span>GW]display current-configuration  <span class="c">##查看配置bfd是否消失</span>
<span class="o">[</span>GW]undo ip route-static 0.0.0.0 0.0.0.0 100.1.1.1
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>Telecom]sysname R1
<span class="o">[</span>Unicom]sys R2
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>R1]ospf 100
<span class="o">[</span>R1-ospf-100]area 0
<span class="o">[</span>R1-ospf-100-area-0.0.0.0]
<span class="o">[</span>R1-ospf-100-area-0.0.0.0]network 0.0.0.0 0.0.0.0 
<span class="o">[</span>R1-ospf-100-area-0.0.0.0]q
<span class="o">[</span>R1-ospf-100]

<span class="o">[</span>R2]ospf 100
<span class="o">[</span>R2-ospf-100]area 0
<span class="o">[</span>R2-ospf-100-area-0.0.0.0]
<span class="o">[</span>R2-ospf-100-area-0.0.0.0]network 0.0.0.0 0.0.0.0 
<span class="o">[</span>R2-ospf-100-area-0.0.0.0]q
<span class="o">[</span>R2-ospf-100]
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>GW]ospf 100
<span class="o">[</span>GW-ospf-100]area 0
<span class="o">[</span>GW-ospf-100-area-0.0.0.0]network 0.0.0.0 0.0.0.0
<span class="o">[</span>GW-ospf-100-area-0.0.0.0]q
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>GW-ospf-100]display ospf peer brief

	 OSPF Process 100 with Router ID 100.1.1.2
		  Peer Statistic Information
 <span class="nt">----------------------------------------------------------------------------</span>
 Area Id          Interface                        Neighbor <span class="nb">id      </span>State    
 0.0.0.0          Ethernet0/0/0                    100.1.1.1        Full        
 0.0.0.0          Ethernet0/0/1                    200.1.1.1        Full        
 <span class="nt">----------------------------------------------------------------------------</span>
<span class="o">[</span>GW-ospf-100]display ip routing-table
Route Flags: R - relay, D - download to fib
<span class="nt">------------------------------------------------------------------------------</span>
Routing Tables: Public
         Destinations : 7        Routes : 8        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      100.1.1.0/24  Direct  0    0           D   100.1.1.2       Ethernet0/0/0
      100.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/0
      123.1.1.1/32  OSPF    10   1           D   200.1.1.1       Ethernet0/0/1
                    OSPF    10   1           D   100.1.1.1       Ethernet0/0/0
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
      200.1.1.0/24  Direct  0    0           D   200.1.1.2       Ethernet0/0/1
      200.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/1

</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>R1-Ethernet0/0/0]shutdown  <span class="c">##在R1的e0/0/0接口断掉</span>
<span class="c">##等待40s，邻居才断掉</span>
<span class="o">[</span>GW-ospf-100]display ospf peer brief

	 OSPF Process 100 with Router ID 100.1.1.2
		  Peer Statistic Information
 <span class="nt">----------------------------------------------------------------------------</span>
 Area Id          Interface                        Neighbor <span class="nb">id      </span>State    
 0.0.0.0          Ethernet0/0/1                    200.1.1.1        Full        
 <span class="nt">----------------------------------------------------------------------------</span>
<span class="o">[</span>GW-ospf-100]display ip routing-table
Route Flags: R - relay, D - download to fib
<span class="nt">------------------------------------------------------------------------------</span>
Routing Tables: Public
         Destinations : 7        Routes : 7        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      100.1.1.0/24  Direct  0    0           D   100.1.1.2       Ethernet0/0/0
      100.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/0
      123.1.1.1/32  OSPF    10   1           D   200.1.1.1       Ethernet0/0/1
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
      200.1.1.0/24  Direct  0    0           D   200.1.1.2       Ethernet0/0/1
      200.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/1
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>GW]bfd
<span class="o">[</span>GW-bfd]q
<span class="o">[</span>GW]ospf 100 
<span class="o">[</span>GW-ospf-100]bfd all	
<span class="o">[</span>GW-ospf-100]bfd all-interfaces en	
<span class="o">[</span>GW-ospf-100]bfd all-interfaces <span class="nb">enable</span> 
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>R1]bfd
<span class="o">[</span>R1-bfd]q
<span class="o">[</span>R1]ospf 100
<span class="o">[</span>R1-ospf-100]bfd all	
<span class="o">[</span>R1-ospf-100]bfd all-interfaces en	
<span class="o">[</span>R1-ospf-100]bfd all-interfaces <span class="nb">enable</span> 
</code></pre></div></div>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/7bf8b4f8-f501-411c-a0a9-3bb01a7a2703" alt="image" /></p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/eeb0a47e-bd09-4fec-851a-63965cc7ab30" alt="image" /></p>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[浮动路由]]></summary></entry><entry><title type="html">VLAN-单臂路由-NAT-DHCP实验</title><link href="https://blog.luoqing.org/blog/2023/09/06/VLAN-%E5%8D%95%E8%87%82%E8%B7%AF%E7%94%B1-NAT-DHCP%E5%AE%9E%E9%AA%8C.html" rel="alternate" type="text/html" title="VLAN-单臂路由-NAT-DHCP实验" /><published>2023-09-06T00:00:00+08:00</published><updated>2023-09-06T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/09/06/VLAN-%E5%8D%95%E8%87%82%E8%B7%AF%E7%94%B1-NAT-DHCP%E5%AE%9E%E9%AA%8C</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/09/06/VLAN-%E5%8D%95%E8%87%82%E8%B7%AF%E7%94%B1-NAT-DHCP%E5%AE%9E%E9%AA%8C.html"><![CDATA[<p>拓扑</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/957c9041-609f-4db1-8768-9946fb07b040" alt="image" /></p>

<p>PC1</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/fc106d77-ed17-4366-bddd-654c3fc6184b" alt="image" /></p>

<p>PC2</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/05028cbd-7656-4817-9605-2bdf0090ad6e" alt="image" /></p>

<p>GW</p>

<p>打开接口</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router#en
Router#show ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES <span class="nb">unset  </span>administratively down down    
FastEthernet1/0            unassigned      YES <span class="nb">unset  </span>administratively down down    
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no sh</span>
<span class="k">*</span>Mar  1 00:30:48.223: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
<span class="k">*</span>Mar  1 00:30:49.223: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#exit</span>
Router#
<span class="k">*</span>Mar  1 00:30:53.767: %SYS-5-CONFIG_I: Configured from console by console
Router#show ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES <span class="nb">unset  </span>up                    up      
FastEthernet1/0            unassigned      YES <span class="nb">unset  </span>administratively down down    
Router#
</code></pre></div></div>
<p>SW</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router&gt;en
Router#vlan data
Router#vlan database 
Router<span class="o">(</span>vlan<span class="o">)</span><span class="c">#vlan 10</span>
VLAN 10 added:
    Name: VLAN0010
Router<span class="o">(</span>vlan<span class="o">)</span><span class="c">#vlan 20</span>
VLAN 20 added:
    Name: VLAN0020
Router<span class="o">(</span>vlan<span class="o">)</span><span class="c">#exit</span>
APPLY completed.
Exiting....
Router#show vlan-sw
Router#show vlan-switch bri
Router#show vlan-switch brief 

VLAN Name                             Status    Ports
<span class="nt">----</span> <span class="nt">--------------------------------</span> <span class="nt">---------</span> <span class="nt">-------------------------------</span>
1    default                          active    Fa0/0, Fa0/1, Fa0/2, Fa0/3
                                                Fa0/4, Fa0/5, Fa0/6, Fa0/7
                                                Fa0/8, Fa0/9, Fa0/10, Fa0/11
                                                Fa0/12, Fa0/13, Fa0/14, Fa0/15
                                                Fa1/0, Fa1/1, Fa1/2, Fa1/3
                                                Fa1/4, Fa1/5, Fa1/6, Fa1/7
                                                Fa1/8, Fa1/9, Fa1/10, Fa1/11
                                                Fa1/12, Fa1/13, Fa1/14, Fa1/15
10   VLAN0010                         active    
20   VLAN0020                         active    
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active    
Router#
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router#conf t  
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/1</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport mode acc</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport mode access </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport acc</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport access vlan 10</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/2</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport mode access   </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport access vlan 20</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#exit</span>
Router#sho
<span class="k">*</span>Mar  1 00:38:31.515: %SYS-5-CONFIG_I: Configured from console by conso   
% Type <span class="s2">"show ?"</span> <span class="k">for </span>a list of subcommands
Router#
Router#show vlan-sw
Router#show vlan-switch bri
Router#show vlan-switch brief 

VLAN Name                             Status    Ports
<span class="nt">----</span> <span class="nt">--------------------------------</span> <span class="nt">---------</span> <span class="nt">-------------------------------</span>
1    default                          active    Fa0/0, Fa0/3, Fa0/4, Fa0/5
                                                Fa0/6, Fa0/7, Fa0/8, Fa0/9
                                                Fa0/10, Fa0/11, Fa0/12, Fa0/13
                                                Fa0/14, Fa0/15, Fa1/0, Fa1/1
                                                Fa1/2, Fa1/3, Fa1/4, Fa1/5
                                                Fa1/6, Fa1/7, Fa1/8, Fa1/9
                                                Fa1/10, Fa1/11, Fa1/12, Fa1/13
                                                Fa1/14, Fa1/15
10   VLAN0010                         active    Fa0/1
20   VLAN0020                         active    Fa0/2
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active    

</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switch</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport tr</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport trunk en</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport trunk encapsulation do</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport trunk encapsulation dot1q </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switc</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport mode tr</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#switchport mode trunk </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#</span>
<span class="k">*</span>Mar  1 00:44:01.579: %DTP-5-TRUNKPORTON: Port Fa0/0 has become dot1q trunk
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#end</span>
Router#show
<span class="k">*</span>Mar  1 00:44:12.323: %SYS-5-CONFIG_I: Configured from console by console 
% Type <span class="s2">"show ?"</span> <span class="k">for </span>a list of subcommands
Router#show int <span class="nb">tr      
</span>Router#show int trunk 

Port      Mode         Encapsulation  Status        Native vlan
Fa0/0     on           802.1q         trunking      1

Port      Vlans allowed on trunk
Fa0/0     1-1005

Port      Vlans allowed and active <span class="k">in </span>management domain
Fa0/0     1,10,20

Port      Vlans <span class="k">in </span>spanning tree forwarding state and not pruned
Fa0/0     1,10,20
Router#show vlan-sw
Router#show vlan-switch br
Router#show vlan-switch brief 

VLAN Name                             Status    Ports
<span class="nt">----</span> <span class="nt">--------------------------------</span> <span class="nt">---------</span> <span class="nt">-------------------------------</span>
1    default                          active    Fa0/3, Fa0/4, Fa0/5, Fa0/6
                                                Fa0/7, Fa0/8, Fa0/9, Fa0/10
                                                Fa0/11, Fa0/12, Fa0/13, Fa0/14
                                                Fa0/15, Fa1/0, Fa1/1, Fa1/2
                                                Fa1/3, Fa1/4, Fa1/5, Fa1/6
                                                Fa1/7, Fa1/8, Fa1/9, Fa1/10
                                                Fa1/11, Fa1/12, Fa1/13, Fa1/14
                                                Fa1/15
10   VLAN0010                         active    Fa0/1
20   VLAN0020                         active    Fa0/2
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active    

</code></pre></div></div>
<p>GW</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no sh</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.?</span>
  &lt;0-4294967295&gt;  FastEthernet interface number

Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.10  </span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.20</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#end</span>
Router#sj
<span class="k">*</span>Mar  1 00:58:33.155: %SYS-5-CONFIG_I: Configured from console by consol 
% Type <span class="s2">"show ?"</span> <span class="k">for </span>a list of subcommands
Router#show ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES <span class="nb">unset  </span>up                    up      
FastEthernet0/0.10         unassigned      YES <span class="nb">unset  </span>up                    up      
FastEthernet0/0.20         unassigned      YES <span class="nb">unset  </span>up                    up      
FastEthernet1/0            unassigned      YES <span class="nb">unset  </span>administratively down down    
Router#en 
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.10</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#en</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#encapsulation do</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#encapsulation dot1Q 10    ##服务vlan10</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#ip add 192.168.1.1 255.255.255.0   ##设置网关IP</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.20                     </span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#encapsulation dot1Q 20          </span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#ip add 192.168.2.1 255.255.255.0</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#exit</span>

</code></pre></div></div>

<p>PC1的测试</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/b22b508d-34be-4700-a9ee-7b8ce7c2e422" alt="image" /></p>

<p>交换机可以转发广播包，路由器不可以转发广播包。
实验结果，PC1、PC2通过路由器互通，且VLAN隔离</p>

<p>GW</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router&gt;
Router&gt;
Router&gt;
Router&gt;en 
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f1/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip add 100.1.1.2 255.255.255.0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no sh </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#</span>
<span class="k">*</span>Mar  1 01:14:37.587: %LINK-3-UPDOWN: Interface FastEthernet1/0, changed state to up
<span class="k">*</span>Mar  1 01:14:38.587: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up 
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#exit</span>
Router#show 
<span class="k">*</span>Mar  1 01:14:56.795: %SYS-5-CONFIG_I: Configured from console by console
% Type <span class="s2">"show ?"</span> <span class="k">for </span>a list of subcommands
Router#show ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES <span class="nb">unset  </span>up                    up      
FastEthernet0/0.10         192.168.1.1     YES manual up                    up      
FastEthernet0/0.20         192.168.2.1     YES manual up                    up      
FastEthernet1/0            100.1.1.2       YES manual up                    up      
Router#
</code></pre></div></div>
<p>ISP</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router#show ip int br
<span class="k">*</span>Mar  1 01:17:43.563: %SYS-5-CONFIG_I: Configured from console by console
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES <span class="nb">unset  </span>administratively down down    
Router#conf t        
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip add 100.1.1.1 255.255.255.0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#int </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#interface loo</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#interface loopback 0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#</span>
<span class="k">*</span>Mar  1 01:18:41.687: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip add 8.8.8.8 255.255.255.0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#end</span>
Router#
<span class="k">*</span>Mar  1 01:19:23.227: %SYS-5-CONFIG_I: Configured from console by console    
Router#show ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            100.1.1.1       YES manual administratively down down    
Loopback0                  8.8.8.8         YES manual up                    up      
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no sh</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#end</span>
Router#
</code></pre></div></div>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>1. ACL permit 抓取数据
2. 转换数据--100.1.1.2  连接运营商的外网地址  --f1/0
3. 定义内部接口和外部接口

通过一个公网地址的多个端口号来区分不同的内部业务数据---overload端口复用

GW
```bash
Router&gt;en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#
Router(config)#ip route 0.0.0.0 0.0.0.0 100.1.1.1
Router(config)#access
Router(config)#access-list 1 p
Router(config)#access-list 1 permit 192.168.1.0 0.0.0.255
Router(config)#access-list 1 permit 192.168.2.0 0.0.0.255
Router(config)#ip nat in
Router(config)#ip nat inside sou
Router(config)#ip nat inside source list 1 int
Router(config)#ip nat inside source list 1 interface f1/0 over
Router(config)#ip nat inside source list 1 interface f1/0 overload 
Router(config)#
*Mar  1 01:47:33.431: %LINEPROTO-5-UPDOWN: Line protocol on Interface NVI0, changed state to up
Router(config)#
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router&gt;en      
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip nat ins</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip nat inside </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#end  </span>
Router#show
<span class="k">*</span>Mar  1 01:58:51.155: %SYS-5-CONFIG_I: Configured from console by console 
% Type <span class="s2">"show ?"</span> <span class="k">for </span>a list of subcommands
Router#show ip inter br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES <span class="nb">unset  </span>up                    up      
FastEthernet0/0.10         192.168.1.1     YES manual up                    up      
FastEthernet0/0.20         192.168.2.1     YES manual up                    up      
FastEthernet1/0            100.1.1.2       YES manual up                    up      
NVI0                       unassigned      NO  <span class="nb">unset  </span>up                    up      
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f1/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip nat outside</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router&gt;en      
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip nat ins</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip nat inside </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#end  </span>
Router#show
<span class="k">*</span>Mar  1 01:58:51.155: %SYS-5-CONFIG_I: Configured from console by console 
% Type <span class="s2">"show ?"</span> <span class="k">for </span>a list of subcommands
Router#show ip inter br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES <span class="nb">unset  </span>up                    up      
FastEthernet0/0.10         192.168.1.1     YES manual up                    up      
FastEthernet0/0.20         192.168.2.1     YES manual up                    up      
FastEthernet1/0            100.1.1.2       YES manual up                    up      
NVI0                       unassigned      NO  <span class="nb">unset  </span>up                    up      
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f1/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip nat outside</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no ip nat in</span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no ip nat inside </span>
Router<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.10</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#ip nat inside</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#exit</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.20  </span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#ip nat inside</span>
Router<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#exit  </span>
</code></pre></div></div>
<p>inside必须定义到有IP的接口上，子接口。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/71dc40bb-1c88-404a-bde1-9ba89dcc60d9" alt="image" /></p>

<p>当ISP新增环回接口模拟新的服务4.4.4.4，PC1和PC2依然能访问。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/74b0daad-082d-49bc-85dd-ff3c1060bee8" alt="image" /></p>

<p>假如需要添加公网地址，需要定义公网池</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Router<span class="o">(</span>config<span class="o">)</span><span class="c">#no ip nat inside source list 1 interface f1/0 overload </span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#ip nat pool CCNA</span>
% Incomplete command.

Router<span class="o">(</span>config<span class="o">)</span><span class="c">#ip nat pool CCNA ?</span>
  A.B.C.D        Start IP address
  netmask        Specify the network mask
  prefix-length  Specify the prefix length

Router<span class="o">(</span>config<span class="o">)</span><span class="c">#ip nat pool CCNA 100.1.1.2 100.1.1.3 net</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#ip nat pool CCNA 100.1.1.2 100.1.1.3 netmask 255.255.255.0</span>
Router<span class="o">(</span>config<span class="o">)</span><span class="c">#ip nat inside source list 1 pool CCNA overload </span>
</code></pre></div></div>
<p>当100.1.1.2端口用满之后，就会使用100.1.1.3</p>

<hr />

<p>静态nat</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#取消动态nat</span>
gw#conf t
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#interface f1/0</span>
gw<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no ip nat outside</span>
gw<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.10</span>
gw<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#no ip nat in  </span>
gw<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#exit        </span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.20 </span>
gw<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#no ip nat inside</span>
gw<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#end</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#no access-list 1</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#no ip nat pool CCNA</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#exit</span>
gw#show run | <span class="k">in </span>ip nat


<span class="c">#开启静态nat</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#interface f1/0</span>
gw<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip nat outside</span>
gw<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.10</span>
gw<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#ip nat inside  </span>
gw<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#exit        </span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0.20 </span>
gw<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#ip nat inside</span>
gw<span class="o">(</span>config-subif<span class="o">)</span><span class="c">#exit</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#ip nat inside source static tcp 192.168.1.10 23 100.1.1.2 1000   </span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#ip nat inside source static tcp 192.168.2.10 23 100.1.1.2 2000</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#exit</span>

<span class="c">##打开telnet</span>
gw<span class="o">(</span>config<span class="o">)</span><span class="c">#line vty 0 4</span>
gw<span class="o">(</span>config-line<span class="o">)</span><span class="c">#password cisco</span>
gw<span class="o">(</span>config-line<span class="o">)</span><span class="c">#login</span>
gw<span class="o">(</span>config-line<span class="o">)</span><span class="c">#exit</span>

pc1<span class="o">(</span>config<span class="o">)</span><span class="c">#line vty 0 4</span>
pc1<span class="o">(</span>config-line<span class="o">)</span><span class="c">#password cisco</span>
pc1<span class="o">(</span>config-line<span class="o">)</span><span class="c">#login</span>
pc1<span class="o">(</span>config-line<span class="o">)</span><span class="c">#end</span>

pc2<span class="o">(</span>config<span class="o">)</span><span class="c">#line vty 0 4</span>
pc2<span class="o">(</span>config-line<span class="o">)</span><span class="c">#password cisco</span>
pc2<span class="o">(</span>config-line<span class="o">)</span><span class="c">#login</span>
pc2<span class="o">(</span>config-line<span class="o">)</span><span class="c">#end</span>
</code></pre></div></div>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/19e4eabb-1553-44d2-9b47-fdf073ff4d04" alt="image" /></p>

<p>DHCP 动态IP配置</p>
<pre><code class="language-bash![请添加图片描述](https://img-blog.csdnimg.cn/71e8eecbfe044d1f9679a1f68e2c4222.png)">
gw#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
gw(config)#
gw(config)#
gw(config)#
gw(config)#ip dhcp pool ?   
  WORD  Pool name

gw(config)#ip dhcp pool DHCP
gw(dhcp-config)#
gw(dhcp-config)#netwo
gw(dhcp-config)#network 192.168.1.0 255.255.255.0 
gw(dhcp-config)#defa
gw(dhcp-config)#default-router 192.168.1.1 
gw(dhcp-config)#dns-
gw(dhcp-config)#dns-server 8.8.8.8
gw(dhcp-config)#
gw(dhcp-config)#end 
gw#
*Mar  1 06:44:53.478: %SYS-5-CONFIG_I: Configured from console by console     
gw#show run | sec dhcp
no ip dhcp use vrf connected
ip dhcp pool DHCP
   network 192.168.1.0 255.255.255.0
   default-router 192.168.1.1 
   dns-server 8.8.8.8 


gw#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
gw(config)#ip dhcp poo
gw(config)#ip dhcp pool DHCP-2
gw(dhcp-config)#net
gw(dhcp-config)#netw
gw(dhcp-config)#network 192.168.2.0 /24
gw(dhcp-config)#defa
gw(dhcp-config)#default-router 192.168.2.1
gw(dhcp-config)#dns-se
gw(dhcp-config)#dns-server 4.4.4.4
gw(dhcp-config)#end
gw#
*Mar  1 06:47:48.830: %SYS-5-CONFIG_I: Configured from console by console
gw#

</code></pre>

<p>PC1</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pc1&gt;en 
pc1#
pc1#
pc1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
pc1<span class="o">(</span>config<span class="o">)</span><span class="c">#</span>
pc1<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no ip add</span>
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip add dh</span>
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip add dhcp ?</span>
  client-id  Specify client-id to use
  <span class="nb">hostname   </span>Specify value <span class="k">for </span><span class="nb">hostname </span>option
  &lt;cr&gt;

pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip addr     </span>
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#ip address dhcp</span>
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#exit</span>

pc1#show ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.1.2     YES DHCP   up                    up      
NVI0                       unassigned      NO  <span class="nb">unset  </span>up                    up      

gw<span class="o">(</span>config<span class="o">)</span><span class="c">#ip dhcp excluded-address 192.168.1.1 192.168.1.100 ##设置不允许下发192.168.1.1到192.168.1.100的地址</span>
pc1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
pc1<span class="o">(</span>config<span class="o">)</span><span class="c">#int f0/0</span>
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#sh</span>
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#no sh</span>
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#</span>
<span class="k">*</span>Mar  1 07:05:40.634: %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
<span class="k">*</span>Mar  1 07:05:41.634: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#</span>
<span class="k">*</span>Mar  1 07:05:44.222: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
<span class="k">*</span>Mar  1 07:05:45.222: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
pc1<span class="o">(</span>config-if<span class="o">)</span><span class="c">#end</span>
pc1#
<span class="k">*</span>Mar  1 07:05:48.778: %DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/0 assigned DHCP address 192.168.1.101, mask 255.255.255.0, <span class="nb">hostname </span>pc1

<span class="k">*</span>Mar  1 07:05:50.210: %SYS-5-CONFIG_I: Configured from console by console
pc1#show ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.1.101   YES DHCP   up                    up      
NVI0                       unassigned      NO  <span class="nb">unset  </span>up                    up      
pc1#  
</code></pre></div></div>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/8e4a8fb3-3477-4144-bbf0-b530f632e642" alt="image" /></p>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[拓扑]]></summary></entry><entry><title type="html">CCNP(三)－路由协议-OSPF</title><link href="https://blog.luoqing.org/blog/2023/08/07/CCNP(%E4%B8%89)-%E8%B7%AF%E7%94%B1%E5%8D%8F%E8%AE%AE-OSPF.html" rel="alternate" type="text/html" title="CCNP(三)－路由协议-OSPF" /><published>2023-08-07T00:00:00+08:00</published><updated>2023-08-07T00:00:00+08:00</updated><id>https://blog.luoqing.org/blog/2023/08/07/CCNP(%E4%B8%89)%EF%BC%8D%E8%B7%AF%E7%94%B1%E5%8D%8F%E8%AE%AE-OSPF</id><content type="html" xml:base="https://blog.luoqing.org/blog/2023/08/07/CCNP(%E4%B8%89)-%E8%B7%AF%E7%94%B1%E5%8D%8F%E8%AE%AE-OSPF.html"><![CDATA[<h2 id="简介">简介</h2>
<p><strong>开放式最短路径优先</strong>（英语：Open Shortest Path First，缩写为 <strong>OSPF</strong>）：<strong>OSPF</strong>协议同时使用单播（Unicast）和组播（Multicast）来发送Hello包和链路状态更新（Link State Updates），使用的组播地址为224.0.0.5和224.0.0.6。与RIP和BGP不同的是，OSPF协议封装不使用TCP或者UDP协议而是直接承载在IP协议之上，IP协议号为89。</p>

<p>在OSPF出现前，RIP是网络上使用最广泛的IGP协议。但随着网络的快速成长和扩展，RIP的某些限制可能会导致其在大型网络中不再适用，OSPF则能够解决RIP所面临的诸多问题。</p>

<p><strong>RIP</strong></p>
<ul>
  <li>基于距离矢量算法，以跳数作为度量方式，忽略带宽的影响。</li>
  <li>RIP的跳数限制为15个，限制了RIP的网络规模。</li>
  <li>按照路由通告进行路由更新和选择，路由器不了解整个网络拓扑，容易产生路由环路。</li>
  <li>收敛速度慢，路由更新会经历一段抑制和垃圾收集期，容易导致路由器之间的路由不一致。</li>
  <li>不能处理可变长子网掩码（VLSM）。</li>
</ul>

<p><strong>OSPF</strong></p>
<ul>
  <li>基于链路状态，以链路开销作为度量方式，并把带宽作为参考值，度量方式更科学。</li>
  <li>没有跳数限制，适用的网络规模更大。</li>
  <li>每台路由器都能够掌握全网拓扑，通过最短路径优先算法SPF（Shortest Path First）计算路由，不会产生路由环路。</li>
  <li>收敛速度快，因为路由更新是及时的，并且能够快速传递到整个网络。</li>
  <li>能够处理VLSM，灵活进行IP地址分配。</li>
</ul>

<p>此外，OSPF还有以下优点：</p>
<ul>
  <li>OSPF可以采用组播形式收发报文，这样可以减少对未运行OSPF的路由器的影响。</li>
  <li>OSPF支持无类型域间选路（CIDR）。</li>
  <li>OSPF支持对等价路由进行负载分担。</li>
  <li>OSPF支持报文验证。
    <h2 id="ospf运行机制">OSPF运行机制</h2>
  </li>
</ul>

<p><strong>OSPF的运行机制包括以下5个步骤</strong></p>

<ul>
  <li>交互Hello报文</li>
  <li>泛洪LSA</li>
  <li>组建LSDB</li>
  <li>SPF算法计算</li>
  <li>维护和更新路由表</li>
</ul>

<p><strong>交互Hello报文</strong></p>

<p>通过交互Hello报文形成邻居关系，如图3所示，路由器运行OSPF协议后，会从所有启动OSPF协议的接口上发送Hello报文。如果两台路由器共享一条公共数据链路，并且能够成功协商各自Hello报文中所指定的某些参数，就能形成邻居关系。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/33ac8221-a590-456b-b472-2689defd9946" alt="image" /></p>

<p><strong>泛洪LSA</strong></p>

<p>通过泛洪LSA通告链路状态信息，形成邻居关系的路由器之间进一步交互LSA形成邻接关系，如图4所示。每台路由器根据自己周围的网络拓扑结构生成LSA，LSA描述了路由器所有的链路、接口、邻居及链路状态等信息，路由器通过交互这些链路信息来了解整个网络的拓扑信息。由于链路的多样性，OSPF协议定义了多种LSA（链路状态通告）类型，LSA描述了所有的链路，接口和邻居等链路状态信息，OSPF路由协议对所有路由信息的描述，都是封装在链路状态通告LSA中发送出去的。详见OSPF LSA类型。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/a5af8dea-d63e-4a2e-9261-3a4c7d19dc22" alt="image" /></p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/27b058fc-93b6-4a7b-a96a-8e07ff0cd0be" alt="image" /></p>

<p><strong>组建LSDB</strong></p>

<p>通过组建LSDB形成带权有向图，通过LSA的泛洪，路由器会把收到的LSA汇总记录存放在LSDB数据库中。最终，所有路由器都会形成同样的LSDB，如图5所示。LSA是对路由器周围网络拓扑结构的描述，而LSDB则是对整个自治系统的网络拓扑结构的描述，LSDB是LSA的汇总。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/4481bbfa-6799-4072-a634-1d3ef1bd049a" alt="image" /></p>

<p><strong>SPF算法计算</strong></p>

<p>通过SPF算法计算并形成路由，如图6所示，当LSDB同步完成之后，每一台路由器都将以其自身为根，使用SPF算法来计算一个无环路的拓扑图来描述它所知道的到达每一个目的地的最短路径（最小的路径代价）。这个拓扑图就是最短路径树，有了这棵树，路由器就能知道到达自治系统中各个节点的最优路径。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/506ddaec-2abe-450f-8d46-38bc775b1016" alt="image" /></p>

<p><strong>维护和更新路由表</strong></p>

<p>根据SPF算法得出最短路径树后，每台路由器将计算得出的最短路径加载到OSPF路由表形成指导数据转发的路由表项，并且实时更新，如图7所示。同时，邻居之间交互Hello报文进行保活，维持邻居关系或邻接关系，并且周期性地重传LSA。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/437eebc6-618d-417b-89f0-a0de63200829" alt="image" /></p>

<h2 id="ospf区域间路由">OSPF区域间路由</h2>
<p>随着网络规模不断扩大，结构也日趋复杂，路由器完成路由计算所消耗的内存、CPU资源也越来越多，网络发生故障的可能性也随之增加，如果区域内某处发生故障，整个区域内的路由器都要重新计算路由，这将大大增加路由器的负担，降低网络运行的稳定性。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/fabb1e44-f472-4620-bb8f-4c9f1725f01c" alt="image" /></p>

<p><strong>优点</strong>：OSPF采用划分区域的方式，将一个大网络划分为多个相互连接的小网络。每个区域内的设备只需同步所在区域内的链路状态数据库，一定程度上降低内存及CPU的消耗。</p>

<ul>
  <li>1.缩小数据库规模（区域间只传递路由信息）</li>
  <li>2.方便路由控制（汇总、过滤）</li>
  <li>3.扩展性强</li>
</ul>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/a974e960-d57a-4754-8471-499864331793" alt="image" /></p>

<h2 id="区域划分的基本概念">区域划分的基本概念</h2>
<p><strong>区域类型</strong>：OSPF区域分为：骨干区域(area 0)，非骨干区域(非area 0)，必须存在骨干区域，可以没有非骨干区域，骨干区域必须拥有所有区域的明细路由，非骨干区域必须围绕着骨干区域建立，以接口进行划分区域，一个接口只能属于一个区域，一台设备可以属于多个区域，非骨干区域之间互访需要经过骨干区域。</p>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/e35389cf-5cfc-437c-8ce1-aed30a43adf2" alt="image" /></p>

<p><strong>OSPF路由器的角色</strong></p>

<p>OSPF路由器的类型决定了什么样的数据流能够进入和离开区域。下面是4种路由器类型如下图。</p>
<ul>
  <li>内部路由器：所有接口都位于同一个区域中的路由器，同一个区域中所有内部路由器的LSDB都相同。</li>
  <li>骨干路由器：位于骨干区域0边缘的路由器，至少有一个接口与区域0相连。骨干路由器在维护OSPF路由信息时采用的步骤和算法与内部路由器相同。</li>
  <li>区域边界路由器（ABR）：连接多个区域的路由器，为其连接的每个区域维护一个LSDB，并路由器前往/来自其他区域的数据流。ABR将区域0连接到非骨干区域，因此是区域的出口，这意味着前往其他区域的路由信息必须经过当前区域的ABR。ABR将这些路由选择信息通告给骨干，骨干路由器再将其转发给其他的ABR。只能在ABR对其连接的区域的地址进行汇总（对其连接的区域的LSDB种的路由选择信息进行汇总）。ABR分离LSA泛洪区，还可能提供默认路由。一个区域肯能有一台或多台ABR。
理想的设计是只让每个ABR连接两个区域：骨干区域和另一个区域。正如前面指出的，建议ABR最多不要连接3个以上的区域。</li>
  <li>自治系统边界路由器（ASBR）：至少有一个接口与其他域（如另一个OSPF自治区域系统或使用其他网络协议的域）相连。OSPF自治系统由所有OSPF区域及其中的路由器组成。ASBR可将外部路由重分发到OSPF域中，反之亦然。</li>
</ul>

<h2 id="ospf工作过程及原理">OSPF工作过程及原理</h2>
<p>OSPF（Open Shortest Path First）是一种用于内部网关协议（IGP），常用于企业和互联网服务提供商中。它的工作过程和原理如下：</p>

<ol>
  <li>
    <p>邻居发现：OSPF路由器通过发送和接收Hello报文来相互发现并建立邻居关系。</p>
  </li>
  <li>
    <p>路由器ID分配：每个OSPF路由器都有一个唯一的路由器ID，可以通过以下方式之一来确定：手动配置、最高循环IP地址、或者最高回环接口IP地址。</p>
  </li>
  <li>
    <p>构建链路状态数据库（LSDB）：邻居关系建立后，路由器会交换链路状态更新（Link State Update）报文，用于构建链路状态数据库，其中保存了整个网络的拓扑信息。</p>
  </li>
  <li>
    <p>SPF计算：一旦链路状态数据库构建完成，每个路由器都会执行SPF（Shortest Path First）算法来计算到达网络中所有目的地的最短路径。</p>
  </li>
  <li>
    <p>路由更新：SPF计算完成后，每个路由器将更新它的路由表，包含最新的最短路径信息。</p>
  </li>
  <li>
    <p>路由信息交换：OSPF通过发送链路状态广告（LSA）报文来交换路由信息，确保网络中的所有路由器都具备相同的链路状态数据库和路由表。</p>
  </li>
  <li>
    <p>链路状态更新和周期性检查：OSPF路由器之间周期性地交换Hello报文来保持邻居关系，并根据网络的变化发送链路状态更新，以保持链路状态数据库的一致性。</p>
  </li>
</ol>

<p>总结来说，OSPF通过建立邻居关系、构建链路状态数据库、执行SPF计算和交换路由信息来找到网络中最短路径，并确保路由表的正确性和一致性。这使得OSPF成为一个高效可靠的内部网关协议，适用于复杂的企业网络和大规模互联网部署。</p>

<h2 id="neighbor和adjacency">Neighbor和Adjacency</h2>

<p>Open Shortest Path First (OSPF) 是一种内部网关协议（IGP），它使用链路状态路由协议 (LSRP) 算法确定网络中的最短路径。OSPF 使用邻居关系和邻接关系来构建网络拓扑图，以在路由器之间交换路由信息。OSPF（开放式最短路径优先协议）的邻居是指在同一个区域内的相互连接的路由器。邻居之间需要建立OSPF邻接关系才能进行路由信息交换。OSPF邻接关系指的是两个邻居之间建立了OSPF协议的连接，可以互相交换路由信息。</p>

<p>当两个OSPF邻居之间建立邻接关系后，它们就会交换自己的路由信息，并根据自己的SPF计算进行更新。这样，在整个区域内的每个路由器都可以了解到整个网络的路由信息，从而实现最优路径的选择和数据转发。</p>

<p>邻居（Neighbor）是指与一个路由器通过直接相连的网络连接起来的另一个路由器。当两个路由器在同一广播域内时，它们就会成为邻居，并开始交换路由信息。路由器通过发送 Hello 消息来发现它们的邻居，并确定它们的状态。</p>

<p>邻接（Adjacency）是指两个邻居之间建立的关系，这种关系建立了连接并开始交换数据。OSPF 邻接建立需要满足以下条件：在同一区域（OSPF Area）中；使用相同的 OSPF 网络类型；使用相同的 OSPF 路由器 ID；使用相同的区域 ID；使用相同的 Hello 和 Dead Interval 值。</p>

<p>一旦邻居建立，路由器之间就可以交换路由信息，并通过最短路径算法计算出网络中的最短路径。邻接关系通常比邻居关系更稳定，因为它们需要满足更多的条件才能建立。</p>

<h2 id="ospf中的spf算法">OSPF中的SPF算法</h2>

<p>OSPF中的SPF算法（Shortest Path First）是用于计算最短路径的核心算法。它基于网络的拓扑结构和链路状态信息，通过逐步计算路由器到每个目的地的最短路径，最终形成最短路径树。下面是SPF算法的几个主要步骤：</p>

<ul>
  <li>
    <p>收集链路状态信息：每个路由器收集与它直接相邻的路由器的链路状态信息，包括链路的开销（即距离、带宽等）和状态（连接状态、可达性等）。</p>
  </li>
  <li>
    <p>构建拓扑图：每个路由器将收集到的链路状态信息转换为拓扑图，其中每个节点表示一个路由器，每条边表示两个相邻路由器之间的连接。</p>
  </li>
  <li>
    <p>计算最短路径：路由器使用Dijkstra或SPF算法计算到达每个目的地的最短路径。计算过程中，路由器记录每个目的地的下一跳路由器，以便以后转发数据包时使用。</p>
  </li>
  <li>
    <p>形成最短路径树：每个路由器将计算出的最短路径转换为最短路径树，其中根节点表示自身，子节点表示直接相邻的路由器，每个叶子节点表示一个目的地。</p>
  </li>
  <li>
    <p>更新路由表：路由器根据最短路径树更新自己的路由表，以便以后转发数据包时使用。</p>
  </li>
</ul>

<p>通过SPF算法，OSPF可以快速计算出整个网络中的最短路径，并自动调整路由，保证数据的可靠传输和高效路由选择。</p>
<h2 id="lsa操作过程">LSA操作过程</h2>

<p>链路状态数据结构（LSA）是广域网中路由协议使用的重要数据结构。在OSPF和IS-IS路由协议中，LSA被用来描述一个特定路由器所知道的本地网络拓扑结构信息。以下是LSA操作的一些常见步骤：</p>

<ul>
  <li>
    <p>探测本地网络拓扑：每台路由器定期探测本地网络拓扑，并保存自己的LSA数据库。</p>
  </li>
  <li>
    <p>将LSA广播到邻居：每当一个路由器探测到拓扑结构的变化，它会将LSA广播给与之相邻的路由器。相邻的路由器会保存这些LSA，并将它们转发给其他路由器。</p>
  </li>
  <li>
    <p>计算最佳路径：每台路由器使用所知道的LSA来计算到达目标地址的最佳路径。为了减少网络拥塞，路由器可能会使用不同的算法来计算路径。</p>
  </li>
  <li>
    <p>更新LSA数据库：如果某个LSA数据库中的信息过时或者网络拓扑发生变化，路由器会将更新的LSA广播给邻居，并更新自己的LSA数据库。</p>
  </li>
  <li>
    <p>路由故障后的恢复：如果某个路由器失效，它周围的路由器会检测到这个故障，并将与该路由器相关的LSA从数据库中删除。随后，它们会重新计算到达目标地址的最佳路径。</p>
  </li>
</ul>

<p>通过LSA操作，路由器可以动态地更新本地网络拓扑结构信息，并计算到达目标地址的最佳路径。这有助于提高网络的可靠性和性能。</p>

<h2 id="ospfopen-shortest-path-first有以下几种类型的数据报文">OSPF（Open Shortest Path First）有以下几种类型的数据报文</h2>

<p><img src="https://github.com/yutao517/yutao517.github.io/assets/62100249/21c16209-8152-4d2c-82c7-c99156acc467" alt="image" /></p>

<p>OSPF报文主要包括以下内容：</p>

<ol>
  <li>
    <p>Hello报文：组播收发，用于邻居、邻接关系的发现、建立、周期保活、发布RouterID、Router Priority等参数信息。hello报文组播发送，hello time为10s或者30s，dead time是hello time 的4倍。</p>
  </li>
  <li>
    <p>Database Description（DD）报文：用于通过比较邻居路由器的LSA数据库，确定两个路由器之间的同步状态。</p>
  </li>
  <li>
    <p>Link State Request (LSR)报文：用于请求邻居路由器发送某些LSA的详细信息。</p>
  </li>
  <li>
    <p>Link State Update (LSU)报文：用于向邻居路由器发送LSA详细信息。</p>
  </li>
  <li>
    <p>Link State Acknowledgment (LSAck)报文：用于确认LSU报文的接收。</p>
  </li>
</ol>

<p>这些报文允许OSPF路由器中的每个节点共享网络拓扑信息，并计算出网络中最短的路径。</p>

<h2 id="数据包的包头字段">数据包的包头字段</h2>

<p>OSPF（Open Shortest Path First）包头字段包括以下内容：</p>

<ol>
  <li>版本（Version）：指示正在使用的OSPF版本。</li>
  <li>类型（Type）：指定OSPF数据包的类型，如Hello、Link State Update（LSU）、Link State Request（LSR）、Link State Acknowledgment（LSA）等。</li>
  <li>数据包长度（Packet Length）：表示OSPF数据包的总长度（以字节为单位）。</li>
  <li>路由器ID（Router ID）：源路由器的唯一标识符。</li>
  <li>区域ID（Area ID）：标识数据包所属的OSPF区域。</li>
  <li>校验和（Checksum）：用于在传输过程中确保数据完整性的校验和。</li>
  <li>AuType（Authentication Type）：用于身份验证的认证类型字段（可选）。</li>
  <li>身份验证（Authentication）：身份验证数据（可选）。</li>
  <li>OSPF数据包主体（OSPF Packet Body）：包含OSPF特定信息，如Hello间隔、失效间隔、LSA信息等。</li>
</ol>

<p>这些字段允许路由器进行通信，并构建网络的拓扑图，从而有效地计算路由数据包的最短路径。</p>

<p><strong>OSPF中Router ID的选举方式：</strong></p>

<ol>
  <li>
    <p>如果配置了loopback接口，优先选择loopback接口的IP地址作为Router ID。</p>
  </li>
  <li>
    <p>如果没有配置loopback接口，则选择所有接口中最高的IP地址作为Router ID。</p>
  </li>
  <li>
    <p>如果存在多个最高IP地址，则选择其中一个作为Router ID。</p>
  </li>
  <li>
    <p>如果以上方式都无法确定Router ID，则可以手动配置Router ID。</p>
  </li>
</ol>

<p>需要注意的是，Router ID在OSPF运行过程中是不会改变的，除非手动配置。因此，在设计网络拓扑时需要考虑Router ID的选择。</p>]]></content><author><name>王宇涛</name></author><category term="blog" /><category term="计算机网络" /><summary type="html"><![CDATA[简介 开放式最短路径优先（英语：Open Shortest Path First，缩写为 OSPF）：OSPF协议同时使用单播（Unicast）和组播（Multicast）来发送Hello包和链路状态更新（Link State Updates），使用的组播地址为224.0.0.5和224.0.0.6。与RIP和BGP不同的是，OSPF协议封装不使用TCP或者UDP协议而是直接承载在IP协议之上，IP协议号为89。]]></summary></entry></feed>