Search code examples
arduinolocalhostipesp32gateway

What is the gateway IP address for localhost?


I am trying to setup my ESP32-arduino Web server to localhost on port 8080.

What should I mention for the gateway IP address?

My current code is as follows:


  IPAddress staticIP(127, 0, 0, 1);
  IPAddress gateway(127, 0, 0, 1);
  IPAddress subnet(255, 255, 0, 0);
  IPAddress primaryDNS(8, 8, 8, 8); //optional
  IPAddress secondaryDNS(8, 8, 4, 4); //optional

  if (WiFi.config(staticIP, gateway, subnet, primaryDNS, secondaryDNS) == false) {
    Serial.println("Configuration failed.");
  }

Solution

  • I'm not really sure what you're trying to do here, but there is no gateway for "localhost".

    127.0.0.1 and "localhost" mean self. They are not meant to be routable or externally reachable.

    You need to use the correct public IP address of a network interface on whatever computer or server you're trying to reach. "localhost" and 127.0.0.1 are not it.