The Domain Name System (DNS) is like a massive addressbook for computers, services and any other devices connected to the Internet or a private network. Just like an address, it holds various pieces of data about each entry. It is most known for translating a domain name like cesanta.com into the corresponding numberical IP address. Functions like this make it essential to the Internet.
To server requests, DNS uses UDP on port 53 primarily. DNS queries consist of a single UDP request from the client followed by a single UDP reply from the server. When the response size exceeds 512 bytes, TCP is used. However, some resolver implementations use TCP for all queries.
The functions of using domain names instead of numerical IP addresses is not just about convenience. For M2M communication, IP addresses tend to change for different reasons. In the embedded world, with billions of connected devices, this change of address can cause serious problems. For example, if you have hundreds of devices that report temperature readings to a dedicated server with the address 18.104.22.168 and this server changes address, the entire system is broken. Hundreds of devices can no longer transmit readings. However, if the temperature readings were sent to a specific domain name like weather.com, the connection will be successful. Of course, a name can change also, but this is happens far less frequently.
Mongoose has several points of DNS support.
First of, you can write mg_connect(“22.214.171.124….”) or mg_connect(“ weather.com….”). By using its own API, Mongoose will automatically resolve the name to the address and establish a connection. This process is asynchronous. It runs in the background so that you don’t have to think about it.
In addition, Mongoose provides s Client DNS API that your application can use to resolve names to addresses.
And finally, Mongoose has Server DNS API where you can write you own DNS server and use it, for example, to build a captive portal.