Community discussions

MikroTik App
 
RackKing
Member
Member
Topic Author
Posts: 380
Joined: Wed Oct 09, 2013 1:59 pm

DHCP client script execution

Mon Dec 10, 2018 5:50 pm

I see the DHCP client can execute a script. I cannot seem to make the script execute - under what circumstances should this trigger? I assumed a manual release would trigger the script. Or any change in the DHCP client status - any thoughts? Thanks.
 
Redmor
Member Candidate
Member Candidate
Posts: 256
Joined: Wed May 31, 2017 7:40 pm
Location: Italy

Re: DHCP client script execution

Mon Dec 10, 2018 8:36 pm

I'll report what Wiki says:

Script that will be executed after lease is assigned or de-assigned. Internal "global" variables that can be used in the script:
leaseBound - set to "1" if bound, otherwise set to "0"
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address

Script is triggered everytime a lease is bound, offered, busy, unbound etc.
You can use leaseBound variable to make script do something when a client correctly gets an IP from DHCP and when he lose it.
For example I made a script that, when a client is bound, it takes IP, checks in neighbor if the client is MK and if yes it adds a dynamic dst-nat rule to connect to, with client MAC address as comment.
When the lease is released, the script disable that dynamic NAT, adding in the comment date and time.

With this script I can install N hAP and I don't need to NAT them.
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1782
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: DHCP client script execution

Mon Dec 10, 2018 8:59 pm

(red)
Last edited by sebastia on Mon Dec 10, 2018 11:59 pm, edited 2 times in total.
 
RackKing
Member
Member
Topic Author
Posts: 380
Joined: Wed Oct 09, 2013 1:59 pm

Re: DHCP client script execution

Mon Dec 10, 2018 10:43 pm

I'll report what Wiki says:

Script that will be executed after lease is assigned or de-assigned. Internal "global" variables that can be used in the script:
leaseBound - set to "1" if bound, otherwise set to "0"
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address

Script is triggered everytime a lease is bound, offered, busy, unbound etc.
You can use leaseBound variable to make script do something when a client correctly gets an IP from DHCP and when he lose it.
For example I made a script that, when a client is bound, it takes IP, checks in neighbor if the client is MK and if yes it adds a dynamic dst-nat rule to connect to, with client MAC address as comment.
When the lease is released, the script disable that dynamic NAT, adding in the comment date and time.

With this script I can install N hAP and I don't need to NAT them.
Thanks for this.
does this script run automatically at startup?

I'm having some trouble getting this to work on a hAP ac2. I will add the variable and see if I get a different result.

Thank you for your help.
 
RackKing
Member
Member
Topic Author
Posts: 380
Joined: Wed Oct 09, 2013 1:59 pm

Re: DHCP client script execution

Tue Dec 11, 2018 2:14 am

I'll report what Wiki says:

Script that will be executed after lease is assigned or de-assigned. Internal "global" variables that can be used in the script:
leaseBound - set to "1" if bound, otherwise set to "0"
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address

Script is triggered everytime a lease is bound, offered, busy, unbound etc.
You can use leaseBound variable to make script do something when a client correctly gets an IP from DHCP and when he lose it.
For example I made a script that, when a client is bound, it takes IP, checks in neighbor if the client is MK and if yes it adds a dynamic dst-nat rule to connect to, with client MAC address as comment.
When the lease is released, the script disable that dynamic NAT, adding in the comment date and time.

With this script I can install N hAP and I don't need to NAT them.
Is there any way to see these values via CLI in the terminal windows to get there current status?
 
Redmor
Member Candidate
Member Candidate
Posts: 256
Joined: Wed May 31, 2017 7:40 pm
Location: Italy

Re: DHCP client script execution

Tue Dec 11, 2018 8:24 am

I'll report what Wiki says:

Script that will be executed after lease is assigned or de-assigned. Internal "global" variables that can be used in the script:
leaseBound - set to "1" if bound, otherwise set to "0"
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address

Script is triggered everytime a lease is bound, offered, busy, unbound etc.
You can use leaseBound variable to make script do something when a client correctly gets an IP from DHCP and when he lose it.
For example I made a script that, when a client is bound, it takes IP, checks in neighbor if the client is MK and if yes it adds a dynamic dst-nat rule to connect to, with client MAC address as comment.
When the lease is released, the script disable that dynamic NAT, adding in the comment date and time.

With this script I can install N hAP and I don't need to NAT them.
Is there any way to see these values via CLI in the terminal windows to get there current status?
I don't know, but I think not.
They're variable only for DHCP server, so maybe they don't have a global scope, they're like :local.
The script doesn't run on startup, but when a client makes DHCP requests, so yes, when you reboot it is ready to be triggered by a client.
 
vytuz
newbie
Posts: 30
Joined: Mon Jul 31, 2017 3:12 pm

Re: DHCP client script execution

Fri Feb 08, 2019 11:56 am

Why interface change status can't change dhcp client status? I have example, then I connect Mikrotik (which had ip dhcp received) to switch, witch has ip-spoofing enabled, Mikrotik sends dhcp request, not discover. In this situation ip-spoofing table do not add this ip. Manually connect to Mikrotik and press release or reboot router is not a good option. Disconnecting interface could make dhcp-client to start from dhcp-discover. Is it possible to make this with script for now and hope for routeros version with this option?
 
Michaelcrapse
newbie
Posts: 26
Joined: Wed Oct 25, 2017 9:57 pm

Re: DHCP client script execution

Thu Mar 26, 2020 5:49 am

Script is triggered everytime a lease is bound, offered, busy, unbound etc.
No it's not, i've tried it.. It's only triggered on a bound event

Who is online

Users browsing this forum: davordaco86, GoogleOther [Bot], jaclaz, Majestic-12 [Bot], markinhusxp, PLJ020 and 208 guests