学习日记(路由与交换技术)——浮动静态路由和缺省路由


一、浮动静态路由

浮动静态路由的作用是实现备份路由

1、原理:如果链路发生故障,浮动静态路由即为主要静态或动态路由提供备份路径的静态路由。 浮动静态路由仅在主路由不可用时使用。 为了完成此操作,浮动静态路由配置了比主路由更高的管理距离

2、操作:浮动静态路由可配置为通过控制管理距离值来备份主链路。 通过配置浮动静态路由做到路由备份,实现在网络中路由的有备无患。

3、简单的例子

拓扑结构:


主机的IP地址:

 PC1

PC2


路由器的配置

Router 1:

Router>en

Router#conf t

Enter configuration commands, one per line. End with CNTL/Z.

R2(config)#host

R2(config)#hostname R1

R1(config)#int g 0/0

R1(config-if)#ip add

R1(config-if)#ip address 192.168.1.254 255.255.255.0(接口0/0 的IP地址)

R1(config-if)#no shu

R1(config-if)#no shutdown

R1(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

R1(config-if)#e

R1(config-if)#exit

R1(config)#int g 0/1

R1(config-if)#ip address 192.168.12.1 255.255.255.0(接口0/1 的IP地址)

R1(config-if)#no shutdown

R1(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

R1(config-if)#e

R1(config)#int g 0/2

R1(config-if)#ip address 192.168.21.1 255.255.255.0(接口0/2 的IP地址)

R1(config-if)#no shutdown

R1(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up

R1(config-if)#e

R1(config)#

R1(config)#ip route 192.168.2.0 255.255.255.0 192.168.12.2(配置静态路由)

R1(config)#ip route 192.168.2.0 255.255.255.0 192.168.21.2 10(10代表的是开销,只要比1大就好)(这一条就是备份的,也是浮动静态路由)

R1(config)#do 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 masks

C 192.168.1.0/24 is directly connected, GigabitEthernet0/0

L 192.168.1.254/32 is directly connected, GigabitEthernet0/0

S 192.168.2.0/24 [1/0] via 192.168.12.2([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/1

L 192.168.12.1/32 is directly connected, GigabitEthernet0/1

192.168.21.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.21.0/24 is directly connected, GigabitEthernet0/2

L 192.168.21.1/32 is directly connected, GigabitEthernet0/2

R1(config)#


路由器2的配置跟1差不多相同

Router 2 :

R2(config-if)#e

R2(config-if)#exit

R2(config)#int g 0/1

R2(config-if)#ip address 192.168.12.2 255.255.255.0

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)#e

R2(config)#int g 0/2

R2(config-if)#ip address 192.168.21.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up

R2(config-if)#e

R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.12.1

R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.21.1 10

R2#show ip route (特权模式下不用加 do

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

S 192.168.1.0/24 [1/0] via 192.168.12.1

192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.2.0/24 is directly connected, GigabitEthernet0/0

L 192.168.2.254/32 is directly connected, GigabitEthernet0/0

192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.12.0/24 is directly connected, GigabitEthernet0/1

L 192.168.12.2/32 is directly connected, GigabitEthernet0/1

192.168.21.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.21.0/24 is directly connected, GigabitEthernet0/2

L 192.168.21.2/32 is directly connected, GigabitEthernet0/2


结果验证

PC1 ping PC2



 二、缺省路由

什么时候用到缺省路由呢?

答:当数据无论想去那个网络,都得通过那个路由器,这时候就可以把路由器设置成缺省(默认)路由。

例子:

相关代码:
Route 1:

Router>en

Router#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#host

Router(config)#hostname R1

R1(config)#in

R1(config)#int g

R1(config)#int gigabitEthernet 0/0

R1(config-if)#ip add

R1(config-if)#ip address 192.168.1.254 255.255.255.0

R1(config-if)#no sh

R1(config-if)#no shutdown

R1(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

R1(config-if)#e

R1(config-if)#exit

R1(config)#int g 0/1

R1(config-if)#ip add

R1(config-if)#ip address

R1(config-if)#ip address 192.168.3.254 255.255.255.0

R1(config-if)#no sh

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)#e

R1(config-if)#exit

R1(config)#int g0/2

R1(config-if)#ip add

R1(config-if)#ip address 192.168.12.1 255.255.255.0

R1(config-if)#no sh

R1(config-if)#no shutdown

R1(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up

R1(config-if)#e

R1(config-if)#exit

R1(config)#

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up

R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.12.2 (配置缺省路由,所有的目标网络表达为0.0.0.0 掩码为0.0.0.0)

R1(config)#do 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 192.168.12.2 to network 0.0.0.0

192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.1.0/24 is directly connected, GigabitEthernet0/0

L 192.168.1.254/32 is directly connected, GigabitEthernet0/0

192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.3.0/24 is directly connected, GigabitEthernet0/1

L 192.168.3.254/32 is directly connected, GigabitEthernet0/1

192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.12.0/24 is directly connected, GigabitEthernet0/2

L 192.168.12.1/32 is directly connected, GigabitEthernet0/2

S* 0.0.0.0/0 [1/0] via 192.168.12.2  (说明缺省路由配置成功)


Route 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 0/0

R2(config-if)#ip add

R2(config-if)#ip address 192.168.2.254 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)#e

R2(config-if)#exit

R2(config)#int g 0/1

R2(config-if)#ip add

R2(config-if)#ip address 192.168.4.254 255.255.255.0

R2(config-if)#no sh

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

e

R2(config-if)#exit

R2(config)#int g 0/2

R2(config-if)#ip add

R2(config-if)#ip address 192.168.12.2 255.255.255.0

R2(config-if)#no s

R2(config-if)#no sh

R2(config-if)#no shutdown

R2(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up

R2(config-if)#e

R2(config-if)#exit

R2(config)#ip rou

R2(config)#ip route 0.0.0.0 0.0.0.0 192.168.12.1

R2(config)#do 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 192.168.12.1 to network 0.0.0.0

192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.2.0/24 is directly connected, GigabitEthernet0/0

L 192.168.2.254/32 is directly connected, GigabitEthernet0/0

192.168.4.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.4.0/24 is directly connected, GigabitEthernet0/1

L 192.168.4.254/32 is directly connected, GigabitEthernet0/1

192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.12.0/24 is directly connected, GigabitEthernet0/2

L 192.168.12.2/32 is directly connected, GigabitEthernet0/2

S* 0.0.0.0/0 [1/0] via 192.168.12.1


结果:

所有网络可以互相Ping通


嘿嘿,这篇文章就到这结束啦,加油。 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值