You can now host DNS domains on Ethereum’s blockchain through ENS, which is short for Ethereum Name Service, a distributed, extensible domain naming system that relies on Ethereum’s blockchain. This is possible via adjusting the domain name server settings to point to gateway DNS servers, which resolve lookups through checking an ENS registry that points to resolvers including the zone data for the domain in question.
Throughout this tutorial, I will present you with a simple guide to help you host your DNS domain on the blockchain.
Note: You have to be running a full Ethereum node on your machine to be able to follow through this tutorial. We have a detailed tutorial on how to run a full Ethereum node that will help you run yours, even if you are a total newbie.
1. Implementing your own ENS registry:
First, you will have to implement ENS central component, i.e. “the registry”. To do so, run the following code into an Ethereum console (via your Ethereum client):
Once this contract is successfully mined, you will have a fresh new ENS registry, whose root is controlled by the account that created the contract, i.e. the transaction. As such, this account will have total control over the registry, as it can add or remove nodes along the entire tree.
2. Implementing a registrar:
A registrar represents a contract that controls a node, i.e. a name, within the ENS registry, and provides a special user interface for participants to register subnodes, i.e. subdomains. A registrar can be implemented on any domain name. Throughout the following example, we will implement a basic first-in-first-served registrar via the root node.
To implement a first-in-first-served registrar via the root node of your ENS registry, run the following code in an Ethereum console.
Once this contract is successfully mined, as owner of the ENS registry, you can transfer the ownership of the root node to the new registrar that has been created via executing the following code in an Ethereum console:
Now, users can register names, i.e. nodes, with the registrar. You can register the names you desire with the FIFS registrar. Users can now register domain names via two top level domains:
- .eth: this top level domain uses an auction registrar that has the same functionality of the main network and permits users, registering domain names, to own them indefinitely. Visit this link for registering a domain name with the auction registrar.
- .test: this top level domain allows any user to claim any unused domain name for test purposes. Domain names expire automatically after 28 days.
3. Implementing a DNSResolver instance:
To implement an instance of the DNSResolver, run the following code in an Ethereum console.
4. Setting DNSResolver as the domain name’s resolver:
The ENS registry has to be modified so that the newly implemented DNSResolver acts as the resolver of your domain name. This can be done by using the setResolver function, as in the following code example:
So, in the previous example, we set DNSResolver to be the resolver of the domain name deepdotweb.eth.
The ENS blog has a useful guide that includes details of how to interact with the ENS registry e.g. registering a name, transferring name ownership, creating subdomains…..etc.
5. Writing a Zonefile:
You have to write a zonefile that includes an NS record of your domain name that specifies address.ns1.ens.domains as the resolver, but don’t forget to replace address with the address of your ENS registry that you implemented in step 1, but omit the “Ox” in the beginning. The following is an example code for a zonefile.
6. Cloning and Building ensdns:
Clone and build ensdns. Now, start your node and then run the following code in an Ethereum console:
This will upload the zonefile to the blockchain.
7. Finally, Updating Your NS Records:
The final step is to update your NS records with your registrar to point to the domain you used above which is in the format:
So, if we chose a domain name e.g. deepdotweb.eth it will be hosted on the blockchain, i.e. resolve to something like:
Here you go, you now have an ENS domain hosted on Ethereum’s blockchain. In the end, it is worth mentioning that ENS hosting is an experimental feature that is still in its infancy, so you should not use it for any critical domains. The DNS gateway still has not been extensively tested and presently, only a single instance is working, so there is no backup or any mitigation strategies in case of server failure. Also note that the configuration and API can be changed in backwards-incompatible ways, which can break your nameserver. This should only be used for experimental and research purposes.