Skip to main content

Connect wan automatically at boot and after a disconnection on OpenWrt

OpenWrt is an open source project for embedded operating system based on Linux, primarily used on embedded devices to route network traffic. I install OpenWrt on my Netgear DGN3500, an ADSL2+ gateway with wireless acccess point integrated. Finally the wifi signal is strong but the internet connection does not go up at boot or after a disconnection.

Found solutions

I find the following solutions: to schedule the reboot and the reconnections by cron (, to write a script to reconnect after a disconnection ( or to insert the command "ifup wan" in the file "/etc/init.d/network".

Recomended solution

To take all the advantages of the previous solutions i write the script "wanup" to connect the wan and i call its at boot and after the disconnection. To call the script "wanup" at boot you can insert the command "/bin/sh /etc/wanup" int file "/etc/init.d/network" at the end of function "service_running". To call the script "wanup" after a disconnection you can create a script for hotplug and place it in "/etc/hotplug.d/iface".


I make a repository, where you can find all files:

The script "/etc/wanup"


while [ $PASS -eq 0 ]
  grep "unknown" /sys/class/net/pppoe-wan/operstate
  logger -t DEBUG "The wan first check is ${RESULT}"
  if [ "$RESULT" != 0 ]; then
    sleep 10 #sec
    grep "unknown" /sys/class/net/pppoe-wan/operstate > /dev/null
    logger -t DEBUG "The wan second check is ${RESULT}"

    if [ "$RESULT" != 0 ]; then

      let COUNTER++
      logger -t DEBUG "Attempt #${COUNTER} to reconnect wan"
      ifup wan
      sleep 30 #sec

      logger -t DEBUG "The wan is connected"
    logger -t DEBUG "The wan is connected"

The script "/etc/hotplug.d/iface/99-keepwanalive"

# Place me in /etc/hotplug.d/iface/99-keepwanalive

if [ "$ACTION" = "ifdown" -a "$INTERFACE" = "wan" ]; then




Popular posts from this blog

IoT temperature sensor with ESP8266 using LWM2M (Eclipse Wakaama)

The sensor uses an ESP8266 board with the protocol Lightweight M2M to communicate the temperature read by DS18B20 to the gateway. The sources of the project are available on GitHub: ESP8266 The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability produced by Espressif Systems. The avalability of same SDK allows the chip to be programmed, removing the need for a separate microcontroller. To program the microchip i use the SDK Arduino core for ESP8266 WiFi chip  and  PlatformIO , that is an open source ecosystem for IoT development. LwM2M Lightweight M2M is a protocol from the Open Mobile Alliance for M2M or IoT device management and communication. It uses CoAP, a light and compact protocol with an efficient resource data model, for the application layer communication between LWM2M Servers and LWM2M Clients. Each service on a constrained device/sensor/actor is

Smart solar water heating solution to take part in the Open IoT Challenge 4.0!

Smart solar water heating solution uses IoT and AI technologies to improve the efficiency of passive solar water heating system. This solution is designed to take part in the Open IoT Challenge 4.0! Solar water heating Solar water heating (SWH) is the conversion of sunlight into heat for water heating using a solar thermal collector. Solar water heating systems include storage tanks and solar collectors. There are two types of solar water heating systems: active, which have circulating pumps and controls, and passive, which don't. Passive solar water heating systems are typically less expensive than active systems, but they're usually not as efficient. However, passive systems can be more reliable and may last longer. The solar panels heat the water in the storage tank when they are affected by the sun rays. The water reaches the highest temperature when the sun is stronger. If the water in the solar panel is hot the divert valve close the flow towards the boiler s