Help with a script to renew DHCP when connection disconnects

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Sun Nov 26, 2017 3:46    Post subject: Help with a script to renew DHCP when connection disconnects Reply with quote
Hello!

I've been having some random (not random see next page) connection disconnects for a while and now it's getting pretty irritating. I disconnect randomly 1-3 times a day and every time i have to go to my router's WAN page and click DHCP Renew and boom connection is backup as soon as i press it.

Is there a setting/script that can do this automatically with little downtime as possible?

I found this in the wiki but not sure if this is fine just as it is? or would i need to edit something?

Code:
#!/bin/sh
INTERVAL=10
PACKETS=1
UDHCPC="udhcpc -i vlan1 -p /var/run/udhcpc.pid -s /tmp/udhcpc"
IFACE=vlan1


ME=`basename $0`
RUNNING=`ps | awk '/'"$ME"'/ {++x}; END {print x+0}'`
if [ "$RUNNING" -gt 3 ]; then
   echo "Another instance of \"$ME\" is running"
   exit 1
fi

while sleep $INTERVAL
do
   TARGET=`ip route | awk '/default via/ {print $3}'`
   RET=`ping -c $PACKETS $TARGET 2> /dev/null | awk '/packets received/ {print $4}'`

   if [ "$RET" -ne "$PACKETS" ]; then
      echo "Ping failed, releasing IP address on $IFACE"
   #send a RELEASE signal
      kill -USR2 `cat /var/run/udhcpc.pid` 2> /dev/null
   #ensure udhcpc is not running
      killall udhcpc 2> /dev/null
      echo "Renewing IP address: $IFACE"
      $UDHCPC
      echo "Waiting 10 s..."
      sleep 10
   else
      echo "Network is up via $TARGET"
   fi
done



Edit: i went ahead and ran the script (dunno if i did it right) and rebooted, resulted in no given wan ip(0.0.0.0) so i had no internet, i should note i'm using my router to connect to a wifi hotspot (wireless client mode)
no modem is being used.
Would love some help editing the original script to work on my router.
here are some maybe useful commands.

Quote:
ps -w | grep udhcpc
14281 root 1200 S udhcpc -i eth2 -p /var/run/udhcpc.pid -s /tmp/udhcpc -O routes -O msstaticroutes -O staticroutes
15132 root 1204 S grep udhcpc


Quote:
iptables -vnL INPUT
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
1357 115K logaccept 0 -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 logaccept udp -- eth2 * 0.0.0.0/0 0.0.0.0/0 udp spt:67 dpt:68
0 0 logdrop udp -- eth2 * 0.0.0.0/0 0.0.0.0/0 udp dpt:520
0 0 logdrop udp -- br0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:520
0 0 logaccept udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:520
0 0 logaccept icmp -- eth2 * 0.0.0.0/0 0.0.0.0/0
27 864 logaccept 2 -- * * 0.0.0.0/0 0.0.0.0/0
0 0 logaccept tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:113
2 136 ACCEPT 0 -- lo * 0.0.0.0/0 0.0.0.0/0 state NEW
301 20774 logaccept 0 -- br0 * 0.0.0.0/0 0.0.0.0/0 state NEW
120 10757 logdrop 0 -- * * 0.0.0.0/0 0.0.0.0/0


Firmware: DD-WRT v3.0-r30949 big (12/15/16


Last edited by t0t0fe0 on Sat Apr 21, 2018 22:12; edited 4 times in total
Sponsor
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Wed Nov 29, 2017 22:09    Post subject: Reply with quote
Bumparoo
_________________
Asus RT-N66U

Firmware: DD-WRT v3.0-r33492 big (10/10/17)
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Thu Nov 30, 2017 2:30    Post subject: Reply with quote
jxm wrote:
Would be more inclined to upate the firmware to the latest release and see if that fixes the disconnect problem. New Broadcom drivers have been added since your firmware was released.


I'll give that a go, thanks.

just always assumed it wasn't a firmware issue, had the same problem with a tomato firmware, but worse! and an older dd-wrt version if i remember correctly.

edit: updated to DD-WRT v3.0-r33492 big (10/10/17)

will report back if it still happens.

_________________
Asus RT-N66U

Firmware: DD-WRT v3.0-r33492 big (10/10/17)
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Fri Dec 01, 2017 3:15    Post subject: Reply with quote
And...it happened again Sad

if this helps this is what syslog showed at the time of disconnect, again Renewing dhcp insta-fixed it.

Code:
Nov 30 03:10:03 DD-WRT user.warn igmpproxy[1826]: The origin for route 239.255.255.250 changed from 192.168.10.107 to 192.168.10.244
Nov 30 03:15:53 DD-WRT user.warn igmpproxy[1826]: The origin for route 239.255.255.250 changed from 192.168.10.244 to 192.168.10.197
Nov 30 03:28:35 DD-WRT user.warn igmpproxy[1826]: The origin for route 239.255.255.250 changed from 192.168.10.197 to 192.168.10.196
Nov 30 04:59:06 DD-WRT user.debug : ttraff: data for 29-11-2017 commited to nvram
Nov 30 21:46:32 DD-WRT user.warn igmpproxy[1826]: The origin for route 239.255.255.250 changed from 192.168.10.196 to 192.168.10.166
Dec 1 03:11:50 DD-WRT user.warn igmpproxy[1826]: select() failure; Errno(4): Interrupted system call
Dec 1 03:12:00 DD-WRT user.info : Maybe igmprt had died, we need to re-exec it
Dec 1 03:12:00 DD-WRT user.info : igmprt : multicast daemon successfully started

_________________
Asus RT-N66U

Firmware: DD-WRT v3.0-r33492 big (10/10/17)
mac913
DD-WRT Guru


Joined: 02 May 2008
Posts: 1848
Location: Canada

PostPosted: Fri Dec 01, 2017 4:25    Post subject: Reply with quote
I use these commands to renew WAN IP....

killall -SIGUSR2 udhcpc # Release WAN IP
killall -SIGUSR1 udhcpc # Renew WAN IP

_________________
Home Network on Telus 1Gb PureFibre - 10GbE Copper Backbone
2x R7800 - Gateway & WiFi & 3xWireGuard - DDWRT r53562 Std k4.9

Off Site 1

R7000 - Gateway & WiFi & WireGuard - DDWRT r54517 Std
E3000 - Station Bridge - DDWRT r49626 Mega K4.4

Off Site 2

R7000 - Gateway & WiFi - DDWRT r54517 Std
E2000 - Wired ISP IPTV PVR Blocker - DDWRT r35531


YAMon 3.4.6 | DNSCrypt-Proxy V2
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Fri Dec 01, 2017 5:44    Post subject: Reply with quote
mac913 wrote:
I use these commands to renew WAN IP....

killall -SIGUSR2 udhcpc # Release WAN IP
killall -SIGUSR1 udhcpc # Renew WAN IP


Isn't that the same thing i'm doing to manually renew DHCP in the web-gui?

I'm looking to edit the above script that supposedly does it automatically when i lose connection.

_________________
Asus RT-N66U

Firmware: DD-WRT v3.0-r33492 big (10/10/17)
mac913
DD-WRT Guru


Joined: 02 May 2008
Posts: 1848
Location: Canada

PostPosted: Fri Dec 01, 2017 6:04    Post subject: Reply with quote
Just adding to your thread...

I've had issues to with the WAN IP not renewing or updating if the modem was reset by the ISP because of maintenance and I found these commands to work.

I use a Con Job to run this script every 5min....

Code:

#!/bin/sh
PACKETS=1 # Check for Packet Reveived
HOST1='8.8.4.4' # Ping this Server
TARGET=`ip route | awk '/default via/ {print $3}'`
# ---CHECK WAN---
 if [ "$TARGET" = "0.0.0.0" ]; then
  logger "WAN has a GW IP $TARGET, Resetting WAN."
  killall -SIGUSR2 udhcpc   # Release WAN IP
  sleep 5
  killall -SIGUSR1 udhcpc   # Renew WAN IP
  exit 0
 fi
 if [ "$TARGET" = "" ]; then
  logger "WAN has a Blank GW IP, Resetting WAN."
  killall -SIGUSR2 udhcpc   # Release WAN IP
  sleep 5
  killall -SIGUSR1 udhcpc   # Renew WAN IP
  exit 0
 fi
 RET1=`ping -I vlan2 -c $PACKETS $HOST1 2> /dev/null | awk '/packets received/ {print $4}'`
 sleep 2
 if [ "$RET1" != "$PACKETS" ]; then
  logger "Ping Failed, Resetting WAN."
  killall -SIGUSR2 udhcpc   # Release WAN IP
  sleep 5
  killall -SIGUSR1 udhcpc   # Renew WAN IP
  exit 0
 fi
exit 0

_________________
Home Network on Telus 1Gb PureFibre - 10GbE Copper Backbone
2x R7800 - Gateway & WiFi & 3xWireGuard - DDWRT r53562 Std k4.9

Off Site 1

R7000 - Gateway & WiFi & WireGuard - DDWRT r54517 Std
E3000 - Station Bridge - DDWRT r49626 Mega K4.4

Off Site 2

R7000 - Gateway & WiFi - DDWRT r54517 Std
E2000 - Wired ISP IPTV PVR Blocker - DDWRT r35531


YAMon 3.4.6 | DNSCrypt-Proxy V2
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Fri Dec 01, 2017 7:35    Post subject: Reply with quote
mac913 wrote:
Just adding to your thread...

I've had issues to with the WAN IP not renewing or updating if the modem was reset by the ISP because of maintenance and I found these commands to work.

I use a Con Job to run this script every 5min....

[/code]


Question though, does this ping (8.8.4.4) every 5 minutes to check if my connection is down? so if my connection drops a minute after the check i have to wait ~4 minutes for it to renew it?
I'm Looking for something to constantly(reasonably) ping so i have the least amount of downtime possible.


thanks for the help!

_________________
Asus RT-N66U

Firmware: DD-WRT v3.0-r33492 big (10/10/17)
mac913
DD-WRT Guru


Joined: 02 May 2008
Posts: 1848
Location: Canada

PostPosted: Fri Dec 01, 2017 16:10    Post subject: Reply with quote
Yes, it's every 5 minutes. It's hasn't been an issue since I lose Internet sometimes within 5 days (worst case).
_________________
Home Network on Telus 1Gb PureFibre - 10GbE Copper Backbone
2x R7800 - Gateway & WiFi & 3xWireGuard - DDWRT r53562 Std k4.9

Off Site 1

R7000 - Gateway & WiFi & WireGuard - DDWRT r54517 Std
E3000 - Station Bridge - DDWRT r49626 Mega K4.4

Off Site 2

R7000 - Gateway & WiFi - DDWRT r54517 Std
E2000 - Wired ISP IPTV PVR Blocker - DDWRT r35531


YAMon 3.4.6 | DNSCrypt-Proxy V2
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Fri Dec 01, 2017 17:05    Post subject: Reply with quote
mac913 wrote:
Yes, it's every 5 minutes. It's hasn't been an issue since I lose Internet sometimes within 5 days (worst case).


I see, well damn.

I need a solution to renew it as soon as the connection drops so i don't get booted out of game.

_________________
Asus RT-N66U

Firmware: DD-WRT v3.0-r33492 big (10/10/17)
Quubee
DD-WRT Novice


Joined: 29 Aug 2017
Posts: 3

PostPosted: Sun Dec 03, 2017 16:13    Post subject: Reply with quote
t0t0fe0 wrote:
I need a solution to renew it as soon as the connection drops so i don't get booted out of game.


You can have cron run the script every second if you want. But then you need to have the script check that another instance of it isn't already running.
jjwatmyself
DD-WRT User


Joined: 19 Mar 2016
Posts: 55

PostPosted: Sun Dec 03, 2017 19:53    Post subject: Reply with quote
Do you have this issue if you connect the modem directly to a PC?
_________________
--------------------------------------------------
VLANs, port trunking, virtual SSID (Guest)
DNSmasq, NTP, syslog, nflow
Hub and spoke, multi-site, routed VPN (OpenVPN client), split tunnel
1 DNS zone per site, forward, reverse look-up across all sites

Asus RT-AC68U rev A2 DD-WRT v3.0-r48138 std (01/17/22)
Asus RT-AC68U rev C1 DD-WRT v3.0-r48138 std (01/17/22)
Asus RT-AC1900P DD-WRT v3.0-r48138 std (01/17/22)
Asus RT-AC1900P DD-WRT v3.0-r48138 std (01/17/22)
Netgear R7000 DD-WRT v3.0-r48138 std (01/17/22)
Linksys E2000 DD-WRT v3.0-r33492 mega (10/10/17)
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Mon Dec 04, 2017 0:48    Post subject: Reply with quote
jjwatmyself wrote:
Do you have this issue if you connect the modem directly to a PC?


I'm connected to an Xfinitywifi hotspot no modem being used, just the router and lan to pc.

Quubee wrote:

You can have cron run the script every second if you want. But then you need to have the script check that another instance of it isn't already running.


I have no clue how to do those would need some help Sad

_________________
Asus RT-N66U

Firmware: DD-WRT v3.0-r33492 big (10/10/17)
t0t0fe0
DD-WRT Novice


Joined: 26 Nov 2017
Posts: 17

PostPosted: Tue Dec 19, 2017 17:51    Post subject: Reply with quote
On a sidenote is there a way i can DHCP-Renew on a press of a button without having the dd-wrt page open? would still prefer some kind of script but i have no clue on how to run those properly.
_________________
Asus RT-N66U

Firmware: DD-WRT v3.0-r33492 big (10/10/17)
MDA400
DD-WRT User


Joined: 10 Jan 2015
Posts: 270
Location: Minnesota

PostPosted: Wed Dec 20, 2017 18:20    Post subject: Reply with quote
t0t0fe0 wrote:

I'm connected to an Xfinitywifi hotspot no modem being used, just the router and lan to pc.


How did you go about connecting your router to an xfinitywifi hotspot? by wifi repeater/ client bridge mode?

More generally, where are you that requires you to use the xfinitywifi hotspot and not a modem hooked up to the router for internet access?

t0t0fe0 wrote:

I need a solution to renew it as soon as the connection drops so i don't get booted out of game.


The xfinitywifi hotspots usually are timed access and you need to re-login every so often since anyone in public with a cable account can use them... This is probably the reason for your disconnection issue and is not an ideal way to get internet access.

_________________
LATEST DD-WRT FW IS LOCATED HERE: https://dd-wrt.com/support/other-downloads/?path=betas%2F
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum