cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1645
Views
0
Helpful
3
Replies

Failover DHCP script

Shawnw4401
Level 1
Level 1

I was wondering if there was a possible script, or configuration, to enable a switch to only do DHCP if the provided link goes down then disable DHCP if that link comes up.

For instance, if Gi1/0/1 reads "%LINK-3-UPDOWN: Interface FastEthernet1/0/48, changed state to down" then turn DHCP on; if Gi1/0/1 reads "%LINK-3-UPDOWN: Interface FastEthernet1/0/48, changed state to up" then turn DHCP off.

1 Accepted Solution

Accepted Solutions

Francesco Molino
VIP Alumni
VIP Alumni

Hi

There are multiple way to handle it by using EEM script.

Within eem you can use tracking interface or trigger eem with a syslog message. 

I will past a sample of eem after.

To activate dhcp through eem, there are 2 ways:

- service dhcp / no service dhcp ==> if you're using ip helper-address command, you can't use this solution as service dhcp impact dhcp server and relay feature.

- configure your dhcp pool through eem command.

Tracking interface :

track 1 interface FastEthernet1/0/48 line-protocol

event manager applet DOWN-DHCP

event track 1 state down

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 2.0 cli command "ip dhcp exclude x.x.x.x"

action 2.1 cli command "ip dhcp pool TEST"

action 2.1 cli command "Network x.x.x.x x.x.x.x"

action 2.1 cli command "default-rout x.x.x.x"

action 2.1 cli command "dns-server x.x.x.x"

action 3.0 cli command "end"

action 3.1 cli command "wr mem"

action 4.0 syslog priority alerts msg "F1/0/48 is down. DHCP server created"

event manager applet UP-DHCP

event track 1 state up

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 2.0 cli command "no ip dhcp exclude x.x.x.x"

action 2.1 cli command "no ip dhcp pool TEST"

action 3.0 cli command "end"

action 3.1 cli command "wr mem"

action 4.0 syslog priority alerts msg "F1/0/48 is up. DHCP server deleted"

with syslog event :

event manager applet DOWN-DHCP

event syslog pattern "Interface FastEthernet1/0/48, changed state to down"

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 2.0 cli command "ip dhcp exclude x.x.x.x"

action 2.1 cli command "ip dhcp pool TEST"

action 2.1 cli command "Network x.x.x.x x.x.x.x"

action 2.1 cli command "default-rout x.x.x.x"

action 2.1 cli command "dns-server x.x.x.x"

action 3.0 cli command "end"

action 3.1 cli command "wr mem"

action 4.0 syslog priority alerts msg "F1/0/48 is down. DHCP server created"


event manager applet UP-DHCP

event syslog pattern "Interface FastEthernet1/0/48, changed state to up"
action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 2.0 cli command "no ip dhcp exclude x.x.x.x"

action 2.1 cli command "no ip dhcp pool TEST"

action 3.0 cli command "end"

action 3.1 cli command "wr mem"

action 4.0 syslog priority alerts msg "F1/0/48 is up. DHCP server deleted"

You need to replace x.x.x.x by real IPs and you can change the dhcp pool name.

The solution I prefer is interface taking.

How this is clear.

Thanks 

PS: Please don't forget to rate and mark as correct answer if this solved your issue 


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

View solution in original post

3 Replies 3

Francesco Molino
VIP Alumni
VIP Alumni

Hi

There are multiple way to handle it by using EEM script.

Within eem you can use tracking interface or trigger eem with a syslog message. 

I will past a sample of eem after.

To activate dhcp through eem, there are 2 ways:

- service dhcp / no service dhcp ==> if you're using ip helper-address command, you can't use this solution as service dhcp impact dhcp server and relay feature.

- configure your dhcp pool through eem command.

Tracking interface :

track 1 interface FastEthernet1/0/48 line-protocol

event manager applet DOWN-DHCP

event track 1 state down

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 2.0 cli command "ip dhcp exclude x.x.x.x"

action 2.1 cli command "ip dhcp pool TEST"

action 2.1 cli command "Network x.x.x.x x.x.x.x"

action 2.1 cli command "default-rout x.x.x.x"

action 2.1 cli command "dns-server x.x.x.x"

action 3.0 cli command "end"

action 3.1 cli command "wr mem"

action 4.0 syslog priority alerts msg "F1/0/48 is down. DHCP server created"

event manager applet UP-DHCP

event track 1 state up

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 2.0 cli command "no ip dhcp exclude x.x.x.x"

action 2.1 cli command "no ip dhcp pool TEST"

action 3.0 cli command "end"

action 3.1 cli command "wr mem"

action 4.0 syslog priority alerts msg "F1/0/48 is up. DHCP server deleted"

with syslog event :

event manager applet DOWN-DHCP

event syslog pattern "Interface FastEthernet1/0/48, changed state to down"

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 2.0 cli command "ip dhcp exclude x.x.x.x"

action 2.1 cli command "ip dhcp pool TEST"

action 2.1 cli command "Network x.x.x.x x.x.x.x"

action 2.1 cli command "default-rout x.x.x.x"

action 2.1 cli command "dns-server x.x.x.x"

action 3.0 cli command "end"

action 3.1 cli command "wr mem"

action 4.0 syslog priority alerts msg "F1/0/48 is down. DHCP server created"


event manager applet UP-DHCP

event syslog pattern "Interface FastEthernet1/0/48, changed state to up"
action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 2.0 cli command "no ip dhcp exclude x.x.x.x"

action 2.1 cli command "no ip dhcp pool TEST"

action 3.0 cli command "end"

action 3.1 cli command "wr mem"

action 4.0 syslog priority alerts msg "F1/0/48 is up. DHCP server deleted"

You need to replace x.x.x.x by real IPs and you can change the dhcp pool name.

The solution I prefer is interface taking.

How this is clear.

Thanks 

PS: Please don't forget to rate and mark as correct answer if this solved your issue 


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Thanks, that is exactly what I was looking for. 

You're very welcome 


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question