要求:对于as2内部的用户,去往1.1.0.0/24和1.1.2.0/24默认从r2走,去往1.1.2.0/24和1.1.3.0/24默认从r3走,并且保证r2或r3任意一台down掉,网络仍然那保持连通性。

option 2就是使用as-path prepend,对r2来说,如果他想从r3去1.1.2.0/24和1.1.3.0/24,那只要把这2条路由的as-path加长就可以了

R1

hostname R1

!

interface Loopback0

ip address 1.1.0.1 255.255.255.0

!

interface Loopback1

ip address 1.1.1.1 255.255.255.0

!

interface Loopback2

ip address 1.1.2.1 255.255.255.0

!

interface Loopback3

ip address 1.1.3.1 255.255.255.0

!

interface FastEthernet0/0

ip address 192.168.12.1 255.255.255.0

speed 100

full-duplex

!

interface FastEthernet0/1

ip address 192.168.13.1 255.255.255.0

speed 100

full-duplex

!

router bgp 10

no synchronization

bgp router-id 1.1.1.1

bgp log-neighbor-changes

network 1.1.0.0 mask 255.255.255.0

network 1.1.1.0 mask 255.255.255.0

network 1.1.2.0 mask 255.255.255.0

network 1.1.3.0 mask 255.255.255.0

neighbor 192.168.12.2 remote-as 20

neighbor 192.168.12.2 soft-reconfiguration inbound

neighbor 192.168.12.2 route-map r2 out

neighbor 192.168.13.3 remote-as 20

neighbor 192.168.13.3 soft-reconfiguration inbound

neighbor 192.168.13.3 route-map r3 out

no auto-summary

!

ip prefix-list detail1 seq 5 permit 1.1.0.0/24

ip prefix-list detail1 seq 10 permit 1.1.1.0/24

!

ip prefix-list detail2 seq 5 permit 1.1.2.0/24

ip prefix-list detail2 seq 10 permit 1.1.3.0/24

!

route-map r2 permit 10

match ip address prefix-list detail2

set as-path prepend 10 10

!

route-map r2 permit 20

!

route-map r3 permit 10

match ip address prefix-list detail1

set as-path prepend 10 10

!

route-map r3 permit 20

!

end

R2

hostname R2

!

interface Loopback0

ip address 2.2.2.2 255.255.255.255

!

interface FastEthernet0/0

ip address 192.168.12.2 255.255.255.0

speed 100

full-duplex

!

interface FastEthernet0/1

ip address 192.168.23.2 255.255.255.0

speed 100

full-duplex

!

router bgp 20

no synchronization

bgp router-id 2.2.2.2

bgp log-neighbor-changes

network 192.168.23.0

neighbor 192.168.12.1 remote-as 10

neighbor 192.168.12.1 soft-reconfiguration inbound

neighbor 192.168.23.3 remote-as 20

neighbor 192.168.23.3 next-hop-self

neighbor 192.168.23.3 soft-reconfiguration inbound

 

no auto-summary

!

end

R3

hostname R3

!

interface Loopback0

ip address 3.3.3.3 255.255.255.255

!

interface FastEthernet0/0

ip address 192.168.13.3 255.255.255.0

speed 100

full-duplex

!

interface FastEthernet0/1

ip address 192.168.23.3 255.255.255.0

speed 100

full-duplex

!

router bgp 20

no synchronization

bgp router-id 3.3.3.3

bgp log-neighbor-changes

network 192.168.23.0

neighbor 192.168.13.1 remote-as 10

neighbor 192.168.13.1 soft-reconfiguration inbound

neighbor 192.168.23.2 remote-as 20

neighbor 192.168.23.2 next-hop-self

neighbor 192.168.23.2 soft-reconfiguration inbound

no auto-summary

!

end

verification

R2#sho ip bgp 1.1.3.0

BGP routing table entry for 1.1.3.0/24, version 13

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Advertised to update-groups:

1

10 10 10, (received & used)

192.168.12.1 from 192.168.12.1 (1.1.1.1)

Origin IGP, metric 0, localpref 100, valid, external

10, (received & used)

192.168.23.3 from 192.168.23.3 (3.3.3.3)

Origin IGP, metric 0, localpref 100, valid, internal, best

R2#sho ip route 1.1.3.0

Routing entry for 1.1.3.0/24

Known via "bgp 20", distance 200, metric 0

Tag 10, type internal

Lastupdatefrom 192.168.23.3 00:33:57 ago

Routing Descriptor Blocks:

* 192.168.23.3, from 192.168.23.3, 00:33:57 ago

Route metric is 0, traffic share count is 1

AS Hops 1

Route tag 10

R2#tra

R2#traceroute 1.1.3.1 pro

R2#traceroute 1.1.3.1 probe 1

Type escape sequence to abort.

Tracing the route to 1.1.3.1

1 192.168.23.3 128 msec

2 192.168.13.1 300 msec

R3#sho ip route 1.1.1.0

Routing entry for 1.1.1.0/24

Known via "bgp 20", distance 200, metric 0

Tag 10, type internal

Lastupdatefrom 192.168.23.2 00:33:49 ago

Routing Descriptor Blocks:

* 192.168.23.2, from 192.168.23.2, 00:33:49 ago

Route metric is 0, traffic share count is 1

AS Hops 1

Route tag 10

R3#tra

R3#traceroute 1.1.1.1 pro

R3#traceroute 1.1.1.1 probe 1

Type escape sequence to abort.

Tracing the route to 1.1.1.1

1 192.168.23.2 48 msec

2 192.168.12.1 360 msec