match ip addressaccess-list_name [access-list_name...]
示例:
ciscoasa(config-route-map)# match ip address testacl
步骤 4
配置一个或多个 set 操作:
设置下一跳地址:
set {ip | ipv6} next-hopipv4_or_ipv6_address
您可以配置多个下一跳 IP 地址,在这种情况下将按指定顺序对它们进行评估,直到找到有效的可路由下一跳 IP 地址。所配置的下一跳应为直连式,否则不会应用 set 操作。
设置默认下一跳地址:
set {ip | ipv6} default next-hopipv4_or_ipv6_address
如果匹配流量的正常路由查询失败,则 ASA 会使用此指定的下一跳 IP 地址转发流量。
设置递归下一跳 IPv4 地址:
set ip next-hop recursive ip_address
set ip next-hop 和 set ip default next-hop 都要求可在直连式子网中找到下一跳。如果使用 set ip next-hop recursive,则下一跳地址不需要是直连式。匹配流量不会在下一跳地址上执行递归查询,而是根据路由器中使用的路由路径被转发到该路由条目使用的下一跳中。
验证路由映射的下一 IPv4 跳是否可用:
set ip next-hop verify-availabilitynext-hop-addresssequence_numbertrackobject
您可以配置 SLA 监控跟踪对象来验证下一跳的可访问性。要验证多个下一跳的可用性,可使用不同的序列号和不同的跟踪对象来配置多个 set ip next-hop verify-availability 命令。
当配置了多个 set 操作时,ASA 将按以下顺序评估它们:set ip next-hop verify-availability;set ip next-hop;set ip next-hop recursive;set interface;set ip default next-hop;set default interface。
ciscoasa(config)# route-map testmap permit 10
ciscoasa(config-route-map)# match ip address <acl_1>
ciscoasa(config-route-map)# set ip next-hop 1.1.1.10
ciscoasa(config)# route-map testmap permit 20
ciscoasa(config-route-map)# match ip address <acl_2>
ciscoasa(config-route-map)# set ip next-hop 2.1.1.10
ciscoasa(config)# route-map testmap permit 30
ciscoasa(config-route-map)# set interface Null0
ciscoasa(config)# route-map testmap permit 10
ciscoasa(config-route-map)# match ip address permit_acl_1 deny_acl_2
ciscoasa(config-route-map)# set ip next-hop 1.1.1.10
ciscoasa(config)# route-map testmap deny 20
ciscoasa(config-route-map)# match ip address permit_acl_3 deny_acl_4
ciscoasa(config-route-map)# set ip next-hop 2.1.1.10
ciscoasa(config)# route-map testmap permit 30
ciscoasa(config-route-map)# match ip address deny_acl_5
ciscoasa(config-route-map)# set interface outside
在以下示例中,当配置了多个 set 操作时,将按照上述顺序对其进行评估。仅当 set 操作的所有选项都已评估且无法应用时,才会考虑后续 set 操作。此排序将确保首先尝试可用性最高 且距离最近的下一跳,然后尝试下一个可用性最高且距离最近的 下一跳,依此类推。
ciscoasa(config)# route-map testmap permit 10
ciscoasa(config-route-map)# match ip address acl_1
ciscoasa(config-route-map)# set ip next-hop verify-availability 1.1.1.10 1 track 1
ciscoasa(config-route-map)# set ip next-hop verify-availability 1.1.1.11 2 track 2
ciscoasa(config-route-map)# set ip next-hop verify-availability 1.1.1.12 3 track 3
ciscoasa(config-route-map)# set ip next-hop 2.1.1.10 2.1.1.11 2.1.1.12
ciscoasa(config-route-map)# set ip next-hop recursive 3.1.1.10
ciscoasa(config-route-map)# set interface outside-1 outside-2
ciscoasa(config-route-map)# set ip default next-hop 4.1.1.10 4.1.1.11
ciscoasa(config-route-map)# set default interface Null0
PBR 配置示例
本节介绍为以下场景配置 PBR 所需的全套配置:
首先,需要配置接口。
ciscoasa(config)# interface GigabitEthernet0/0
ciscoasa(config-if)# no shutdown
ciscoasa(config-if)# nameif inside
ciscoasa(config-if)# ip address 10.1.1.1 255.255.255.0
ciscoasa(config)# interface GigabitEthernet0/1
ciscoasa(config-if)# no shutdown
ciscoasa(config-if)# nameif outside-1
ciscoasa(config-if)# ip address 192.168.6.5 255.255.255.0
ciscoasa(config)# interface GigabitEthernet0/2
ciscoasa(config-if)# no shutdown
ciscoasa(config-if)# nameif outside-2
ciscoasa(config-if)# ip address 172.16.7.6 255.255.255.0
然后,我们需要配置一个访问列表来匹配流量。
ciscoasa(config)# access-list acl-1 permit ip 10.1.0.0 255.255.0.0
ciscoasa(config)# access-list acl-2 permit ip 10.2.0.0 255.255.0.0
我们需要将上述访问列表指定为匹配条件,并指定需要执行的一系列操作,以此来配置一个路由映射。
ciscoasa(config)# route-map equal-access permit 10
ciscoasa(config-route-map)# match ip address acl-1
ciscoasa(config-route-map)# set ip next-hop 192.168.6.6
ciscoasa(config)# route-map equal-access permit 20
ciscoasa(config-route-map)# match ip address acl-2
ciscoasa(config-route-map)# set ip next-hop 172.16.7.7
ciscoasa(config)# route-map equal-access permit 30
ciscoasa(config-route-map)# set ip interface Null0
ciscoasa(config)# interface Loopback1
ciscoasa(config-if)# ip address 15.1.1.100 255.255.255.255
ciscoasa(config-if)# interface Loopback2
ciscoasa(config-if)# ip address 15.1.1.101 255.255.255.255
ciscoasa(config)# ip route 0.0.0.0 0.0.0.0 10.1.1.60
H2:
ciscoasa(config)# interface GigabitEthernet0/1
ciscoasa(config-if)# ip address 65.1.1.100 255.255.255.0
ciscoasa(config-if)# ip route 15.1.1.0 255.255.255.0 65.1.1.60
我们将在 ASA-A 上配置 PBR 以路由源自 H1 的流量。
ASA-A:
ciscoasa(config-if)# access-list pbracl_1 extended permit ip host 15.1.1.100 any
ciscoasa(config-if)# route-map testmap permit 10
ciscoasa(config-if)# match ip address pbracl_1
ciscoasa(config-if)# set ip next-hop 25.1.1.61
ciscoasa(config)# interface GigabitEthernet0/0
ciscoasa(config-if)# policy-route route-map testmap
ciscoasa(config-if)# debug policy-route
H1:ping 65.1.1.100 repeat 1 source loopback1
pbr: policy based route lookup called for 15.1.1.100/44397 to 65.1.1.100/0 proto 1 sub_proto 8 received on interface inside
pbr: First matching rule from ACL(2)
pbr: route map testmap, sequence 10, permit; proceed with policy routing
pbr: evaluating next-hop 25.1.1.61
pbr: policy based routing applied; egress_ifc = outside : next_hop = 25.1.1.61
in 255.255.255.255 255.255.255.255 identity
in 10.1.1.60 255.255.255.255 identity
in 25.1.1.60 255.255.255.255 identity
in 35.1.1.60 255.255.255.255 identity
in 10.127.46.17 255.255.255.255 identity
in 10.1.1.0 255.255.255.0 inside
in 25.1.1.0 255.255.255.0 outside
in 35.1.1.0 255.255.255.0 dmz
ciscoasa(config)# access-list pbracl_2 extended permit ip host 15.1.1.101 any
ciscoasa(config)# route-map testmap permit 20
ciscoasa(config-route-map)# match ip address pbracl
ciscoasa(config-route-map)# set ip next-hop 35.1.1.61
ciscoasa(config)# show run route-map
!
route-map testmap permit 10
match ip address pbracl_1
set ip next-hop 25.1.1.61
!
route-map testmap permit 20
match ip address pbracl_2
set ip next-hop 35.1.1.61
!
H1:ping 65.1.1.100 repeat 1 source loopback2
调试如下所示:
pbr: policy based route lookup called for 15.1.1.101/1234 to 65.1.1.100/1234 proto 6 sub_proto 0 received on interface inside
pbr: First matching rule from ACL(3)
pbr: route map testmap, sequence 20, permit; proceed with policy routing
pbr: evaluating next-hop 35.1.1.61
pbr: policy based routing applied; egress_ifc = dmz : next_hop = 35.1.1.61
从输入路由表中所选的路由条目如下所示:
in 255.255.255.255 255.255.255.255 identity
in 10.1.1.60 255.255.255.255 identity
in 25.1.1.60 255.255.255.255 identity
in 35.1.1.60 255.255.255.255 identity
in 10.127.46.17 255.255.255.255 identity
in 10.1.1.0 255.255.255.0 inside
in 25.1.1.0 255.255.255.0 outside
in 35.1.1.0 255.255.255.0 dmz
引入了以下命令:set ip next-hop verify-availability、set ip next-hop、set ip next-hop recursive、set interface、set ip default next-hop、set default interface、set ip df、set ip dscp、policy-route route-map、show policy-route 和 debug policy-route