Skip to content

Instantly share code, notes, and snippets.

@ninadpchaudhari
Forked from navhaxs/99-keepwanalive
Last active March 28, 2024 19:18
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ninadpchaudhari/6561841ffc3667b1e5ee to your computer and use it in GitHub Desktop.
Save ninadpchaudhari/6561841ffc3667b1e5ee to your computer and use it in GitHub Desktop.
openwrt wan auto reconnect hotplug script
#!/bin/sh
#File for my debugging purposes
echo $ACTION >> /tmp/mylog
echo $INTERFACE >> /tmp/mylog
echo "" >> /tmp/mylog
#!/bin/sh
# Place me in /etc/hotplug.d/iface/99-keepwanalive
if [ "$ACTION" = "ifdown" -a "$INTERFACE" = "wan6" ]; then
echo "Entering IF statement" >> /tmp/mylog
COUNTER="0"
FLAG="0"
while [ "$FLAG" = 0 ]
do
echo "Entered While" >> /tmp/mylog
sleep 1
grep "unknown" /sys/class/net/pppoe-wan6/operstate
RESULT="$?"
echo "Result : $RESULT" >> /tmp/mylog
if [ "$RESULT" != 0 ]; then
let COUNTER++
echo "Log from /etc/hotplug.d/iface/99-keepwanalive -- pppoe-wan6 Fou$
logger -t DEBUG "Log from /etc/hotplug.d/iface/99-keepwanalive -- pppoe$
logger -t DEBUG "Attempt #${COUNTER} to reconnect pppoe-wan6"
echo "Attempt #${COUNTER} to reconnect pppoe-wan6" >> /tmp/mylog
ifup wan6
sleep 10 #sec
else
FLAG=1
fi
done
fi
@ninadpchaudhari
Copy link
Author

98-mylog is just for debugging purposes
tail -f /tmp/mylog would keep you updated

For interface names ,
ls /sys/class/net ...
In my case in 14.07,
Interface wan6 was for pppoe

@boussouira
Copy link

Thank you!

@ThomasCr
Copy link

ThomasCr commented May 4, 2018

operstate is on my interface always unknown - also when it is connected.

@Leo5117
Copy link

Leo5117 commented Apr 15, 2020

I'm new guy for openwrt and github too. I read your script is awesome!
I hope you can help me if I want to connect l2tp over ipsec client when WAN was connected.
How can I do it with hotplug iface script?
The l2tp over ipsec config was done and I can connect it use command. But it will discount after every 12 hours.
So I want to use hotplug to reconnect it if it is possibale!
Thanks a lot!

@Leo5117
Copy link

Leo5117 commented Apr 15, 2020

Here is my command code for l2tp
/etc/init.d/ipsec enable
/etc/init.d/xl2tpd enable
/etc/init.d/ipsec restart
/etc/init.d/xl2tpd restart
ipsec restart
ipsec up L2TP-PSK
ipsec statusall
echo "c strong-vpn" > /var/run/xl2tpd/l2tp-control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment