Using Policy-Based Routing to Route Based on Source Address
Problem
You want to use different network links depending on the source address.
Solution
Policy-based routing allows you to configure special routing rules beyond the normal IP routing table. One common application is to route packets based on the IP source address rather than the destination address:
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z. Router(config)#access-list
1
permit
Router(config)#
10.15.35.0 0.0.0.255
access-list
2
permit
Router(config)#
10.15.36.0 0.0.0.255
interface
Router(config-if)#
Ethernet0
ip address
Router(config-if)#
10.15.22.7 255.255.255.0
ip policy route-map
Router(config-if)#
Engineers
ip route-cache policy
Router(config-if)#exit
Router(config)#route-map
Engineers
permit
Router(config-route-map)#
10
match ip address
Router(config-route-map)#
1
set ip next-hop
Router(config-route-map)#
10.15.27.1
exit
Router(config)#route-map
Engineers
permit
Router(config-route-map)#
20
match ip address
Router(config-route-map)#
2
set interface
Router(config-route-map)#
Ethernet1
end
Router#
Discussion
This configuration example defines a special routing policy for a group of users defined by the route map called “Engineers.” This name is arbitrary, and we recommend that you choose names for your route maps that are meaningful in your organization. This example applies the route map to all of the packets received on the interface Ethernet0. This might be required because these users ...
Get Cisco IOS Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.