1. 搭建拓扑并连接设备
-
添加 3 台路由器(例如 Cisco 2911 或 2620)。
-
按以下方式连接接口(以 FastEthernet 或 GigabitEthernet 为例):
-
R1 的 g0/0 连接 R2 的 g0/0
-
R2 的 g0/1 连接 R3 的 g0/0
-
也可以使用 Serial 接口,但注意接口名称。本示例使用 Ethernet 接口。
2. 配置各路由器接口 IP 地址及环回口
R1 配置
bash
enable configure terminal hostname R1 # 环回口 Loopback 0 interface loopback 0 ip address 192.168.10.1 255.255.255.0 no shutdown exit # 连接 R2 的接口(假设为 g0/0) interface g0/0 ip address 192.168.1.1 255.255.255.0 no shutdown exit # 查看配置 do show ip interface brief
R2 配置
bash
enable configure terminal hostname R2 # 环回口 interface loopback 0 ip address 192.168.20.1 255.255.255.0 no shutdown exit # 连接 R1 的接口(g0/0) interface g0/0 ip address 192.168.1.2 255.255.255.0 no shutdown exit # 连接 R3 的接口(g0/1) interface g0/1 ip address 192.168.3.2 255.255.255.0 no shutdown exit do show ip interface brief
R3 配置
bash
enable configure terminal hostname R3 # 环回口 interface loopback 0 ip address 192.168.30.1 255.255.255.0 no shutdown exit # 连接 R2 的接口(g0/0) interface g0/0 ip address 192.168.3.3 255.255.255.0 no shutdown exit do show ip interface brief
此时直连链路应该能通(例如从 R1 ping 192.168.1.2 成功),但非直连网段无法访问。
3. 配置静态路由(实现全网互通)
3.1 R1 上的静态路由
R1 需要到达 192.168.20.0/24 和 192.168.30.0/24,下一跳都是 R2(192.168.1.2)。
bash
ip route 192.168.20.0 255.255.255.0 192.168.1.2 ip route 192.168.30.0 255.255.255.0 192.168.1.2
3.2 R2 上的静态路由
R2 需要到达 192.168.10.0/24(下一跳 R1)和 192.168.30.0/24(下一跳 R3)。
bash
ip route 192.168.10.0 255.255.255.0 192.168.1.1 ip route 192.168.30.0 255.255.255.0 192.168.3.3
3.3 R3 上的静态路由
R3 需要到达 192.168.10.0/24 和 192.168.20.0/24,下一跳都是 R2(192.168.3.2)。
bash
ip route 192.168.10.0 255.255.255.0 192.168.3.2 ip route 192.168.20.0 255.255.255.0 192.168.3.2
4. 验证全网互通
在每台路由器上执行 ping 命令,测试到其它环回口的连通性。
-
R1 上测试:
bash
ping 192.168.20.1 ping 192.168.30.1
-
R2 上测试:
bash
ping 192.168.10.1 ping 192.168.30.1
-
R3 上测试:
bash
ping 192.168.10.1 ping 192.168.20.1
如果所有 ping 都成功,说明静态路由配置正确,全网互通。
5. 查看路由表(可选)
bash
show ip route static
可以看到添加的静态路由条目。
转载自CSDN-专业IT技术社区
原文链接:https://blog.csdn.net/2603_94880596/article/details/160411210



