cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
15538
Views
5
Helpful
3
Replies

Static route tracking

jay_7301
Level 1
Level 1

Hello,

 

I have 3 routes in my network and want to track a static route so if the upstream link fails it will remove it from the routing table, and once it comes backup add it back to the routing table.

I have it setup so if we do not get a response from 192.168.1.2 it will remove it from the routing table which seems to work well. However when i bring the link backup it does not inject the static route back into the routing table. Is there something missing in my code below? Looking online i cannot see anything i need to add here? 

 

ip sla 10

 icmp-echo 192.168.1.2 source-interface FastEthernet0/0

 threshold 2

 timeout 1000

 frequency 3

ip sla schedule 10 life forever start-time now

 

track 10 ip sla 10 reachability

ip route 192.168.1.0 255.255.255.252 10.1.1.2 track 10

 

Thanks

3 Replies 3

cadet alain
VIP Alumni
VIP Alumni

Hi,

I think you've got " a chicken and egg " problem.the only way to get to 192.168.1.2 is via the static route you are tracking and once this route is away from RIB thenyour router still tries to ping 192.168.1.2 but as the route is not there it can't and so the route is not reinstalled.

Either  configure a more specific route for the IP you are pinging:

ip route 192.168.1.2 255.255.255.255 10.1.1.2

Or use local PBR for pinging 192.168.1.2:

access-list 100 permit icmp any host 192.168.1.2

route-map SLA permit 10

match ip address 100

set ip next-hop 10.1.1.2

ip local policy route-map SLA

 

Regards,

 

Alain

Don't forget to rate helpful posts.

Hello

Try this:

track 1 interface FastEthernet0/0 line-protocol

event manager applet Static-DOWN
 event track 1 state down
 action 5.0 cli command "enable"
 action 5.1 cli command "conf t"
 action 5.2 cli command "no ip route 192.168.1.0 255.255.255.252 10.1.1.2"
 action 5.3 cli command "end"

event manager applet Static-UP
 event track 1 state up
 action 5.5 cli command "enable"
 action 5.6 cli command "conf t"
 action 5.7 cli command "ip route 192.168.1.0 255.255.255.252 10.1.1.2"
 action 5.8 cli command "end"

 

res

Paul

 


Please rate and mark as an accepted solution if you have found any of the information provided useful.
This then could assist others on these forums to find a valuable answer and broadens the community’s global network.

Kind Regards
Paul

This is one we did to do something similar. We found that no matter what interface we specified that the router was chasing a route to our other DC where we were also injecting that routes from a different path.

 

Yes it might be a bit much but it check for system uptime to ensure that the interface up/down notification wasn't generated from a cold start condition etc etc. A little overly complicated but a fun exercise that works for us 100% every time without fail or any user involvement whatsoever.

 

::cisco::eem::event_register_syslog pattern "Line protocol on Interface GigabitEthernet1/0/48*" occurs 1 maxrun 20 queue_priority high nice 0

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]

# --------------- Determine the uptime in minutes so we dont triggr a route redistribution change on a cold start -------------
array set snmp_res [sys_reqinfo_snmp oid 1.3.6.1.2.1.1.3.0 get_type exact]
set snmp_val $snmp_res(value)
set dvar1 100
set dvar2 60

# string range $sys_int 36 39
# --------------- Grab the device name, Ifindex, description and operational status of Gi 1/0/48 -------------
set routername [info hostname]
set sys_int [string range [sys_reqinfo_snmp oid 1.3.6.1.2.1.2.2.1.1.55 get_type exact] 36 37]
set sys_int_desc [string range [sys_reqinfo_snmp oid 1.3.6.1.2.1.2.2.1.2.55 get_type exact] 36 56]
set sys_int_oper_stat [string range [sys_reqinfo_snmp oid 1.3.6.1.2.1.2.2.1.8.55 get_type exact] 36 36]

# convert the exact syslog uptime from "TICKS" to minutes
set uptime [expr $snmp_val / $dvar1 / $dvar2]
set bootwindow 3

# Debug the VARs
# Action_syslog msg "$sys_int -- $sys_int_desc -- $sys_int_oper_stat"

# only execute and DISABLE the SOME ROUTES route redistribution flip if the router / switch has an uptime greater then 3 minutes,
# AND the interface in Gi1/0/48 AND the Ifindex of the interface is 55 AND the operational status of the interface is "2 / Down".
if {$uptime > $bootwindow} {
if {$sys_int == "55"} {
if {$sys_int_desc == "GigabitEthernet1/0/48"} {
if {$sys_int_oper_stat == "2"} {

# open CLI and executes
if {[catch {cli_open} result]} {error $result $errorInfo} else {array set cli_fd $result}
if {[catch {cli_exec $cli_fd(fd) "enable"} result]} {error $result $errorInfo}
if {[catch {cli_exec $cli_fd(fd) "configure terminal"} result]} {error $result $errorInfo}

# XXX run BGP so deny on the RM_STATIC_TO_BGP route-map
if {$routername == "SOME_HOSTNAME"} {
if {[catch {cli_exec $cli_fd(fd) "route-map RM_STATIC_TO_BGP deny 10"} result]} {error $result $errorInfo}
}
# XXX run OSPF so deny on the RM_STATIC_TO_OSPF route-map
if {$routername == "SOME_OTHER_HOSTNAME"} {
if {[catch {cli_exec $cli_fd(fd) "route-map RM_STATIC_TO_OSPF deny 10"} result]} {error $result $errorInfo}
}

# write to system's local logging buffer
action_syslog msg "****************************************************************************************************"
action_syslog msg "********************** Important Message Regarding SOME ROUTES Routes ***********************************"
action_syslog msg "****************************************************************************************************"
action_syslog msg "* $routername EEM Message - Uptime is $uptime minutes and the boot window is $bootwindow minutes"
action_syslog msg "* $routername EEM Message - Uptime is > than the boot window - This is not a cold start"
action_syslog msg "* $routername EEM Message - The SOME ROUTES connection has been lost"
action_syslog msg "* $routername EEM Message - The redistribution of SOME ROUTES routes has been disabled $routername"
action_syslog msg "****************************************************************************************************"
action_syslog msg "****************************************************************************************************"
action_snmp_trap

# close CLI
if {[catch {cli_close $cli_fd(fd) $cli_fd(tty_id)} result]} {error $result $errorInfo}
}
}
}
# only execute and ENABLE the SOME ROUTES route redistribution flip if the router / switch has an uptime greater then 3 minutes,
# AND the interface in Gi1/0/48 AND the Ifindex of the interface is 55 AND the operational status of the interface is "1 / UP".
if {$sys_int == "55"} {
if {$sys_int_desc == "GigabitEthernet1/0/48"} {
if {$sys_int_oper_stat == "1"} {

# open CLI and execute
if {[catch {cli_open} result]} {error $result $errorInfo} else {array set cli_fd $result}
if {[catch {cli_exec $cli_fd(fd) "enable"} result]} {error $result $errorInfo}
if {[catch {cli_exec $cli_fd(fd) "configure terminal"} result]} {error $result $errorInfo}

# XXX run BGP so allow on the RM_STATIC_TO_BGP route-map
if {$routername == "SOME_HOSTNAME"} {
if {[catch {cli_exec $cli_fd(fd) "route-map RM_STATIC_TO_BGP permit 10"} result]} {error $result $errorInfo}
}
# DXXX run OSPF so allow on the RM_STATIC_TO_OSPF route-map
if {$routername == "SOME_OTHER_HOSTNAME"} {
if {[catch {cli_exec $cli_fd(fd) "route-map RM_STATIC_TO_OSPF permit 10"} result]} {error $result $errorInfo}
}

# write to system's local logging buffer
action_syslog msg "****************************************************************************************************"
action_syslog msg "********************** Important Message Regarding SOME ROUTES Routes ***********************************"
action_syslog msg "****************************************************************************************************"
action_syslog msg "* $routername EEM Message - Uptime is $uptime minutes and the boot window is $bootwindow minutes"
action_syslog msg "* $routername EEM Message - Uptime is > than the boot window - This is not a cold start"
action_syslog msg "* $routername EEM Message - The SOME ROUTES connection has been re-established"
action_syslog msg "* $routername EEM Message - The redistribution of SOME ROUTES routes has been enabled on $routername"
action_syslog msg "****************************************************************************************************"
action_syslog msg "****************************************************************************************************"
action_snmp_trap

# close CLI
if {[catch {cli_close $cli_fd(fd) $cli_fd(tty_id)} result]} {error $result $errorInfo}
}
}
}

# The Router / Switch has undergone a "COLD START". Execute and ENABLE the SOME ROUTES route redistribution.
} elseif {$uptime <= $bootwindow} {

# open CLI and execute
if {[catch {cli_open} result]} {error $result $errorInfo} else {array set cli_fd $result}
if {[catch {cli_exec $cli_fd(fd) "enable"} result]} {error $result $errorInfo}
if {[catch {cli_exec $cli_fd(fd) "configure terminal"} result]} {error $result $errorInfo}
if {[catch {cli_exec $cli_fd(fd) "router bgp 65230"} result]} {error $result $errorInfo}

# XXX run BGP so allow on the RM_STATIC_TO_BGP route-map
if {$routername == "SOME_HOSTNAME"} {
if {[catch {cli_exec $cli_fd(fd) "route-map RM_STATIC_TO_BGP permit 10"} result]} {error $result $errorInfo}
}
# XXX run OSPF so allow on the RM_STATIC_TO_OSPF route-map
if {$routername == "SOME_OTHER_HOSTNAME"} {
if {[catch {cli_exec $cli_fd(fd) "route-map RM_STATIC_TO_OSPF permit 10"} result]} {error $result $errorInfo}
}

# write to system's local logging buffer
action_syslog msg "****************************************************************************************************"
action_syslog msg "********************** Important Message Regarding SOME ROUTES Routes ***********************************"
action_syslog msg "****************************************************************************************************"
action_syslog msg "* $routername EEM Message - Uptime is $uptime minutes and the boot window is $bootwindow minutes"
action_syslog msg "* $routername EEM Message - Uptime is >= than the boot window - This is not a cold start"
action_syslog msg "* $routername EEM Message - SOME ROUTES router / DCI Switch has experienced a cold start"
action_syslog msg "* $routername EEM Message - The redistribution of SOME ROUTES routes has been enabled on $routername"
action_syslog msg "****************************************************************************************************"
action_syslog msg "****************************************************************************************************"
action_snmp_trap

}

# clear up all decalred variables
unset routername
unset arr_einfo
unset bootwindow
unset uptime
unset snmp_res
unset snmp_val
unset dvar1
unset dvar2
unset sys_int
unset sys_int_desc
unset sys_int_oper_stat  

Review Cisco Networking for a $25 gift card