03-02-2020 11:57 AM
Hi,
Here is the question. Is there any way to use a static route only if the source IP address of the packet is something special?
Imagine I have a static route as this:
ip route 10.10.10.0/24 5.5.5.2
I would like to use this static route only if the source IP address of coming packet be 192.168.0.20. This static route shouldn't be used for any other packet that doesn't have such a source IP.
I know that I can use "route-map + set ip next-hop" feature. But in this case, there is no need for a specific static route and a combination of "route-map" and "set ip next hop" is enough to route a packet based on a source IP address, while I would like to use a static route.
Thanks in advance,
Bob
03-02-2020 12:04 PM - edited 03-02-2020 12:18 PM
Routing is done based on destination IP address.
If you want to route based on other criteria such as source IP that is what PBR is for.
Jon
03-02-2020 01:51 PM
Hello,
a possible somewhat creative solution would be something like the below, where an EEM script would install the route whenever the source sends something. How long do you want the route to be in the routing table ?
Router#debug ip packet 1
!
access-list 1 permit host 192.168.0.20
!
event manager applet SOURCE_ROUTE
event syslog pattern "s=192.168.0.20"
action 1.0 cli command "enable"
action 2.0 cli command "conf t"
action 3.0 cli command "ip route 10.10.10.0 255.255.255.0 5.5.5.2"
action 4.0 cli command "exit"
action 5.0 cli command "clear log"
action 6.0 cli command "y"
action 7.0 cli command "end"
03-02-2020 11:58 PM
The problem with that solution is once the route has been entered into the routing table it then applies to all source IPs and not just 192.168.0.20 which is not what the OP wanted.
Jon
03-02-2020 11:59 PM
Thanks Georg,
It's looks an interesting solution but I'm afraid to say it doesn't work in my case.
I need to have that static route permanent and the router uses it whenever meet the condition (receiving a frame with source ip: 192.168.0.20).
In your solution when router receives such a packet with source 192.168.0.20, it adds the static routes but it has two issues:
1- Static route will remain in router
2- When the static routes added to the router it will also apply to any other packet destined to 10.10.10.0/24 regardless of their source IP address.
Br,
Bob
03-03-2020 12:14 AM
Hello,
that's why I was asking how long the route needs to stay in there. You could tweak the script to remove it when there is no traffic sourced from 192.168.0.20. Then again, as soon as the route is in there, all other traffic will use it too...
I'll see if I can think of something else than PBR...
03-03-2020 12:17 AM
Hello
I know that I can use "route-map + set ip next-hop" feature.
The above is policy based routing and it sounds as @Jon Marshall stated this is what you require otherwise anything else would also require a conditional action for path selection
PBR is designed to do exactly as you have queried other than installing a static route
03-03-2020 12:42 AM
Thanks for your comment. You are right but for some reason, I need to have the static route while PBR does routing without an explicit static route.
By the way, I have found something about "Configuring a static route for use with a route map" by using "tag" at the end of the static route and then use that tag in PBR :
But I couldn't find how to use that tag in PBR. If it works then I can use the Static route and PBR to meet my requirement.
\Bob
03-03-2020 12:49 AM
Why do you need the static route ?
Jon
03-03-2020 05:35 AM
Well, this is part of a customized solution that is not easy to explain here. I may open another case to discuss about that.
But it's surprising it is not possible to use a static route only in certain conditions!
\Bob
03-03-2020 06:20 AM
You can use a static route in certain conditions using IP SLA and tracking etc. but the fundamental issue remains the same ie. routing is based on destination IP address only.
Jon
03-03-2020 12:46 PM
Thanks Jon for your reply,
Have you heard about this feature: "install-routes-recurse-via-nexthop" ?!
It seems this is a feature to put a static route on the routing table with using PBR but I'm not sure how it works? At least it doesn't work for me when I try it. Or maybe it is something else!
Br,
Bob
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide