Hi everyone,

I used to run in windows when I had no router the following script


        ipconfig/release
        netsh interface IP set address "mywan" static 1.2.3.4 255.0.0.0
        1.2.3.5 0
        netsh interface IP set address "mywan" dhcp
        ipconfig/renew 

It gets a new ip from the ISP (for example if ISP has the feature of
giving the user various IPs but won't renew it before before two days)


When I tried to get the above code to work in linux I wrote something
like this


        dhcpcd -k eth0 ; sleep 4s; dhcpcd -r 190.189.48.70 -l 10000 eth0
        

Which worked almost flawlessly.
Here is the complete code for those interested
http://ubuntuforums.org/showthread.php?t=1440125

When I switched again to dd-wrt (cause no image for my router was
available at that time), I used a similar script which used udhcpc. I
sadly lost that  script.

Now I tried rewriting the script for open-wrt


        ##SCRIPT
        #!/bin/sh
        oldip==`ifconfig br-wan | sed -n -e 's/.*inet addr:\([0-9]*
        \.[0-9]*\.[0-9]*\.[0-9]*\)\ .*/\1/p'`
        echo "Old ip was $oldip"
        oldsubnet=`ifconfig br-wan | sed -n -e 's/.*inet addr:\([0-9]*
        \.[0-9]*\)\..*/\1/p'`
        echo "Old subnet is $oldsubnet"
        number=$(awk 'BEGIN{srand(); print int(255 * rand()) }')
        sleep 1
        number2=$(awk 'BEGIN{srand(); print int(255 * rand()) }')
        pid=`pidof udhcpc`; /bin/kill -SIGUSR2 $pid
        udhcpc -r "$oldsubnet.$number.$number2" -i br-wan
        newip==`ifconfig br-wan | sed -n -e 's/.*inet addr:\([0-9]*
        \.[0-9]*\.[0-9]*\.[0-9]*\)\ .*/\1/p'`
        echo "New ip was $newip"
        

I pass it via ssh.
#!/bin/bash
ssh 192.168.1.1 -l root 'sh -s' < /home/martin/bin/open-wrt/script.sh
exit


Problem is that after the script runs I have no Internet connection. I
seem to get my new ip
Wondering what happened I use Luci reconnect interface button which
clears the apparent mess, and I get to use the new ip.

So I suppose that somehow the connection state ends messed up somehow.
Specifying in the udhcpc call

        -p /var/run/udhcpc-br-wan.pid -s /lib/netifd/dhcp.script

kinda works but gets me the same ip. I do not want this.


ifdown br-wan and ifup br-wan do nothing since i don't have them as
interfaces in /etc/config/networking/
I wonder how LUCI actually reconnects??
I tried searching the documentation, but it's a little difficult for my
current knowledge
http://luci.subsignal.org/trac/wiki/Documentation

Nonetheless I think my problem here is that giving a custom call to
udhcpc messes with netifd original config or something and renders the
interface useless?

Any ideas on how to properly script this??

Sorry for the long mail!
Thanks Everyone


_______________________________________________
openwrt-users mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-users

Reply via email to