静态路由
1)特点:
由管理员手工配置的,是单向的,因此需要在两个网络之间的边缘路由器上需要双方对指,否则就会造成流量有去无回,缺乏灵活性,适用于小型网络。
2)配置
全局模式:
ip route-static 目标网络ID 子网掩码 下一跳IP
实验目的:
实现两个不同网络间互通
实验拓扑: //今天的拓扑图可能有点乱,因为害怕有人看不懂,所以做了些标注,望谅解 0^0
实验思路:
两网络间通信,任意一网络数据到达网关处需在路由器中查找路由表,找到通往目标网段的最佳路径。但显然现路由器中没有通往另一网络的路由条目,所以作为管理员我们可以手动添加。此处我们可以为路由器配置静态路由。
实验步骤:
#华为
PC机:PC1:192.168.1.1
255.255.255.0
192.168.1.254
PC2:192.168.4.1
255.255.255.0
192.168.4.254
路由器:
R1:
将路由器重命名为R1
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R1
给端口g0/0/2配置IP地址:192.168.1.254/24
[R1]interface GigabitEthernet 0/0/2
[R1-GigabitEthernet0/0/2]ip address 192.168.1.254 24
[R1-GigabitEthernet0/0/2]undo shutdown
Info: Interface GigabitEthernet0/0/2 is not shutdown.
给端口g0/0/0配置IP地址:192.168.2.1/24
[R1-GigabitEthernet0/0/2]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.2.1 24
[R1-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]quit
配置静态路由:0.0.0.0 0.0.0.0 192.168.2.254
[R1]ip route-static 0.0.0.0 0.0.0.0 192.168.2.254
R2:
将路由器重命名为R2
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R2
给端口g0/0/0配置IP地址:192.168.2.254/24
[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 192.168.2.254 24
[R2-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
给端口g0/0/1配置IP地址:192.168.3.1/24
[R2-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[R2-GigabitEthernet0/0/1]ip address 192.168.3.1 24
[R2-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R2-GigabitEthernet0/0/1]quit
配置静态路由:192.168.1.0 255.255.255.0 192.168.2.1 (华为也可用24代替255.255.255.0)
192.168.4.0 24 192.168.3.254
[R2]ip route-static 192.168.1.0 255.255.255.0 192.168.2.1
192.168.4.0 24 192.168.3.254
R3:
将路由器重命名为R3
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R3
给端口g0/0/1配置IP地址:192.168.3.254/24
[R3]interface GigabitEthernet 0/0/1
[R3-GigabitEthernet0/0/1]ip address 192.168.3.254 24
[R3-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
给端口g0/0/2配置IP地址:192.168.4.254/24
[R3-GigabitEthernet0/0/1]interface GigabitEthernet 0/0/2
[R3-GigabitEthernet0/0/2]ip address 192.168.4.254 24
[R3-GigabitEthernet0/0/2]undo shutdown
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[R3-GigabitEthernet0/0/2]quit
配置静态路由:0.0.0.0 0.0.0.0 192.168.3.1
[R3]ip route-static 0.0.0.0 0.0.0.0 192.168.3.1
验证,测试,保存
验证:<R1>display ip routing-table //查看路由表
<R2>display ip routing-table
<R3>display ip routing-table
测试: PC1:ping 192.168.4.1
PC2:ping 192.168.1.1
保存: <R1>save
Are you sure to continue?(y/n)[n]: y
#思科
PC配置同华为;
路由器:
R1:
重命名
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R1
给端口g0/2配置IP地址:192.168.1.254/24
R1(config)#interface gigabitEthernet 0/2
R1(config-if)#ip address 192.168.1.254 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
给端口g0/0配置IP地址:192.168.2.1/24
R1(config)#interface gigabitEthernet 0/0
R1(config-if)#ip address 192.168.2.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
配置静态路由
R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.2.254
R2:
重命名
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R2
给端口g0/0配置IP地址:192.168.2.254/24
R2(config)#interface gigabitEthernet 0/0
R2(config-if)#ip address 192.168.2.254 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
给端口g0/1配置IP地址:192.168.3.1/24
R2(config)#interface gigabitEthernet 0/1
R2(config-if)#ip address 192.168.3.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
配置静态路由
R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1
R2(config)#ip route 192.168.4.0 255.255.255.0 192.168.3.254
R3:
重命名
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R3
给端口g0/1配置IP地址:192.168.3.254/24
R3(config)#interface gigabitEthernet 0/1
R3(config-if)#ip address 192.168.3.254 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
给端口g0/2配置IP地址:192.168.4.254/24
R3(config)#interface gigabitEthernet 0/2
R3(config-if)#ip address 192.168.4.254 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
配置静态路由
R3(config)#ip route 0.0.0.0 0.0.0.0 192.168.3.1
验证,测试,保存
验证:<R1>show ip route //查看路由表
<R2>show ip route //查看路由表
<R3>show ip route //查看路由表
测试:PC1:ping 192.168.4.1
PC2 : ping 192.168.1.1
保存:<R1>write
<R2>write
<R3>write
转载于:https://blog.51cto.com/13886506/2161805