Help needed how to renew DHCP every 25 or 20minutes

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Author Message
AirFart
DD-WRT User


Joined: 06 Mar 2008
Posts: 92
Location: South East Asia

PostPosted: Thu Sep 04, 2008 8:43    Post subject: Help needed how to renew DHCP every 25 or 20minutes Reply with quote
Hi i got some problem here. My router connected to my ISP through wifi connection. Lease time is 30minutes. But the problem is after 30minutes it takes time to update the ip lease time. so after 3ominutes i always get disconnected then after 1-2minutes connection will be ok again.

how do i write a custom script so that it auto DHCP re-new every 20 or 25minutes so that i wont get disconnected after 3omin.

My Spec:
Buffalo WHR-G54S
Repeater mode
V24 SP1 final

currently using this script. but no luck so far :(

Code:
INTERVAL=10
PACKETS=1
UDHCPC="udhcpc -i eth1 -p /var/run/udhcpc.pid -s /tmp/udhcpc"
IFACE=eth1


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
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 Renewing IP address: $IFACE
      $UDHCPC
      echo Waiting 10 s ...
      sleep 10
   else
      echo Network is up via $TARGET
   fi
done

_________________
1xWAP54G : Bricked
1xWHR-G54S : Repeater @ 251mW (2.2km link)DD-WRT Installation Guide
1xRT-N12 : Repeater Bridge (15962)
1xRT-N16 : Router + Optware (TomatoUSB DualWAN)
1xEOC-2611P : Bricked (RMA)
1xWHR-HP-GN : WDS AP @ 23dBm (15962)
2xWHR-HP-G300N : WDS Station @ 21-28dBm (15962)
1xTL-WA5110G : AP @ 26dBm (Stock)
|Free WiFi for all|
Sponsor
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Sep 04, 2008 8:59    Post subject: Reply with quote
Do try
Code:

stopservice wan
startservice wan


My Copperjet 816-2P runs in ZipB-mode (Alcatel calls it DHCP-spoof) and gives its WAN-IP to a local host.
Somehow it doesn't work after a restart of the modem, so I wrote a cronjob to check my Internet acces and if it fails, it will login to the modem using telnet and reconfigure my modem.

My scripting improved in the mean time, but it still works:


Code:
# cat /tmp/custom.sh
#!/bin/sh
pingip=66.249.93.99
result=`ping -c 1 172.19.3.1 | grep -c from`
if [ $result == 0 ]; then
 logger -t 'ModemCheck' 'No modem.. restart WAN'
 echo 'No modem.. restart WAN' | tee -a /jffs/zipB.log
 stopservice wan
 startservice wan
else
 if [ ! -f /tmp/fail_count ]; then
  echo "" >/tmp/fail_count
 fi
 result=`grep -c x /tmp/fail_count`
 if [ $result -ge 3 ]; then
   date >>/jffs/zipB.log
   echo "tried $result times" | tee -a /jffs/zipB.log
   logger -t 'ModemCheck' 'After $result tries the modem is not functioning... will reboot'
   (sleep 1; echo -e "admin\r"; sleep 1; echo -e "admin\r"; sleep 1; echo -e "system restart\r") | telnet 172.19.3.1
   echo "" > /tmp/fail_count
 else
  result=`ping -c 1 $pingip | grep -c from`
  if [ $result == 0 ]; then
   date >>/jffs/zipB.log
   echo "rewriting zipB.." | tee -a /jffs/zipB.log
   echo "x" >>/tmp/fail_count
   logger -t 'ModemCheck' 'Modem not functioning... rewrite ZipB'
   (sleep 1; echo -e "admin\r"; sleep 1; echo -e "admin\r"; sleep 1; echo -e "zipb set public device WAN\r"; sleep 1; echo -e "user logout\r") | telnet 172.19.3.1
   stopservice wan
   startservice wan
  else
   echo "Modem alright"
   logger -t 'ModemCheck' 'Modem alright'
   echo -n "" > /tmp/fail_count
  fi
 fi
fi

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Sep 04, 2008 9:12    Post subject: Reply with quote
A solution for your problem can be as simple as this:

In Administration -> management
enable cron
* * * * * root /tmp/custom.sh

In Administration -> Commands
paste the following and press "Save Custom Script"

Code:
#!/bin/sh
pingip=66.249.93.99
result=`ping -c 1 $pingip | grep -c from`
if [ $result == 0 ]; then
 date >>/jffs/zipB.log
 echo "$pingip not reachable.. DHCP renew" | tee -a /jffs/dhcp.log
 stopservice wan
 startservice wan
fi

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
Display posts from previous:    Page 1 of 1
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