jonask1337 / esp-idf-nat-example

ESP-IDF example project with NAT setup.
82 stars 15 forks source link

esp-idf-v3.3 dns server(192.168.4.1) #15

Closed betashepherd closed 4 years ago

betashepherd commented 4 years ago

Hi,

I have merged this branch to mongoose os, the final problem is the DNS server as 192.16.4.1, if the device needs access the internet, need manually set the DNS server(8.8.8.8). How to fix it? Pls, help!

wifi sta(192.168.0.1) -> nat -> wifi ap(192.168.4.1), the right dns server should be 192.168.0.1, but the device connected to esp32 get dns server as 192.168.4.1

jonask1337 commented 4 years ago

Hi, by default the DHCP server which is running on the ESP32 returns his own IP when a device connects to it. In the esp-idf-nat-example in the main.c file a custom IP address (in this case 8.8.8.8) is set that the DHCP server will offer to connected devices.

These are the corresponding lines to this in the main.c file:

 // Set custom dns server address for dhcp server
dnsserver.u_addr.ip4.addr = htonl(MY_DNS_IP_ADDR);
dnsserver.type = IPADDR_TYPE_V4;
dhcps_dns_setserver(&dnsserver);

It seems for some reason the custom DNS IP is not set in your case and the DHCP server on the ESP32 is returning the default IP address. Did you make any changes to the esp-idf-nat-example? I don't have any experience with mongoose os, so I can't really help with the problem or analyze it in this direction though.

betashepherd commented 4 years ago

Hi, by default the DHCP server which is running on the ESP32 returns his own IP when a device connects to it. In the esp-idf-nat-example in the main.c file a custom IP address (in this case 8.8.8.8) is set that the DHCP server will offer to connected devices.

These are the corresponding lines to this in the main.c file:

// Set custom dns server address for dhcp server
dnsserver.u_addr.ip4.addr = htonl(MY_DNS_IP_ADDR);
dnsserver.type = IPADDR_TYPE_V4;
dhcps_dns_setserver(&dnsserver);

It seems for some reason the custom DNS IP is not set in your case and the DHCP server on the ESP32 is returning the default IP address. Did you make any changes to the esp-idf-nat-example? I don't have any experience with mongoose os, so I can't really help with the problem or analyze it in this direction though.

Thanks for your help, I will