静态路由是在网络设备上手动配置的路由信息,用于指定数据包的传输路径。
无论是项目中交换机的静态路由配置,还是在公司网络中路由器的静态路由设置,都有非常多的应用。
下面我用三个实验实例讲解,让你彻底明白静态路由。
一、静态路由
1. 实验目的
掌握静态路由配2.置与路由表的概念。
2. 实验拓扑
3. 实验步骤
R1配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R1
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]ip address 12.1.1.1 24
[R1-GigabitEthernet0/0/0]undo shutdown
R2配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R2
[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 12.1.1.2 24
[R2-GigabitEthernet0/0/0]undo shutdown
[R2-GigabitEthernet0/0/0]quit
[R2]interface g0/0/1
[R2-GigabitEthernet0/0/1]ip address 23.1.1.2 24
[R2-GigabitEthernet0/0/1]undo shutdown
R3配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R3
[R3]interface GigabitEthernet 0/0/1
[R3-GigabitEthernet0/0/1]ip address 23.1.1.3 24
[R3-GigabitEthernet0/0/1]undo shutdown
测试连通性,发现无法ping通。
[R3]ping 12.1.1.1
PING 12.1.1.1: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
--- 12.1.1.1 ping statistics ---
3 packet(s) transmitted
0 packet(s) received
100.00% packet loss
配置静态路由
[R1]ip route-static 23.1.1.0 255.255.255.0 12.1.1.2 //配置静态路由
[R1]display ip routing-table //查看路由表
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
12.1.1.0/24 Direct 0 0 D 12.1.1.1 GigabitEthernet
0/0/0
12.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
12.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
23.1.1.0/24 Static 60 0 RD 12.1.1.2 GigabitEthernet
0/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
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
以上输出路由条目中可以看到有一条23.1.1.0/24的静态理由。
路由表参数解析如下。
参数 | 描述 |
Destination/Mask | 目标网段/子网掩码 |
Proto | 协议 (static为静态) |
Pre | 优先级。(静态路由优先级为60) |
Cost | 开销。(路由开销为0) |
Flags | 标记。(R代表此迭代理由条目,D此路由下发到FIB表中) |
NextHop | 下一跳地址 |
Interface | 接口 |
[R3]ip route-static 12.1.1.0 255.255.255.0 23.1.1.2
[R3]ping 12.1.1.1
PING 12.1.1.1: 56 data bytes, press CTRL_C to break
Request time out
Reply from 12.1.1.1: bytes=56 Sequence=2 ttl=254 time=90 ms
Reply from 12.1.1.1: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 12.1.1.1: bytes=56 Sequence=4 ttl=254 time=20 ms
Reply from 12.1.1.1: bytes=56 Sequence=5 ttl=254 time=20 ms
思考:为什么不在R2上配置路由?
因为R2上有12.1.1.0/24和23.1.1.0/24的直连路由。可以从R2路由器上查看路由表得知。
[R2]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
12.1.1.0/24 Direct 0 0 D 12.1.1.2 GigabitEthernet
0/0/0
12.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
12.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
23.1.1.0/24 Direct 0 0 D 23.1.1.2 GigabitEthernet
0/0/1
23.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
23.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/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
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
二、缺省路由
1. 实验目的
掌握缺省路由的配置方法和使用场景。
2. 实验拓扑
3. 实验步骤
R1配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R1
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]ip address 12.1.1.1 24
[R1-GigabitEthernet0/0/0]undo shutdown
R2配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R2
[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 12.1.1.2 24
[R2-GigabitEthernet0/0/0]undo shutdown
[R2-GigabitEthernet0/0/0]quit
[R2]interface g0/0/1
[R2-GigabitEthernet0/0/1]ip address 23.1.1.2 24
[R2-GigabitEthernet0/0/1]undo shutdown
[R2-GigabitEthernet0/0/1]quit
[R2]interface g0/0/2
[R2-GigabitEthernet0/0/2]ip address 24.1.1.2 24
[R2-GigabitEthernet0/0/2]undo shutdown
R3配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R3
[R3]interface GigabitEthernet 0/0/1
[R3-GigabitEthernet0/0/1]ip address 23.1.1.3 24
[R3-GigabitEthernet0/0/1]undo shutdown
R4配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R4
[R4]interface GigabitEthernet 0/0/2
[R4-GigabitEthernet0/0/2]ip address 24.1.1.4 24
[R4-GigabitEthernet0/0/2]undo shutdown
配置缺省路由
[R1]ip route-static 0.0.0.0 0.0.0.0 12.1.1.2
[R1]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 Static 60 0 RD 12.1.1.2 GigabitEthernet
0/0/0
12.1.1.0/24 Direct 0 0 D 12.1.1.1 GigabitEthernet
0/0/0
12.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
12.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/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
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
[R3]ip route-static 0.0.0.0 0.0.0.0 23.1.1.2
[R4]ip route-static 0.0.0.0 0.0.0.0 24.1.1.2
测试连通性
[R1]ping 23.1.1.3
PING 23.1.1.3: 56 data bytes, press CTRL_C to break
Reply from 23.1.1.3: bytes=56 Sequence=3 ttl=254 time=30 ms
[R1]ping 24.1.1.4
PING 24.1.1.4: 56 data bytes, press CTRL_C to break
Reply from 24.1.1.4: bytes=56 Sequence=1 ttl=254 time=30 ms
[R4]ping 12.1.1.1
PING 12.1.1.1: 56 data bytes, press CTRL_C to break
Reply from 12.1.1.1: bytes=56 Sequence=1 ttl=254 time=40 ms
[R4]ping 23.1.1.3
PING 23.1.1.3: 56 data bytes, press CTRL_C to break
Reply from 23.1.1.3: bytes=56 Sequence=1 ttl=254 time=30 ms
思考:为什么不用静态路由?
使用静态路由会也可以,只是路由条目会变多。试想以下,如果有1000条路由,那么配置过程就会变得极其繁琐,所以针对与下一跳相同的多条静态路由,可以使用缺省路由来简化配置。
三、浮动静态路由
1. 实验目的
掌握浮动静态路由的使用场景和配置方法。
2. 实验拓扑
3. 实验步骤
R1配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R1
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]ip address 12.1.1.1 24
[R1-GigabitEthernet0/0/0]undo shutdown
[R1-GigabitEthernet0/0/0]quit
[R1]interface g0/0/1
[R1-GigabitEthernet0/0/1]ip address 10.1.1.1 24
[R1-GigabitEthernet0/0/1]undo shutdown
R2配置
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname R2
[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 12.1.1.2 24
[R2-GigabitEthernet0/0/0]undo shutdown
[R2-GigabitEthernet0/0/0]quit
[R2]interface g0/0/1
[R2-GigabitEthernet0/0/1]ip address 10.1.1.2 24
[R2-GigabitEthernet0/0/1]undo shutdown
[R2-GigabitEthernet0/0/1]quit
[R2]interface LoopBack 0 //创建回环接口0号,作为测试用。
[R2-LoopBack0]ip address 8.8.8.8 32
[R2-LoopBack0]undo shutdown
配置浮动静态路由
[R1]ip route-static 8.8.8.8 255.255.255.255 12.1.1.2 preference 50
[R1]ip route-static 8.8.8.8 255.255.255.255 10.1.1.2 preference 100
技术要点
LoopBack是路由器中的一个逻辑接口,它是能够实现数据交换功能,但是物理接口并不存在,通常可以拿来做测试使用。
Preference代表一条路由的可信程度,越小越优先。
关注+点赞+评论+收藏,分享更多网工实验小技巧。
标签:127.0,R1,R2,静态,GigabitEthernet0,12.1,实验,路由 From: https://blog.csdn.net/2301_79308927/article/details/141226423