一、相关概念
1. 静态路由的优点 (1).不需要动态路由选择协议,减少路由器的日常开销; (2).在小型网络上很容易配置; (3).可以控制路由选择; (4).安全性比较高,允许网络管理员指定在有限的网络划分中哪些是可以公开,哪些可以隐藏起来。
二、简单的例子
1、拓扑结构:
2、设置主机IP地址
这是PC0的设置,其他主机也以此类推
34、配置路由
路由器1(R1):
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host
Router(config)#hostname R1(改名为:R1)
R1(config)#int
R1(config)#interface g0/1
R1(config-if)#iip add
R1(config-if)#ip addr
R1(config-if)#ip address 192.168.1.254 255.255.255.0
R1(config-if)#no shut
R1(config-if)#no shutdown
R1(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up
R1(config-if)#exit
R1(config)#int g
R1(config)#int gigabitEthernet 0/0
R1(config-if)#ip add
R1(config-if)#ip address 192.168.12.1 255.255.255.0
R1(config-if)#no s
R1(config-if)#no sh
R1(config-if)#no shutdown
R1(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up
R1(config-if)#exit
路由器2(R1):
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host
Router(config)#hostname R2
R2(config)#int g
R2(config)#int gigabitEthernet 0/1
R2(config-if)#ip add
R2(config-if)#ip address 192.168.2.254 255.255.255.0
R2(config-if)#no shu
R2(config-if)#no shutdown
R2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up
R2(config-if)#ex
R2(config-if)#exit
R2(config)#int g
R2(config)#int gigabitEthernet 0/0
R2(config-if)#ip add
R2(config-if)#ip address 192.168.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#no shutdown
R2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up
R2(config-if)#ex
R2(config-if)#exit
4、配置静态路由(简单的拓扑结构)
R1(config)#ip route 192.168.2.0 255.255.255.0 192.168.12.2
第一个ip地址是目的网段,第二个是掩码 第三个是下一跳
R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.12.1
这样就算配好了,可以用命令:show ip route 查看路由信息
R1#show ip route(需要在特权用户模式下)
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks6
C 192.168.1.0/24 is directly connected, GigabitEthernet0/1
L 192.168.1.254/32 is directly connected, GigabitEthernet0/1
S 192.168.2.0/24 [1/0] via 192.168.12.2 (via表示下一跳 [1/0] 1表示管理距离,0表示跳数)
192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.12.0/24 is directly connected, GigabitEthernet0/0
L 192.168.12.1/32 is directly connected, GigabitEthernet0/0
5、验证结果
ping不同网段的主机
如图 pc0(192.168.1.1) ping pc2 (192.168.2.1)
开始丢两个包是正常的
结果是:配置正确,ping通啦!!!