1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Reconnect Script ?

Discussion in 'Tomato Firmware' started by zorkmta, May 14, 2013.

  1. zorkmta

    zorkmta LI Guru Member

    Hi all,

    For some reason i have a RT.N66u behind of a Modem Thomson, so RT-N66U get automatically internet IP from modem (ex. 200.xx.xx.xx1) and it´s change every one or 2 days. So RT-N66U keeping al ip and can´t access to Internet. So i have to reconnect or reboot the router to get new ip assined by thomson.

    I used reboot schedule and reconnect schedule, but the sometime modems thomson give different ip in short time. So can´t access to internet again and have to enter to router and make it manually (rebooting or renewing) to get new ip assigned. :S

    Are there some scripts to monitor the router can´t ping or can access to internet, then automatically to make reboot o reconnect Wan ( release and renew ip). Can someone help me to solved it?
     
  2. philess

    philess Networkin' Nut Member

    That sounds a bit odd to me. How is your modem set up? Not in bridge mode i assume? Can you set it to?
    Or does it give out a IP by DHCP on the port where the router is connected to?
    There shouldnt be any need to reboot the router if the modem gets a new WAN ip.
    But maybe you are forced by your ISP to use this "weird" setup, i dont know. Could it help to reboot
    the modem instead of the router?

    Anyhow, theres a bunch of scripts that you can modify easily:
    http://www.linksysinfo.org/index.php?threads/custom-tomato-script.19525/#post-89529
    Or this one here executed by scheduler every x minutes:
    http://linksysinfo.org/index.php?th...r-command-or-custom-script.26441/#post-124046
    Scripts for various modems:
    http://www.paehl.de/reconnect/
     
    zorkmta likes this.
  3. Monk E. Boy

    Monk E. Boy Network Guru Member

    Try inserting the following line into Administration -> Scripts -> Firewall:

    Code:
    iptables -I INPUT -p udp --sport 67 --dport 68 -j ACCEPT
    Then reboot the device. See if your problem vanishes, like it does on AT&T UVerse.
     
    philess likes this.
  4. zorkmta

    zorkmta LI Guru Member

    Thanks for answering, this is very strange cuz I want to put I'm bridge mode but operator don't let me! I'm from south America with VDSL movistar and with iptv.
    So led getting ip from modem (Thomson) on LAN 3 and LAN 1 connected with tomato router (I think it give me ip of subnet 192.168.1.xx but not getting public internet ip (better for me and can use all services directly)

    The scripts of last one, monitor wan ip of router tomato all time? Testing


    Enviado desde Xperia Z
     
  5. Monk E. Boy

    Monk E. Boy Network Guru Member

    That command changes the INPUT table, which controls what types of packets are allowed to talk to services running on the router itself. It basically says that if a UDP packet is directed at the router (INPUT), from port 67 (sport) and directed at port 68 (dport), it will accept that packet.

    When your DHCP lease on the WAN connection reaches the 50% point (if, say, the lease is for 4 hours, the 50% point when 2 hours are left on the lease) the device and DHCP server (your Thompson router) are supposed to negotiate a longer lease, provided both are online and functioning.

    If this negotiation doesn't take place the device & DHCP server then wait for the end of the lease to negotiate a new lease, which is supposed to only take a few seconds. On some modem/router combinations (cough, 2Wire, cough) this process takes forever, and sometimes doesn't even complete at all. Until you have a valid lease on your WAN connection Tomato can't route packets to/from the internet, which is why it's a bit of a problem.

    To be honest I haven't had a UVerse connection since I had a WRT54GL and was running original Tomato, so I'm not sure if that rule is going to fix anything. It may have already been added to the default rules. Adding it twice (default + firewall script) won't break anything, and it's a good diagnostic step to see if that fixes your problem.

    Another alternative would be to perform a DHCP release & a DHCP renew from the Tomato overview page. Unless the ISP's router is spectacularly pants-on-head-on-fire stupid that should work, though it is annoying.
     
    zorkmta likes this.
  6. zorkmta

    zorkmta LI Guru Member

    The Fisrt script didn´t work. Once thomson change ip, tomato didn´t automatically release/renew Ip :

    iptables -I INPUT -p udp --sport 67 --dport 68 -j ACCEPT




    Now trying this one, testing
    I use something like this for my "init" script. administration->scripts->init


    #!/bin/sh
    # seconds between checks
    WATCHDOG_SLEEP_SEC=90
    # hostname or IP to ping
    WATCHDOG_SITE=somewhere.example.com

    while sleep $WATCHDOG_SLEEP_SEC
    do
    if ping -c 1 $WATCHDOG_SITE > /tmp/null
    then
    echo "$WATCHDOG_SITE ok"
    else
    logger "$WATCHDOG_SITE missed ping"
    sleep 4
    if ! ping -c 1 $WATCHDOG_SITE > /tmp/null
    then
    logger "$WATCHDOG_SITE down, refreshing DHCP"
    killall -SIGUSR2 udhcpc
    sleep 2
    killall -SIGUSR1 udhcpc
    fi
    fi
    done 2>&1 &
     
  7. Monk E. Boy

    Monk E. Boy Network Guru Member

    That sucks, that means the Thompson is doing something spectacularly wrong.

    I had a single-line script suitable for sticking in scheduler, under custom 1/2, that would basically check to see if the WAN's default gateway was available and if not do... something... to the WAN interface to bring it back online. I haven't needed it in forever, I'll see if it's lurking on a router someplace... I thought it was for sure on this one router, but apparently it got disabled and was removed completely during the last replacement/upgrade cycle.
     
  8. zorkmta

    zorkmta LI Guru Member

    A crazy Thomson tg789vn is totally a black box, can't do nothing or a few config on vdsl and iptv.

    So I'm trying to make think in router, both script didn't work on administration--scrip - - init. Today got disconnected from Thomson and I had to manually to released and renew ip on tomato webui and then work again and got new public 's ip. :(



    Enviado desde Xperia Z
     
  9. Monk E. Boy

    Monk E. Boy Network Guru Member

    I've completed my survey and it appears to have been lost. :(

    /sbin/dhcpc-release and /sbin/dhcpc-renew are called when you click on the buttons in the gui. Those could take the place of killall -SIGUSR2 udhcpc and killall -SIGUSR1 udhcpc.

    Instead of pinging some random internet site, you probably should ping the wan's gateway IP, which will respond much faster than some random site. I don't remember what the value is that you need to ping though.
     
  10. zorkmta

    zorkmta LI Guru Member

    i want to try it, i´m bit noob in scripts and linux. could you help how can i do it?


    /sbin/dhcpc-release and /sbin/dhcpc-renew are called when you click on the buttons in the gui. Those could take the place of killall -SIGUSR2 udhcpc and killall -SIGUSR1 udhcpc.





    After lurking a lot, i found this script for DDWRT, is it work on tomato?


    #!/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
     
  11. philess

    philess Networkin' Nut Member

    I am using this (modified now to only release & renew DHCP instead of reboot modem).

    Code:
    #!/bin/sh
     
    # which host to ping
    host=`nvram get wan_gateway`
    # can be replaced by whatever you want, example: host="8.8.8.8"
     
    # do not modify
    ping_attempt=0
     
    # send 1 ping packet, timeout 5 seconds, exit ping after maximum of 10 sec
    while ( ( /bin/ping -c 1 -W 5 -w 10 $host | grep -q '100% packet loss' ) && \
    [ $ping_attempt -lt '3' ] )
    do
    ping_attempt=`expr $ping_attempt + 1`
    # wait 1 sec before next try
    /bin/sleep 1
    done
    if [ $ping_attempt = 3 ] ; then
      # make syslog entry
      logger -p INFO -t CHECKWAN "Ping to $host has failed, release & re-newing DHCP lease."
      # Ping has failed 3 times. Release & renew DHCP
      /sbin/dhcpc-release
      sleep 5
      /sbin/dhcpc-renew
    fi
    It is based on a script that TexasFlood has posted here and i modified it slightly.
    Edit: Updated thanks to Monk. E Boy´s post right below.

    save it as .sh file, upload to router, run with scheduler (for example every 2 minutes).
    It will ping a host (GoogleDNS 8.8.4.4), if one ping failes, it tries 2 more times, if they fail too,
    it releases & renews the WAN DHCP lease. You can easily modify it to reboot the modem,
    or the router, or both. Whatever.
     
    QQQTJ and zorkmta like this.
  12. Monk E. Boy

    Monk E. Boy Network Guru Member

    I'd suggest pinging $(nvram get wan_gateway) since the WAN's gateway is a very local IP address and should respond much faster and with less tribulation than a distributed server like GoogleDNS. If the WAN's gateway doesn't respond, you know the WAN is down.
     
    QQQTJ, zorkmta and philess like this.
  13. philess

    philess Networkin' Nut Member

    Thats is true. I wanted to edit my post and add that. Personally i prefer pinging a "actual" IP on the internet
    instead of "just" the gateway, and if it fails i have the script reboot my cablemodem. I had it happen
    once that the gateway was responding but no actual internet connection was possible, then a reboot
    of the modem fixed it. But that may just have been a coincidence and it was a temporary routing issue
    on the side of my ISP. Anyhow, i prefer to ping GoogleDNS instead of the gateway.
     
    zorkmta likes this.
  14. zorkmta

    zorkmta LI Guru Member


    saved this scripts as wan1.sh, then uploaded to jffs

    On tools--- system----Execute System Commands

    sh /jffs/wan1.sh


    Executed, and give me this error


    /jffs/wan1.sh: line 9: syntax error: unexpected word (expecting "do")

    what shoul can fix?
     
  15. philess

    philess Networkin' Nut Member

    Make sure you have removed linebreaks caused by Windows copy&paste.
    For example use Notepad++ and select "Edit, EOL Conversion, UNIX" and save it again.
     
    Monk E. Boy, darkknight93 and zorkmta like this.
  16. zorkmta

    zorkmta LI Guru Member

    Thanks for all and help, now working very smooth, 2 days with automatically release and renew IP.


    May 23 14:06:53 Tomato daemon.info dnsmasq-dhcp[11566]: DHCPACK(br0) 80.80.1.10 38:60:77:bd:26:ae ANTEC-PC
    May 23 14:12:45 Tomato user.info CHECKWAN: Ping to 10.52.173.3 has failed, release & re-newing DHCP lease.
    May 23 14:12:54 Tomato user.debug dhcpc-event[28128]: 182: pptp peerdns disabled
    May 23 14:12:54 Tomato daemon.info dnsmasq[11566]: reading /etc/resolv.dnsmasq
    May 23 14:12:54 Tomato daemon.info dnsmasq[11566]: using nameserver 200.28.4.129#53
    May 23 14:12:54 Tomato daemon.info dnsmasq[11566]: using nameserver 200.28.4.130#53
    May 23 14:12:54 Tomato daemon.info dnsmasq[11566]: using nameserver 192.168.1.254#53
    May 23 14:12:54 Tomato user.debug init[1]: 182: pptp peerdns disabled
    May 23 14:12:54 Tomato daemon.info dnsmasq[11566]: exiting on receipt of SIGTERM
    May 23 14:12:54 Tomato daemon.info dnsmasq[28131]: started, version 2.67test3CS cachesize 1500
    May 23 14:12:54 Tomato daemon.info dnsmasq[28131]: compile time options: IPv6 GNU-getopt no-RTC no-DBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset Tomato-helper auth
    May 23 14:12:54 Tomato daemon.info dnsmasq[28131]: asynchronous logging enabled, queue limit is 5 messages
    May 23 14:12:54 Tomato daemon.info dnsmasq-dhcp[28131]: DHCP, IP range 80.80.1.2 -- 80.80.1.51, lease time 1d

    Thanks Again!!!
    :)
     
    QQQTJ, philess and Monk E. Boy like this.
  17. Monk E. Boy

    Monk E. Boy Network Guru Member

  18. jbcdidgosir

    jbcdidgosir Serious Server Member

    I'm in China and the operator was also refuse to give me the super admin password. I threated and forced the operator and make him believe that I'm expert in network. At last, he had no choice and called telecom and gave me the super admin password. ^_^

    Your modem must be in bridge mode. Otherwise it'll be much trouble. Because your router couldn't get an Internet IP. Just a local IP assigned by DHCP of Modem. So of course reconnect in script doesn't work at all. Also your router couldn't be a server, such as VPN server, web server, proxy server...

    Also you can get this super admin password by some other ways. Please google. Or provide your modem's type. Maybe I can help you to serach if any solution in Chinese web sites.
     
    QQQTJ likes this.

Share This Page