Delay script running?

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


Joined: 22 Aug 2013
Posts: 154

PostPosted: Sat Dec 21, 2013 0:26    Post subject: Delay script running? Reply with quote
I have managed to load "v24-21061_NEWD-2_K2.6-openvpn-small" onto my Netgear WNR2000v2 router. It runs great and I have two wireless networks setup and running as well as the OpenVPN server for remote connections. It is running well, using only 46% of the RAM in the device.

Now, I have one tiny problem that bugged me when I was running the mini build that still bugs me. When I reboot the router or if the power flickers, my guest wireless cannot access the Internet. I enter the command below to solve the issue, but upon a reboot it is lost.
Code:

iptables -t nat -I POSTROUTING -o `get_wanface` -j SNAT --to `nvram get wan_ipaddr`

If I put this into the startup commands it executes before the WAN interface has an IP address from my ISP and does not work. Is there a way to bind this command to the WAN interface coming up? There was a way to bind scripts to interfaces coming up back in Debian Lenny that I used, but that was years ago and a lot has changed since then. Also, this isn't Debian. Thanks for the help!
Sponsor
Sephiroth
DD-WRT User


Joined: 22 Aug 2013
Posts: 154

PostPosted: Sun Dec 22, 2013 16:36    Post subject: Reply with quote
I am beginning to question the level of knowledge here as far as help goes. The simple yet not complete solution is below.
Code:

sleep 120 ; iptables -t nat -I POSTROUTING -o `get_wanface` -j SNAT --to `nvram get wan_ipaddr`

Save that as startup and it will wait two minutes before applying the iptables rule. This works on my router, but other routers may be faster or slower. Also, if you are having trouble with your ISP and the router cannot grab an IP address before the script runs, such as during an outage, the script will fail. If your ISP comes up an hour later you will have to reboot your router or run the script manually.

I was hoping that somebody would make a post about tying a script to when the WAN interface came up. In a full-blown Linux OS on a PC you can copy scripts to /etc/network/if-up.d/ or similar, edit /etc/network/interfaces, and add post-up /etc/network/if-up.d/scriptname.sh to the interface you want. Then the script runs each time the interface comes up.

Now, is it possible to do this with DD-WRT in some way? That would be the best solution until we have a way to make it just work from the GUI.
James2k
DD-WRT Guru


Joined: 23 Oct 2011
Posts: 549

PostPosted: Sun Dec 22, 2013 19:03    Post subject: Reply with quote
http://www.dd-wrt.com/wiki/index.php/Script_Execution
_________________
James

Main router:

Netgear R7000 overclocked to 1.2GHz - DD-WRT v3.0-r35965M kongac

IPv6 6in4 (HE.net), OpenVPN (with PBR and split tunnelling), Entware, dnsmasq with ipset

Easy ipset support for the R7000

VPN speed: Download: 77.96 Mbps Upload: 5.00 Mbps (AES-128-CBC HMAC-SHA1)

Yes you can get 50 Mbps+ with OpenVPN on a R7000 if you configure it properly!

Previous routers:

ASUS RT-N66U - The Dark Knight
WNR2000v3 - Bought on the cheap for someone else, neutered crap
WNR3500Lv1 - First venture into the DD-WRT world
redhawk0
DD-WRT Guru


Joined: 04 Jan 2007
Posts: 11564
Location: Wherever the wind blows- North America

PostPosted: Sun Dec 22, 2013 21:47    Post subject: Reply with quote
Include a

sleep 20

before your command. I've seen others with a "race condition" for running script commands. (including myself)

redhawk

_________________
The only stupid question....is the unasked one.
Sephiroth
DD-WRT User


Joined: 22 Aug 2013
Posts: 154

PostPosted: Sun Dec 22, 2013 23:19    Post subject: Reply with quote
Look at my second post. I put in a 120 second (2 minute) sleep so the WAN interface has time to come up before the command executes. I am now trying to tie this command into the WAN interface coming up.
basmaf
DD-WRT Guru


Joined: 24 Feb 2011
Posts: 1074

PostPosted: Mon Dec 23, 2013 5:20    Post subject: Reply with quote
Save the commands in firewall script not in startup
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