---
title: "W6100 khoih-prog / AsyncDNSServer_ESP32_Ethernet"
url: "https://maker.wiznet.io/eric_g/projects/khoih-prog-asyncdnsserver-esp32-ethernet/"
markdown_url: "https://maker.wiznet.io/eric_g/projects/khoih-prog-asyncdnsserver-esp32-ethernet/md"
type: "UCC: User Created Content"
author: "khoih prog"
author_url: "https://github.com/khoih-prog/AsyncDNSServer_ESP32_Ethernet"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "khoih prog"
original_url: "https://github.com/khoih-prog/AsyncDNSServer_ESP32_Ethernet"
published: "2023-02-01"
language: "en"
likes: 6
views: 641
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# W6100 khoih-prog / AsyncDNSServer_ESP32_Ethernet

> This AsyncDNSServer_ESP32_Ethernet library is a fully asynchronous DNSServer library, designed for a trouble-free, multi-connection network.

Original author: khoih prog (source: https://github.com/khoih-prog/AsyncDNSServer_ESP32_Ethernet)

## Documents and links

- [Async DNS Serverr](https://github.com/khoih-prog/AsyncDNSServer_ESP32_Ethernet) (code)

## Article

#### Why Async is better

- Using asynchronous network means that you can handle **more than one connection at the same time**

- You are called once the packet is ready

- After a DNS Client connected to this Async DNS server, you are **immediately ready** to handle other connections while the Server is taking care of receiving and responding to the UDP packets in the background.

- You are not required to check in a tight loop() the arrival of the DNS requesting packets to process them.

- **Speed is OMG**

## HOWTO Setting up the Async DNS Server

For ESP32 using `LwIP W5500 Ethernet`

```
#include <AsyncDNSServer_ESP32_Ethernet.h>
#include <ESPAsyncWebServer.h>

const byte DNS_PORT = 53;

IPAddress apIP;

AsyncDNSServer dnsServer;

AsyncWebServer server(80);

void setup()
{
  ...
  
  ///////////////////////////////////

  // To be called before ETH.begin()
  ESP32_W5500_onEvent(); --> ESP32_W6100_onEvent() 

  // start the ethernet connection and the server:
  // Use DHCP dynamic IP and random mac
  //bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
  //           int SPI_HOST, uint8_t *W5500_Mac = W5500_Default_Mac);
  ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
  //ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );

  // Static IP, leave without this line to get IP via DHCP
  //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
  //ETH.config(myIP, myGW, mySN, myDNS);

  ESP32_W5500_waitForConnect(); --> ESP32_W6100_waitForConnect()

  ///////////////////////////////////

  apIP = ETH.localIP();

  ///////////////////////////////////

	// modify TTL associated  with the domain name (in seconds)
	// default is 60 seconds
	dnsServer.setTTL(300);
	// set which return code will be used for all other domains (e.g. sending
	// ServerFailure instead of NonExistentDomain will reduce number of queries
	// sent by clients)
	// default is AsyncDNSReplyCode::NonExistentDomain
	dnsServer.setErrorReplyCode(AsyncDNSReplyCode::ServerFailure);

	// start DNS server for a specific domain name
	dnsServer.start(DNS_PORT, "*", apIP);

  ...
}

void loop() 
{
}
```

---

Source: https://maker.wiznet.io/eric_g/projects/khoih-prog-asyncdnsserver-esp32-ethernet/
