需求:
实现 PC1 与 PC2 互通
1、拓扑图
主机 | IP | 掩码 | 网关 |
PC1 | 192.168.10.10 | 255.255.255.0 | 192.168.10.1 |
PC2 | 192.168.40.40 | 255.255.255.0 | 192.168.40.1 |
PC3 | 192.168.30.30 | 255.255.255.0 | 192.168.30.1 |
2、R1 路由器
<Huawei>undo ter mo
Info: Current terminal monitor is off.
<Huawei>
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]
[Huawei]sys R1
[R1]
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]
[R1-GigabitEthernet0/0/0]ip addr 192.168.10.1 24
[R1-GigabitEthernet0/0/0]
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]
[R1-GigabitEthernet0/0/1]ip addr 192.168.20.1 24
3、R2 路由器
<Huawei>undo ter mo
Info: Current terminal monitor is off.
<Huawei>
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]
[Huawei]sys R2
[R2]
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]
[R2-GigabitEthernet0/0/0]ip addr 192.168.20.2 24
[R2-GigabitEthernet0/0/0]
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]
[R2-GigabitEthernet0/0/1]ip addr 192.168.30.1 24
[R2-GigabitEthernet0/0/1]
[R2-GigabitEthernet0/0/1]int g0/0/2
[R2-GigabitEthernet0/0/2]
[R2-GigabitEthernet0/0/2]ip addr 192.168.40.1 24
4、我们首先查看 2个路由器 路由表信息
(1)R1路由器 找到2个直连路由信息,分别是
192.168.10.0/24 下一跳 192.168.10.1
192.168.20.0/24 下一跳 192.168.20.1
[R1]dis ip rou
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
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.10.0/24 Direct 0 0 D 192.168.10.1 GigabitEthernet 0/0/0
192.168.10.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
192.168.10.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
192.168.20.0/24 Direct 0 0 D 192.168.20.1 GigabitEthernet 0/0/1
192.168.20.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
192.168.20.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
(2)R2 路由器 找到3个直连路由信息,因为有3个端口
[R2]dis ip rou
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 13 Routes : 13
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.20.0/24 Direct 0 0 D 192.168.20.2 GigabitEthernet 0/0/0
192.168.20.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
192.168.20.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
192.168.30.0/24 Direct 0 0 D 192.168.30.1 GigabitEthernet 0/0/1
192.168.30.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
192.168.30.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
192.168.40.0/24 Direct 0 0 D 192.168.40.1 GigabitEthernet 0/0/2
192.168.40.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/2
192.168.40.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/2
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
5、这时 PC1 访问 PC2
(1)PC1 访问 PC2 192.168.40.40 是不通的,因为中间还要经过 R2 路由器,并且没有路由
(2)PC1 访问 R1 的 G0/0/1 端口 192.168.20.1 是通的,因为是直连路由
6、R1路由器 添加一条静态路由
(1)静态路由 192.168.40.0/24 下一跳 192.168.20.2
[R1]ip route-static 192.168.40.0 24 192.168.20.2
(2)查看 R1 路由表
这时我们看到多一个静态路由信息
192.168.40.0/24 下一跳 192.168.20.2
[R1]dis ip rou
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 11 Routes : 11
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.10.0/24 Direct 0 0 D 192.168.10.1 GigabitEthernet 0/0/0
192.168.10.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
192.168.10.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
192.168.20.0/24 Direct 0 0 D 192.168.20.1 GigabitEthernet 0/0/1
192.168.20.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
192.168.20.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
192.168.40.0/24 Static 60 0 RD 192.168.20.2 GigabitEthernet 0/0/1
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
(3)我们用 PC1访问 PC2
发现还是不通
7、我们将 R2路由器 也添加一条静态路由
(1)静态路由 192.168.10.0/24 下一跳 192.168.20.1
[R2]ip route-static 192.168.10.0 24 192.168.20.1
(2)查看 R2 路由表
也多了一条静态路由信息
192.168.10.0/24 下一跳 192.168.20.1
[R2]dis ip rou
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 14 Routes : 14
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.10.0/24 Static 60 0 RD 192.168.20.1 GigabitEthernet 0/0/0
192.168.20.0/24 Direct 0 0 D 192.168.20.2 GigabitEthernet 0/0/0
192.168.20.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
192.168.20.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
192.168.30.0/24 Direct 0 0 D 192.168.30.1 GigabitEthernet 0/0/1
192.168.30.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
192.168.30.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
192.168.40.0/24 Direct 0 0 D 192.168.40.1 GigabitEthernet 0/0/2
192.168.40.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/2
192.168.40.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/2
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
(3)再次尝试,成功