BGP配置和应用案例

发布于:2024-04-26 ⋅ 阅读:(31) ⋅ 点赞:(0)

策略路由的配置步骤

l 策略路由的配置步骤如下:

Ø 创建route-map

Ø 通过ACL匹配感兴趣的数据,定义策略动作

Ø 在指定接口下通过ip policy 命令应用route-map

l 最终实现对通过该接口进入设备的数据进行检查,对匹配的数据执行规定的策略

创建route-map

l 路由器通过route-map语句对符合条件的数据包实施路由策略

Ø Permit:对符合条件的数据包实施策略

Ø Deny:对符合条件的数据包不实施策略

Sequence: 0-65535, route-map语句的执行顺序(插入/删除route-map语句 )

Router(config)#route-map route-map-name [permit | deny] sequence

l route-map 最后有有一条deny所有的语句,对于没有匹配到策略路由的流量,不会把内网的流量丢弃, 而是做正常的IP路由转发。

定义出口

l 定义匹配规则后的操作,如对符合规则的数据包进行下一跳的设置。

l 先策略路由,后查路由表

Ø 定义发出的数据包的出口

Router(config-route-map)# set interface type number [...type number]

Ø 定义发出的数据包的下一跳地址

Router(config-route-map)# set ip next-hop ip-address [...ip-address]

l 特殊的下一跳:定义到达目的网络时无显式路由时的隐含下一跳地址

Ø 路由器先检查路由表,后检查策略路由

Router(config-route-map)# set ip default next-hop ip-address [...ip-address]

应用到端口

l 在入口上应用策略路由,从该接口进入设备的数据会先执行PBR。

Ø 策略路由一定要应用到数据包的in方向接口,不能应用到数据包的out方向接口

Router(config-if)# ip policy route-map map-name

l 查看策略路由

Router# show ip policy

策略路由案例

l 根据数据源选择不同的出口,其余数据走默认路由

Ø 192.168.1.0用户访问外网强制走R5的线路;

Ø 192.168.2.0用户访问外网强制走R6的线路;

access-list 1 permit 192.168.1.0 0.0.0.255

access-list 2 permit 192.168.2.0 0.0.0.255

route-map PBR permit 10

match ip address 1

set ip next-hop 10.1.45.2

route-map PBR permit 40

match ip address 2

set ip next-hop 10.1.46.2

interface GigabitEthernet 0/0

ip policy route-map PBR

ip route 0.0.0.0 0.0.0.0 10.1.45.2

ip route 0.0.0.0 0.0.0.0 10.1.46.2 20

l 根据数据源选择不同的出口,其余数据走默认路由

Ø 192.168.1.0用户访问外网强制走ISP1的线路;

Ø 192.168.2.0用户访问外网强制走ISP2的线路;

access-list 1 permit 192.168.1.0 0.0.0.255

access-list 2 permit 192.168.2.0 0.0.0.255

ip nat inside source list 1 interface G0/1 overload

ip nat inside source list 2 interface G0/2 overload

注意:路由器的其他配置均以省略,请根据情况配置