PDA

Bekijk de volledige versie : Automatic renew IP address



GerardNL
29-12-2006, 22:23
Due to irregular but daily powerfailures, I loose my routers IP number from time to time. The only way to get my internet to work again, is to "Reconnect" on the status page of the router. Not being there the whole time means that reguarly the downloads take a long unwanted pause.

What I have been looking for is a little program that will check every e.g. 10 minutes to see if I still ping the gateway of my ISP. If not, then renew the IP address. In windows, renewing the IP address is as simple as "ipconfig renew", but that doesn't work on our router.

Did some searching on the internet and see the ifup and ifdown commands, but those don't work.

Then I figured out that our beloved router uses udhcpc program. I've found this page about it: http://www.penguin-soft.com/penguin/man/8/udhcpc.html

Did some reading and testing, but when I do "udhcpc -i eth0", I get a few errors about missing scripts. So, not much luck yet.

With a bit of searching on the internet, I've found & partically created the script below. I don't know if other people have the same problem with loosing their IP address, then it might be good to include it in the "standard" KC build?

Can any of you help to improve this script and get it to work?

Many thanks in advance


#!/opt/bin/bash
DEST="addrres default gateway provider"

while [ : ]
do
if ping -q -w 2 -c 1 "$DEST" &>/dev/null # &> means both stdout+stderr
then # ping succeeded
then
flag="connected" # do nothing
fi
else # ping failed
result="$?" # to catch the return code if neede
then
reboot # Here should be a IP address renew instead of reboot
flag="disconnected" # if there is no power, then it will indicate as disconnected.
fi
fi
sleep 600 # sleep for 10 minutes
done

kfurge
31-12-2006, 03:17
Sending udhcpc a SIGUSR1 should cause it to renew the lease. Can you try the following line instead of reboot?

kill -USR1 `cat /var/run/udhcpc.pid`

You could even probably add that line as a regular cron job entry eliminating the need for the script altogether. I quickly tested it here without any ill effects.

- K.C.

GerardNL
31-12-2006, 08:17
Thanks for your reply!

I also found a command like the one you describe. I first found something with "-signal" in it and later on figured out to remove the "signal" bit.

A good idea to put the command in the cron instead. That makes a lot of sense. I realized later that the cron is great for this.

But if we just add "kill -USR1 `cat /var/run/udhcpc.pid`" to the cron, is n't the IP address renewed too many times? If the IP address is not lost, the connection is temporary interupted when the renew is attemted? At least that is the case with windows...

I will do some testing once we had a powercut (and I'm back)

GS

jaapjeuk
17-04-2007, 23:21
Thanks for your reply!

I also found a command like the one you describe. I first found something with "-signal" in it and later on figured out to remove the "signal" bit.

A good idea to put the command in the cron instead. That makes a lot of sense. I realized later that the cron is great for this.

But if we just add "kill -USR1 `cat /var/run/udhcpc.pid`" to the cron, is n't the IP address renewed too many times? If the IP address is not lost, the connection is temporary interupted when the renew is attemted? At least that is the case with windows...

I will do some testing once we had a powercut (and I'm back)

GS


Just force to get a new ip this way:
udhcpc -q -i eth1 -s /bin/true

AverySimonsen
05-09-2007, 11:53
I think I might be experiencing a similar problem. The 'Internet' light in my speedstream adsl modem turns off and my internet connection goes down (daily). The way I have been 'fixing' the problem is to reboot the modem which would then cause both adsl light, internet light and activity light to turn back on.

I have talked to my ISP support a number of times and today I finally caught somebody capable of giving straight answers. He said that the adsl light (which doesn't go off during connection failures) indicates the connection to my ISP is fine. The 'Internet' light however turns off when the users computer (in my case: the wl700) doesn't renew its ip address. The thing is that even though I have a fixed ip, my ISP specifies to still use DHCP to obtain it (not sure why).

I don't know that much about dhcp leases, so can anybody tell me if udhcp is at the root of my problem? Would I need to put in a command to renew my dhcp lease with my ISP in my crontab? Any negative effects to be expected from this?

jaapjeuk
12-09-2007, 19:13
I think I might be experiencing a similar problem. The 'Internet' light in my speedstream adsl modem turns off and my internet connection goes down (daily). The way I have been 'fixing' the problem is to reboot the modem which would then cause both adsl light, internet light and activity light to turn back on.

I have talked to my ISP support a number of times and today I finally caught somebody capable of giving straight answers. He said that the adsl light (which doesn't go off during connection failures) indicates the connection to my ISP is fine. The 'Internet' light however turns off when the users computer (in my case: the wl700) doesn't renew its ip address. The thing is that even though I have a fixed ip, my ISP specifies to still use DHCP to obtain it (not sure why).

I don't know that much about dhcp leases, so can anybody tell me if udhcp is at the root of my problem? Would I need to put in a command to renew my dhcp lease with my ISP in my crontab? Any negative effects to be expected from this?

a (u)DHCPC (client!!!) daemon/program must run at your router.
the obtained dynamic ip and leasetime is defined by your ISP's DHCP-SERVER, when the end-of that specific lease has been reached, than the ip will be refreshed, or a new one will be given, the new lease-time will be set.

AverySimonsen
14-09-2007, 13:37
a (u)DHCPC (client!!!) daemon/program must run at your router.
the obtained dynamic ip and leasetime is defined by your ISP's DHCP-SERVER, when the end-of that specific lease has been reached, than the ip will be refreshed, or a new one will be given, the new lease-time will be set.

Sure.. I figured as much out on my own, but that doesn't really shed any light on what is causing my problem. I have udhcpc running on my router, but still the problem occurs regularly.

Funny thing is that the problem rarely occurs, when there is lots of regular traffic (eg when I have torrents running). As soon as I have nothing generating traffic, the connection goes dead (not always, but almost always).

Does anyone know why an ISP would insist that I use DHCP to obtain my fixed (as in guaranteed not to change) IP (rather than just hard-code the fixed ip on my router)? I suspect it has to do with user friendliness, as in Joe Schmoe doesn't have to set up anything on his PC for it to go online when connected to the speedstream.