What's new

WAN connect and disconnect using script

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

@RMerlin
there is a faster method for renew wan ip other than 'service restart_wan'?
thanks

I don't know what you expect here... Running that command over SSH takes about 5 seconds, including the login time.
 
@RMerlin
it's not the command launch and the login, that's is automated.
is the service wan stop and start that take a few seconds itself.
I just wanted to know if there is a command to make faster renew of wan ip.
 
@merlin

Thank you for the great firmware, it solved already some problems for me. Having the need to reset my internet connection daily i wonder if there is another way than reboot the router via script...

Is there any chance to reset WAN as well if it is connected via USB key Modem?

Beside that, is there a list for <action_service> for the service command?

Thanx
teefix
 
@RMerlin
it's not the command launch and the login, that's is automated.
is the service wan stop and start that take a few seconds itself.
I just wanted to know if there is a command to make faster renew of wan ip.

No, this is the most direct method of restarting your WAN interface. You are bound to the time it takes your ISP to issue a new DHCP lease, and then you have to reconfigure every services that rely on that WAN IP (such as the firewall rules).
 
@merlin

Thank you for the great firmware, it solved already some problems for me. Having the need to reset my internet connection daily i wonder if there is another way than reboot the router via script...

Is there any chance to reset WAN as well if it is connected via USB key Modem?

Beside that, is there a list for <action_service> for the service command?

Thanx
teefix

There's no list, as those are internal commands intended for internal use by the firmware. They can change at any time in a future update.

restart_wan should in theory restart all WAN interfaces, but I have no way of testing it, as I don't have any USB modem.
 
Hi all, checked and didn't work properly. WAN interface was probably restarted, but on my AC56U internet connection via USB Dongle did not automatically reconnect. Had to reset the router...
 
Same with me. Wan reset dosent work.

Best command to reconnect the USB-Dongel is
killall -SIGUSR2 udhcpc
 
Unfortunately doesn't work
ImageUploadedByTapatalk1432577169.409928.jpg
 
this script work for me often

#!/bin/sh
if ping -w 10 -c 1 212.247.8.38 > /dev/null; then
echo "SERVERNAME=on"
else
echo "SERVERNAME=off"
killall -SIGUSR2 udhcpc
fi

You must connect with internet therefore killall will work.

I will the command testing with telnet and see what will report me.

at weekend
 
Here is short tutorial how to create Reboot script on ASUS WRT MERLIN routers (everything in one place, for linux newbies like me)

prerequisite:
Advanced Settings - Administration - System
Persistent JFFS2 partition
Enable JFFS partition: Yes
Format JFFS partition at next boot: No
Enable JFFS custom scripts and configs: Yes

APPLY

1. telnet or SSH to your router
2. cd /
3. cd /jffs/scripts
4. vi init-start
5. press INSERT
6. paste this code
Code:
#!/bin/sh
cru a ScheduledReboot "0 4 * * * /sbin/reboot"
7. press ESCAPE
8. type ":wq" (write quit)
9. paste this code (set scripts as executable)
Code:
chmod a+rx /jffs/scripts/*
10. reboot


if you want WAN Reconnect script, but not reboot, just change step 6 with this code:
Code:
#!/bin/sh
cru a ScheduledReboot "0 4 * * * /sbin/service restart_wan"

this short tutorial should be bullet proof, I have just tested it on two ASUS routers with Merlin firmware version: 378.53

if you want to double check, telnet or SSH to your router
go to /jffs/scripts
ls - to check if script is really there
cru l - you should see your job scheduled in the cron list
 
Last edited:
Hello, I have problem with my provider. Sometimes I get my IP 100.*.*.* but it is not public IP. I need to reconnect while is other than 100.*.*.* (2-3 times) (I need public IP, because I need DDNS and VPN)
I need to create a script somethink like this:
Code:
#!/bin/sh

mojaIP=`nvram show | grep -e "wan_ipaddr=" | cut -f2 -d"="`
zacina=${mojaIP:0:3}

while true; do

if [ "$zacina" == "100" ]; then
  service restart_wan
  mojaIP=`show | grep -e "wan_ipaddr=" | cut -f2 -d"="`
  zacina=${mojaIP:0:3}
fi

sleep 60

done

It will input actual IP into $mojaIP and read first 3 chars from it into $zacina. If $zacina=100 it will service restart_wan. I create neverending loop for testing IP if it is not 100.*.*.* if my dinamic IP expires or something...
I hope it is good. If you have better idea, please help.
Important is - I need to run it like a daemon, and/or after reboot router. Because if will power down - I can't connect to my home network remotely, if my IP starts with 100 (probability 90%). Any idea? Is here something like /etc/init.d/ alternative?
Thank you for your help.
(sorry for my poor english)
 
How is a 100.*.*.* not a public IP address?
 
Yes there is, Rostelecom provider, if the address type 100. *. *. * Or 10. *. *. * They are gray are not public, the lack of impact of IP addresses in Russia.
I throw the script in a separate file, and run from wan-start with a pause of 60 seconds. Previously, it does not work.

Да есть такое, провайдер Ростелеком, если адрес типа 100.*.*.* Или 10.*.*.* Они серые не публичные, сказывается нехватка IP адресов в России.
Я кидаю скрипт в отдельный файл и запускаю из wan-start с паузой 60 секунд. Раньше не срабатывает.

Code:
#!/bin/sh
CYKLON=0
while [ "$CYKLON" = "0" ]
do
MYIP=$(ifconfig ppp0 | grep 'inet addr' | awk '{print(substr($2,6))}')
GRIP=$(echo "$MYIP" | cut -d . -f1)
let "GRIP += 1"
if [ $GRIP -eq 1 ]; then
    logger "!!!...Connect DOWN..service restart_wan........!!!"
    service restart_wan
    exit 0
    sleep 60 #not work exit 0 - exit script
else
    logger "!!!...Connect UP..WAN IP adress $MYIP......!!!"
fi
MYIP=$(ifconfig ppp0 | grep 'inet addr' | awk '{print(substr($2,6))}')
logger "!!!...WAN IP adress $MYIP"
GRIP=$(echo "$MYIP" | cut -d . -f1)
let "GRIP += 1"
if [ $GRIP -eq 11 ]; then
    CYKLON=0
    logger "!!!..WAN IP adress 10.x.x.x..service restart_wan...!!!"
    service restart_wan
    exit 0
    sleep 60
else
    CYKLON=1
    logger "!!!...WAN IP adress OK!!!..test_1...!!!"
fi
if [ $GRIP -eq 101 ]; then
    CYKLON=0
    logger "!!!..WAN IP adress 100.x.x.x..service restart_wan...!!!"
    service restart_wan
    exit 0
    sleep 60
else
    CYKLON=1
    logger "!!!...WAN IP adress OK!!!..test_2...!!!"
fi
logger "!!!...WAN IP adress $MYIP!!!..services start..!!!"
#ntpclient -h $(nvram get ntp_server0) -i 3 -l -s
#/opt/etc/init.d/S29udpxy restart
#logger "!!!...System time update and udpxy services restart OK!!!....!!!"
done
#/jffs/scripts/he-net.sh
#logger "!!!...Update IP http://he.net OK!!!....!!!"
exit 0
 
Last edited:
vmkogeretla, thank you for your help... Can you write me some "how to" for yours "... and run from wan-start"? I do not know what to do, how to make it. I am newbie :) Thanks again.
L&LD - yes, my provider is using private address starts with 100.*.*.* (I try from terminal command: curl ifconfig.me and it shows my public IP - it is different than I can see at the router - 100.*.*.* but if I have any other IP - than it is equal to... And I have confirmed it by provider support, then can't do anything with this, so I need help with this script). If router have IP 100... there is not work nothing - ping, vpn, closed all ports...
 
Add a file /jffs/scripts/wan-start this code:
Code:
#!/bin/sh
sleep 60
/jffs/scripts/name_your_script.sh
Add a file /jffs/scripts/name_your_script.sh this code:
Code:
CYKLON=0
while [ "$CYKLON" = "0" ]
do
MYIP=$(ifconfig ppp0 | grep 'inet addr' | awk '{print(substr($2,6))}')
GRIP=$(echo "$MYIP" | cut -d . -f1)
let "GRIP += 1"
if [ $GRIP -eq 1 ]; then
    logger "!!!...Connect DOWN..service restart_wan........!!!"
    service restart_wan
    exit 0
    sleep 60 #not work exit 0 - exit script
else
    logger "!!!...Connect UP..WAN IP adress $MYIP......!!!"
fi
MYIP=$(ifconfig ppp0 | grep 'inet addr' | awk '{print(substr($2,6))}')
if [ $GRIP -eq 101 ]; then
    CYKLON=0
    logger "!!!..WAN IP adress 100.x.x.x..service restart_wan...!!!"
    service restart_wan
    exit 0
    sleep 60
else
    CYKLON=1
fi
logger "!!!...WAN IP adress $MYIP....!!!"
done
exit 0
And run:
Code:
chmod a+rx /jffs/scripts/*
Reboot the router for testing.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top