网络:路由

  1. 路由器

路由器工作在三层,每个接口都处于不用的网段中,即不同的广播域。但大多情况下,两台路由器直接相连的接口是同一个广播域,即一个网段。

路由器具有判断网络地址和选择路径的功能,能在多网络互联的环境中,建立灵活的连接,可用完全不同的数据分组和介质访问方法连接各种子网。

路由器属于网络层的设备,有隔离广播域的作用,它的每个端口都是一个独立的广播域,也是一个单独的冲突域。

  1. 路由

通俗地说,去往目标的路径。网络中是指导IP报文转发的路径信息。

  1. 路由表

路由的信息都放在路由表当中,就是帮助路由进行选路用的,是路由器或者三层交换机或者具备三层功能防火墙用于指导IP报文的转发。

查看路由的命令

<AR3>display ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 7        Routes : 7        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      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
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
    192.168.1.0/24  Direct  0    0           D   192.168.1.3     GigabitEthernet0/0/0
    192.168.1.3/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
  192.168.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

<AR3>

思科中用show

华为默认的路由表如下:

<AR3>display ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 4        Routes : 4        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      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
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

Destination/Mask:目标/掩码。

Proto:协议。

Pre:优先级。

直连路由默认优先级为0。

OSPF华为默认优先级为10和150,思科默认优先级为110。

静态路由华为默认为60,思科默认静态路由为10。

RIP默认优先级为100。

BGP默认优先级为255。

Cost:开销。

Flags:标识。下载到FIB。Route Flags:R-relay 中继。D-download to fib。

NextHop:下一跳。想要发送数据的下一站。

Interface:出接口。数据包发送的接口。一般出接口和下一跳在同一网段。

为什么华为中有默认4个路由表?

  1. 直连路由与非直连路由

直连路由:配置IP地址,端口UP状态,形成直连路由。例如AR1与AR3,AR3与AR1、AR4,AR4与AR3、AR5,AR5与AR4。即:当接口配置IP地址,且IP地址和协议都是UP时,满足直连路由产生条件。

优点:是所有路由当中优先级最高的。

是可以自动生成的。

缺点:不能去往非直连的其它网段。

非直连路由:需要静态路由或动态路由,将网段添加到路由表中。例如AR1与AR4。

直连路由优先级高于非直连路由。

为什么需要非直连路由?

由于直连路由存在不足,不能去往非自己直连的其它网段。

需要静态路由或动态路由,将网段添加到路由表中。

  1. 路由转发规则

被转发的路由必须存在。如果不存在,直接丢弃。

  1. 根据最长匹配原则进行,掩码越长,越优先转发。

  2. 当掩码一样,优先级的数值越小,越优先转发。

  3. 当掩码、优先级一样,开销越小,越优先转发。

  4. 当前述原则一致,负载分担。

  5. 静态路由

静态路由的应用场景

  1. 静态路由是指由管理员手动配置和维护的路由。

  2. 静态路由配置简单。无需像动态路由那样占用路由器的CPU资源来计算和分析路由更新。

  3. 静态路由一般适用于结构简单的网络。不过,即使是在复杂网络环境中,合理地配置一些静态路由也可以改进网络的性能。

静态路由的3种语法

在系统视图下执行:

  1. ip route-static 目标网段 目标网段掩码 出接口 #出接口即g0/0/0。

  2. ip route-static 目标网段 目标网段掩码 下一跳

  3. ip route-static 目标网段 目标网段掩码 出接口 下一跳 #推荐使用方式

为什么不用出接口?容易产生解析失败。

静态路由的不足:

静态路由:不能动态的根据现网拓扑的改变而改变。

  1. 下图为例:在AR10上如何访问路由3.3.3.3?

先配置AR10,配完后暂时无法ping通3.3.3.3:

[Huawei]sysname AR10
[AR10]interface LoopBack 0
[AR10-LoopBack0]ip add 1.1.1.1 32
[AR10-LoopBack0]dis ip inter bri
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 2
The number of interface that is DOWN in Protocol is 3

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              unassigned           up         down      
GigabitEthernet0/0/1              unassigned           down       down      
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         1.1.1.1/32           up         up(s)     
NULL0                             unassigned           up         up(s)     
[AR10-LoopBack0]quit
[AR10]interface g0/0/0
[AR10-GigabitEthernet0/0/0]ip add 192.168.1.1 24
Aug 10 2023 18:27:50-08:00 AR10 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. 
[AR10-GigabitEthernet0/0/0]quit
[AR10]ping 3.3.3.3
  PING 3.3.3.3: 56  data bytes, press CTRL_C to break
    Request time out
    Request time out
    Request time out
    Request time out
    Request time out

  --- 3.3.3.3 ping statistics ---
    5 packet(s) transmitted
    0 packet(s) received
    100.00% packet loss

[AR10]

配置AR11:

[AR11]inter g0/0/0
[AR11-GigabitEthernet0/0/0]ip add 192.168.1.2 24
[AR11-GigabitEthernet0/0/0]quit
[AR11]inte g0/0/1
[AR11-GigabitEthernet0/0/1]ip add 172.16.1.2 24
[AR11]inter LoopBack 0
[AR11-LoopBack0]ip add 2.2.2.2 32
[AR11-LoopBack0]quit
[AR11]dis ip inter brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              192.168.1.2/24       up         up        
GigabitEthernet0/0/1              172.16.1.2/24        up         up        
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         2.2.2.2/32           up         up(s)     
NULL0                             unassigned           up         up(s)     
<AR11>display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 11       Routes : 11       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        2.2.2.2/32  Direct  0    0           D   127.0.0.1       LoopBack0
      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
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
     172.16.1.0/24  Direct  0    0           D   172.16.1.2      GigabitEthernet0/0/1
     172.16.1.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
   172.16.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
    192.168.1.0/24  Direct  0    0           D   192.168.1.2     GigabitEthernet0/0/0
    192.168.1.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
  192.168.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

<AR11>

配置AR12:

[AR12]inter LoopBack 0
[AR12-LoopBack0]ip add 3.3.3.3 32
[AR12-LoopBack0]quit
[AR12]inter g0/0/0
[AR12-GigabitEthernet0/0/0]ip add 172.16.1.3 24
Aug 11 2023 15:34:54-08:00 AR12 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. 
[AR12-GigabitEthernet0/0/0]quit
[AR12]dis ip inter bri
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              172.16.1.3/24        up         up        
GigabitEthernet0/0/1              unassigned           down       down      
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         3.3.3.3/32           up         up(s)     
NULL0                             unassigned           up         up(s)     

配置完成后,AR10无法ping通3.3.3.3。

因为数据在传递过程中,经过AR11,AR10会将数据传递给AR11,但AR11上没有通往3.3.3.3的路由。因此AR11设备会丢弃该报文。因此需要在AR11上写入静态路由,使之增加到达3.3.3.3的路由

[AR11]ip route-static 3.3.3.3 32 g0/0/0 192.168.1.1

配置完成后,AR10依然无法ping通3.3.3.3。

因为数据在传递过程中,AR0发现到达3.3.3.3需要通过AR11设备的172.16.1.2接口。因此AR10会将数据传递给AR11设备。AR11设备到达3.3.3.3需经过AR12设备的172.16.1.3接口。因此AR12会接收数据,并传给直连路由3.3.3.3。

但是,如果想要ping通3.3.3.3,数据已然发送成功,也要接收成功。因此数据能够从AR12返回给AR10,才能ping通。

  1. 负载分担与负载均衡

负载分担:从AR6出来的流量 M + N = 100%,但M != N,例如M = 40%,N = 60%。

负载均衡:从AR6出来的流量 M + N = 100%,且M = N = 50%。

分逐流和逐包,默认逐流。

  1. 路由器控制平面和转发平面

路由器的两大典型功能:数据通道功能和控制功能。

数据通道功能包括转发决定、背板转发以及输出链路调度等,一般由特定的硬件来完成;控制功能一般用软件完成,包括与相邻路由器之间的信息交接、系统配置、系统管理等。

管理平面/控制平面(统称控制平面、分布平面)

控制平面用于控制和管理所有网络协议的运行,例如生成树协议、VLAN协议、ARP协议、各种路由协议和组播协议等的管理与控制。

控制平面通过网络协议提供给路由器/交换机对整个网络环境中的网络设备、连接链路和交互协议准确了解,并在网络状况发送改变时做出及时的调整以维护网络的正常运行。

控制平面提供转发前所需的各种网络信息。

控制平面并不占用过多的硬件资源,但在正常状态下依然是网络设备CPU资源的主要占用平面,控制平面主要靠CPU资源来处理信息。

display ip routing-table 查看IP路由表,属控制平面范畴(路由信息数据库,RIB)。

路由器不依赖控制平面进行数据转发。

数据转发平面/数据平面

对于数据处理过程中各种具体的处理转发过程,例如L2/L3/ACL/QOS/组播/安全防护等个功能的具体执行过程,都属于数据转发平面的任务范畴。

display fib 查看最终迭代的出接口,属数据平面范畴(转发信息数据库,FIB)。

路由器依赖数据平面进行数据转发。

  1. 路由表和FIB表

每个路由器都至少保存着一张路由表(routing-table)和一张FIB(Forwarding Information Base)表。

  1. Loopback是逻辑接口,区别于实际的物理接口,只要配置IP地址,即为UP状态。配置命令为:

    [AR11]inter LoopBack 0
    [AR11-LoopBack0]ip add 2.2.2.2 32

  2. 默认路由

默认路由一般在末节点配置。优点是仅仅用一条路由代替所有路由条目。

[AR10]ip route-static 0.0.0.0  0 下一跳

注意:0.0.0.0 0 表示任意IP,其中第5个0为掩码,表示32个0。

明细路由:具体到某一网段。

默认路由:

路由转发规则:明细路由优先级高于默认路由。如果路由表当中明细路由和默认路由同时存在,则明细路由优先转发。当路由表中只有默认路由时,会选择默认路由。

一般不要在中间节点写2条默认路由,容易产生环路。

  1. 删除路由

    [AR10]undo ip route-static 3.3.3.0 255.255.255.0 GigabitEthernet0/0/0 192.168.1.2

先查看当前的静态路由,之后通过undo删除:

[AR10]display current-configuration 
[V200R003C00]
#
 sysname AR10
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
aaa 
 authentication-scheme default
 authorization-scheme default
 accounting-scheme default
 domain default 
 domain default_admin 
 local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
 local-user admin service-type http       
#
firewall zone Local
 priority 15
#
interface GigabitEthernet0/0/0
 ip address 192.168.1.1 255.255.255.0 
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
 ip address 1.1.1.1 255.255.255.255 
#
ip route-static 3.3.3.0 255.255.255.0 GigabitEthernet0/0/0 192.168.1.2
#
user-interface con 0
 authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
#
wlan ac                                   
#
return
[AR10]undo ip route-static 3.3.3.0 255.255.255.0 GigabitEthernet0/0/0 192.168.1.2
[AR10]display current-configuration 
[V200R003C00]
#
 sysname AR10
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
aaa 
 authentication-scheme default
 authorization-scheme default
 accounting-scheme default
 domain default 
 domain default_admin 
 local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
 local-user admin service-type http       
#
firewall zone Local
 priority 15
#
interface GigabitEthernet0/0/0
 ip address 192.168.1.1 255.255.255.0 
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
 ip address 1.1.1.1 255.255.255.255 
#
user-interface con 0
 authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
#
wlan ac
#
return                                    
[AR10]
  1. 浮动路由

浮动路由就是只让主链路进行工作,备链路不让转发流量。

当主链路出现问题时,路由器选择备用链路。当主链路恢复,路由器会选择主链路。

  1. 路由器转发数据使用 Routing table,而交换机转发数据使用cam cable。
相关推荐
一fan风顺1 分钟前
BGP实验
网络
RememberLey4 分钟前
【VitualBox】VitualBox的网络模式+网络配置
linux·网络·virtualbox
u0109053591 小时前
黑群晖安装教程
网络
IPFoxy6662 小时前
在线安全干货|如何更改IP地址?
网络
二进制杯莫停3 小时前
k8s pod网络故障注入,命令行实现
网络·容器·kubernetes
hgdlip4 小时前
电脑ip地址怎么换地区:操作步骤与利弊分析
网络·电脑·ip地址
域智盾系统4 小时前
电脑USB端口禁止软件有哪些?什么软件能指定USB端口禁用?分享四款好用软件!
网络·电脑
一个很帅的帅哥4 小时前
axios(基于Promise的HTTP客户端) 与 `async` 和 `await` 结合使用
javascript·网络·网络协议·http·async·promise·await