Results 1 to 7 of 7

Thread: Automatic renew IP address

  1. #1
    Join Date
    Sep 2006
    Location
    Prishtina, Kosovo
    Posts
    56

    Automatic renew IP address

    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

    Code:
    #!/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

  2. #2
    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.

  3. #3
    Join Date
    Sep 2006
    Location
    Prishtina, Kosovo
    Posts
    56

    I was thinking about that as well

    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

  4. #4
    Join Date
    Mar 2005
    Location
    the hague
    Posts
    33
    Quote Originally Posted by GerardNL View Post
    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

  5. #5
    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?
    Last edited by AverySimonsen; 05-09-2007 at 11:54. Reason: typo

  6. #6
    Join Date
    Mar 2005
    Location
    the hague
    Posts
    33
    Quote Originally Posted by AverySimonsen View Post
    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.

  7. #7
    Quote Originally Posted by jaapjeuk View Post
    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.

Similar Threads

  1. Проблема с реконектом
    By scorpio in forum Russian Discussion - РУССКИЙ (RU)
    Replies: 14
    Last Post: 28-03-2007, 09:21
  2. filtering virtual server port with mac address
    By dwienie in forum WL-500g Q&A
    Replies: 0
    Last Post: 19-03-2006, 16:46
  3. FTP server op wl500g-dlx niet bereikbaar vanaf internet
    By Sawilla in forum Dutch Discussion - Nederlands
    Replies: 16
    Last Post: 19-12-2005, 09:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •