Community discussions

MikroTik App
 
Piplfox
just joined
Topic Author
Posts: 13
Joined: Mon Nov 13, 2006 3:43 pm

Scrip for relase/renew IP DHCP Client

Fri Apr 20, 2012 10:42 am

Hi, I need a sript that will ping some Internet address or dns (let say 8.8.8.8 ) and if no replay for 5 min release WAN address and renew it. I have dynamic address on MT WAN from Internet provider cable modem. Is there any similar solution, cose sometimes Internet stops working and all I have to do is renew IP address on DHCP clinet on WAN interface.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Scrip for relase/renew IP DHCP Client

Fri Apr 20, 2012 7:22 pm

this script
:if ( [/ping 8.8.8.8 interface=wan count=6 ] = 0 ) do={/ip dhcp-client renew wan}

and scheduler for the script with interval 5 min
 
jandafields
Forum Guru
Forum Guru
Posts: 1515
Joined: Mon Sep 19, 2005 6:12 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 21, 2012 4:51 am

Hi, I need a sript that will ping some Internet address or dns (let say 8.8.8.8 ) and if no replay for 5 min release WAN address and renew it. I have dynamic address on MT WAN from Internet provider cable modem. Is there any similar solution, cose sometimes Internet stops working and all I have to do is renew IP address on DHCP clinet on WAN interface.
Make the script disable and then enable the interface. That should cause it to renew the DHCP.
 
Piplfox
just joined
Topic Author
Posts: 13
Joined: Mon Nov 13, 2006 3:43 pm

Re: Scrip for relase/renew IP DHCP Client

Thu May 03, 2012 9:57 am

this script
:if ( [/ping 8.8.8.8 interface=wan count=6 ] = 0 ) do={/ip dhcp-client renew wan}

and scheduler for the script with interval 5 min
Thanks mate this work like a charm.
 
givemesam
Frequent Visitor
Frequent Visitor
Posts: 50
Joined: Sun Jan 09, 2011 11:49 am

Re: Scrip for relase/renew IP DHCP Client

Tue Jun 05, 2012 3:01 am

Hi!

this is what i am looking for but i am a noob for scripting.

it would be great if someone could make this a bit clearer for me.

I need a script that will renew the dhcp client on ether1-gateway (i assume 'wan' was a label) if it can not ping out to 8.8.8.8 x times in 15 seconds.

Ideally you can give me instructions on how to do this via winbox, box by box.

Thank you

Sam

ps. disable / enable will work too

pps. i tried doing it with the script above, chaning the label and the the times, but the script would run every 15 seconds regardless, and it was not doing what i wanted. I assume you have to paste the script into the scheduler.

Is there a way to make this so it is triggered? and not run every 15 seconds? (dont know what is the best way to accomplish this task. Actual problem is that if the parent DHCP server is reset, MT doesnt get renewal due to elapsed boot time of dhcp server. so i need to have something that will do a kind of health check)
 
faustomorales
just joined
Posts: 1
Joined: Wed Mar 02, 2011 2:54 am

Re: Scrip for relase/renew IP DHCP Client

Wed Oct 10, 2012 9:21 am

Upgrade your routerOs to 5.10 or higher to fix this bug.

What's new in 5.10 (2011-Dec-09 11:49):

*) snmp - provide extended interface statistics when availabe;
*) dhcpv6 client - use link-scoped multicast address;
*) dhcp client - renew dhcp lease on ethernet link up event;
*) ipv6 gre tunnel added (/interface gre6) supports ip and ipv6 encapsulation;
*) ip gre tunnel supports ipv6 encapsulation;
*) allow setting bigger trafflow cache;
*) improved RB1200 stability when using ether9,ether10;
*) fixed RB1200 stability issues when using crypto hardware acceleration;
 
ddrazen
just joined
Posts: 1
Joined: Mon May 05, 2014 6:33 pm

Re: Scrip for relase/renew IP DHCP Client

Wed May 07, 2014 1:47 pm

I'm connected to free hotspot.I need to accept EULA to surf, but when 30 min pass I need to release wan to connect again and accept Eula again.I can only ping 1.1.1.1 after accepting eula in browser.Renew wan doesn't work.I tried this script with removing renew and put release but it didn't work,I must mannualy click release to again connect and accept eula.What kind of script would help with this?
I have routerboard 411r with 6.7 ROS.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scrip for relase/renew IP DHCP Client

Sun May 11, 2014 3:31 am

It's a free hotspot, do not abuse the service :o
 
plisken
Forum Guru
Forum Guru
Posts: 2509
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Scrip for relase/renew IP DHCP Client

Tue May 13, 2014 11:31 am

Is that the fully script?

this script
:if ( [/ping 8.8.8.8 interface=wan count=6 ] = 0 ) do={/ip dhcp-client renew wan}

and scheduler for the script with interval 5 min
Thanks mate this work like a charm.
 
dangucci
just joined
Posts: 18
Joined: Sun Aug 31, 2014 10:30 pm

Re: Scrip for relase/renew IP DHCP Client

Sun Aug 31, 2014 10:47 pm

Hi guys, I would like to know how to make a script to check if ppp-out1 interfaces's ip falls in an ip range which is, the first octet
must be 10, second octet 43 , third octet greater than 128 .. eg 10.43.129.23

If ip addres of ppp-out1 falls within the range then

script should exit

but if ip addres of ppp-out1 doesnt fall within the range then script should execute the command

interface ppp-client disable ppp-out1
interface ppp-client enable ppp-out1

this would be on a scheduled task to be run every 10 seconds

Thank you so much for all your help!!!!!
 
User avatar
JHOELIT
just joined
Posts: 12
Joined: Sun Sep 03, 2017 1:12 pm
Location: Perú
Contact:

Re: Scrip for relase/renew IP DHCP Client

Mon Dec 04, 2017 5:22 am

I share these useful examples

/ ip dhcp-client release 0
/ ip dhcp-client release [find interface =ether1]

It is valid for (release) or (renew)

God bless you
 
jos7890106
just joined
Posts: 2
Joined: Wed Jun 06, 2018 9:43 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Jun 09, 2018 8:58 am

try with the previous script but it gives me an error I think, try to modify it to my settings but it just gave another error. I need help, I am new and I do not know where to find the solution, if they could explain me. Thank you.

this is the error ke gives me now

[admin @ HTC Desire 626s]>: if ([/ ping ng 8.8.8.8 interface = wan count = 6] = 0) do = {/ ip dhcp-client renew wlan 1}
expected end of command (line 1 column 19)
[admin @ HTC Desire 626s] >>
[admin @ HTC Desire 626s] >>: if ([/ ping ng 8.8.8.8 interface = wlan 1 count = 6] = 0) do = {/ ip dhcp-client renew wlan 1}
expected end of command (line 1 column 19)
[admin @ HTC Desire 626s] >>: if ([/ ping ng 181.225.231.120 interface = wlan 1 count = 6] = 0) do = {/ ip dhcp-client renew wlan 1}
expected end of command (line 1 column 19)
[admin @ HTC Desire 626s] >>
 
Shestakov
just joined
Posts: 1
Joined: Fri Feb 08, 2019 11:50 am

Re: Scrip for relase/renew IP DHCP Client

Fri Feb 08, 2019 11:54 am

try without "ng"
 
dcavni
Member Candidate
Member Candidate
Posts: 108
Joined: Sun Mar 31, 2013 6:02 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 4:43 pm

this script
:if ( [/ping 8.8.8.8 interface=wan count=6 ] = 0 ) do={/ip dhcp-client renew wan}

and scheduler for the script with interval 5 min
Let me bring this old topic up a bit.

I have the same problem on one cable modem. If you restart the modem, Mikrotik doesn't let go of the WAN DHCP IP and the internet isn't working until you restart Mikrotik or use DHCP Release button. Where can i set this rule or something similar in Mikrotik, so that it tries to ping some IP and if no response it renews DHCP lease?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 4:53 pm

Simply schedule it on boot with interval of 5 min
 
dcavni
Member Candidate
Member Candidate
Posts: 108
Joined: Sun Mar 31, 2013 6:02 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 4:55 pm

Can you please give me a bit more detailed instruction where to put the script? I'm completly new at scripts. I also looked at netwatch, can this be used in any way?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 4:59 pm

What you can do, if you do not have experience, simply put 8.8.8.8 inside System / Watchdog / Watch Address
With default values, if 8.8.8.8 stop responding for more than 1 minute, the device reboot.
But after reboot, the OS wait 5 minutes before check again, and so on.
 
eldoncito2019
Member
Member
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 5:09 pm

Try this friend


:if condition=([/ping 1.1.1.1  count=6] =0) do={/ip dhcp-client release [ find interface ="ether1"]}

I hope it helps you



EL DONCITO.
 
dcavni
Member Candidate
Member Candidate
Posts: 108
Joined: Sun Mar 31, 2013 6:02 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 5:15 pm

Try this friend


:if condition=([/ping 1.1.1.1  count=6] =0) do={/ip dhcp-client release [ find interface ="ether1"]}

I hope it helps you



EL DONCITO.
Please only tell me, where should i put this script?
 
eldoncito2019
Member
Member
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 5:18 pm

In scheduler and give it a time of 10 seconds for the script to run.

"ether1" is your interface that receives internet, with what name do you have it?


EL DONCITO.
 
dcavni
Member Candidate
Member Candidate
Posts: 108
Joined: Sun Mar 31, 2013 6:02 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 5:20 pm

Ok, thank you very much for help. Will do it as soon as i get to computer.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 5:29 pm

Do it correctly, this do not need to specific the interface.
:if ([/ping 1.1.1.1 count=10] = 0) do={/ip dhcp-client release [find]}
Do not execute ping too often, or you risk to be putted sooner or later on blacklist...
 
dcavni
Member Candidate
Member Candidate
Posts: 108
Joined: Sun Mar 31, 2013 6:02 pm

Re: Scrip for relase/renew IP DHCP Client

Sat Apr 23, 2022 6:46 pm

Do it correctly, this do not need to specific the interface.
:if ([/ping 1.1.1.1 count=10] = 0) do={/ip dhcp-client release [find]}
Do not execute ping too often, or you risk to be putted sooner or later on blacklist...
Ok, now i set this:
:if ([/ping 1.1.1.1 count=5] = 0) do={/ip dhcp-client release [find]}
in system/schedule

admin@MikroTik] > /system/schedule print
Columns: NAME, START-DATE, START-TIME, INTERVAL
# NAME START-DATE START-TIME INTERVAL
0 DHCP Renew apr/23/2022 15:32:24 59m

i think count=5 should be enough and interval is 59 minutes.

Thank you all for help.

Who is online

Users browsing this forum: FoxWhite and 21 guests