How to turn ESP32 into NAT Router/Repeater

Disclosure
Some of the links in this post are affiliate links and if you go through them to make a purchase I will earn a commission. Keep in mind that I link these companies and their products because of their quality and not because of the commission I receive from your purchases. The decision is yours, and whether or not you decide to buy something is completely up to you. Read more

ESP32 development board can be used as WiFi router/repeater with NAT(Network Address Translation), thanks to martin-ger, who developed this great firmware for that purpose.

Features:
Small form factor.
Easy to make.
Low power consumption.
Can be used as WiFi range extender.
Can be used to setup additional WiFi network with different SSID and password(e.g. for guest or IOT devices).

Setup and installation

  1. Install esptool.
  2. Download the project form its GitHub page.
Download form GitHub
Downloading the project from its GitHub page

Or using GitHub CLI:

CMD/Terminal
gh repo clone martin-ger/esp32_nat_router
  1. Unzip the project and go inside its main directory.
  2. Connect your ESP32 to your computer(Get your ESP32 form AliExpress, Gearbest or Banggood).
  3. Enter the following command:
CMD/Terminal
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 build/bootloader/bootloader.bin 0x10000 build/esp32_nat_router.bin 0x8000 build/partitions_example.bin

For Linux /dev/ttyUSB0 is the name of the serial port, make sure that you specify the name of the serial port to which ESP32 is connected. While for Windows, serial ports are named something like COM1, COM2 and so on.

First boot

After first power up, your new ESP32 router will create an open WiFi network with SSID “ESP32_NAT_Router”.

Now, you can configure your ESP32 router, either using simple web interface or via the serial console.

Configuration via web interface

  • Connect your PC or smartphone to the open WiFi network “ESP32_NAT_Router”.
  • Open your browser and go to “http://192.168.4.1“. Subsequently, you should have the following page on your screen:
ESP32 NAT router web interface
  • At first, enter the correct values for the uplink WiFi network, in the STA Settings section. For open networks, leave the password field blank. Then, press Connect. After that, the ESP32 will reboot and connect to your WiFi AP.
  • Now, you reconnect and reload the page again, then you modify the AP Settings. So, you enter a new SSID and password for your ESP32 router. Then, click Set, the ESP32 will reboot again and its ready to forward traffic over the newly configured AP. If you want to make further changes, you need to connect to the newly configured AP.

Because the web interface is not secure and not protected with a password, anyone can open it and modify the settings. To get around that, the web interface can be disabled via the command line interface by the following commands:

Serial console
esp32>nvs_namespace esp32_nat
esp32>nvs_set lock str -v 1

After reboot, the web interface is no longer available. To re-enable it, enter the following commands:

Serial console
esp32>nvs_namespace esp32_nat
esp32>nvs_set lock str -v 0

Configuration via command-line interface

  • Connect your ESP32 to the USB port of your computer.
  • Open the serial port to which your ESP32 is connected, using Putty or any other serial terminal with baud rate set to 115200 bps.
  • After successful connection, type the following command, replacing <ssid> and <password> with your uplink WiFi network SSID and password respectively.
Serial console
esp32>set_sta <ssid> <password>
  • Now, using the “set_ap” command, you set your ESP32 access point SSID and password.
Serial console
esp32>set_ap <ssid> <password>
  • Finally, type “restart” to reboot the ESP32 with your new configurations.
Serial console
esp32>restart
Notes
  1. During configuration, If you want to enter non-ASCII or special characters (such as ‘ ‘) within your SSID or password, you have to use HTTP-style hex encoding (e.g. “Access%20Point” results in a string “Access Point”).
  2. If you made a mistake and you can’t communicate with the ESP32 anymore, you can use the serial console to reconfigure it. The parameter settings are stored in NVS(Non Volatile Storage), which will not be erased by re-flashing the binaries. However, you can wipe it out, by this command esptool.py -p /dev/ttyUSB0 erase_flash
  3. In the serial console, if you want to show the current configurations use show command. And you can type help to get the full list of available commands.

Share


Other articles you may find interesting

Description: Cool glowing animated frame, can be used to indicate activation or as click ripple effect Dependencies: None Mobile support:…
Read More
Description: Animated dot spinning around a word that can be used as animated logo or as a loader. Dependencies: None…
Read More
Description: Calendar month view that just resembles Window 10’s calendar appearance and animations. Dependencies: JQuery Mobile support: No Live: Su…
Read More
how to test an ethernet cable
Sometimes you need to test your Ethernet cable either to make sure it is working correctly before setup or to…
Read More
embed material design icons to your website
In this guide your are going to learn how to embed google’s material design icons to your website in simple,…
Read More
managed vs unmanaged switches
In general, network switches are the main building block of wired computer networks. It’s the networking hardware that connects other…
Read More

Advertisment

7 thoughts on “How to turn ESP32 into NAT Router/Repeater”

  1. A wholly agreeable point of view, I think primarily based on my own experience with this that your points are well made, and your analysis on target. Goldarina Kory Wojcik

  2. My wife and i got so cheerful when John could finish off his preliminary research using the ideas he had while using the weblog. It’s not at all simplistic to simply find yourself handing out steps some other people could have been making money from. And we see we have the blog owner to thank for this. The most important illustrations you have made, the easy website navigation, the relationships you will make it possible to create – it is many overwhelming, and it’s helping our son and our family do think this theme is excellent, which is very mandatory. Thank you for all! Curtis Cortis

Leave a Reply

Your email address will not be published. Required fields are marked *