06-20-2016 07:52 PM
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.
Solved! Go to Solution.
06-20-2016 09:34 PM
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-DHCPevent 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
06-20-2016 09:34 PM
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-DHCPevent 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
06-21-2016 06:16 PM
Thanks, that is exactly what I was looking for.
06-21-2016 06:41 PM
You're very welcome
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