2011-05-12
Namecoin - A DNS alternative based on Bitcoin
Namecoin is a domain name system based on Bitcoin. It extends Bitcoin to add transactions for registering, updating and transferring names. The idea behind this is to provide an alternative to the existing DNS system where names can be taken from their owners by groups that control the DNS servers.
The project was originally announced in the bitcoin forums and has seen some uptake. The namecoin author, vinced, states in the post:
- This is a new blockchain, separate from the main Bitcoin chain
- Name/value pairs are stored in the blockchain attached to coins
- Names are acquired through new transaction types - new, first-update and update
- Names expire after 12000 blocks unless renewed with an update
- No two unexpired names can be identical
- Block validation is extended to reject transactions that do not follow the above rules
- The code is here: https://github.com/vinced/namecoin
A number of projects have been created around this to provide a mapping from namecoin names to standard DNS. This allows resolving namecoin names to a '.bit' suffixed domain. I'll go through building the namecoin software, registering and updating names, then the software to use these names.
Building Namecoin
Namecoin needs to be built from source. The following steps on a Linux based system will build without UPNP support:
$ git clone git://github.com/namecoin/namecoin.git
$ cd namecoin
namecoin $ make -f makefile.unix USE_UPNP=
Once built you'll need to create a ~/.namecoin/bitcoin.conf file that contains entries for a username and password used for the JSON-RPC server that namecoind runs. Notice the name of the .conf file is bitcoin.conf even though this is namecoind. It won't clash with an existing bitcoin installation as it is in a ~/.namecoin directory. To prevent conflict with an existing bitcoin install I suggest running namecoind on a different port. An example ~/.namecoin/bitcoin.conf is:
rpcuser=me
rpcpassword=password
rpcport=9332
Running namecoind will start the daemon and you can then use namecoind to execute commands:
$ ./namecoind
bitcoin server starting
$ ./namecoind getblockcount
2167
Yes, it prints out 'bitcoin server starting'. There are still bitcoin references in the code that need to be changed apparently.
Getting Namecoins
To register a name you need to have some namecoins. These can be obtained via mining, just like bitcoins. Or you can buy them. To mine namecoins you can run any of the standard bitcoin miners and point them to the server and port that is running namecoind. The difficulty level for namecoin mining is currently very low (about 290 at the time of writing) so even CPU miners have a chance. Generating a block gets you 50 namecoins.
You can also buy namecoins as described here. The going rate seems to be about 1BTC for 50 namecoins.
Registering a name
The name_new command will register a name. An example invocation is:
$ ./namecoind name_new d/myname
[
"1234567890123456789012345678901234567890",
"0987654321"
]
This will start the registration process for the name myname. Note the two hash values returned. Once this is done you need to wait for 12 blocks to be generated by the namecoin network. You then need to run a name_firstupdate command:
$ ./namecoind name_firstupdate d/myname 0987654321 '{"map":{"":"1.2.3.4"}}'
We pass to name_firstupdate the domain name we are updating, the shorter hash that we got from name_new and a JSON value that defines how that name is mapped to an IP address.
In this case the name is mapped to the IP address 1.2.3.4. Using the existing systems for mapping names this would make myname.bit resolve to 1.2.3.4. You can also do subdomains (See the update example later).
The cost to do a name_new, followed by a name_firstupdate, varies depending on how many blocks there are in the namecoin block chain. It started at 50 namecoins and slowly reduces. The formula is defined in the namecoin design document as:
- Network fees start out at 50 NC per operation at the genesis block
Every block, the network fees decreases based on this algorithm, in 1e-8 NC:
res = 500000000 >> floor(nBlock / 8192) res = res - (res >> 14)*(nBlock % 8192)nBlock is zero at the genesis block
- This is a decrease of 50% every 8192 blocks (about two months)
- As 50 NC are generated per block, the maximum number of registrations in the first 8192 blocks is therefore 2/3 of 8192, which is 5461
- Difficulty starts at 512
Updating a name
To update the domain mapping you use name_update:
$ ./namecoind name_update d/myname '{"map":{"":"1.2.3.4","www":"5.6.7.8"}}'
This example updates the value of myname so it includes a www subdomain. The name www.myname.bit will now map to 5.6.7.8.
There are other possibilities for the JSON mapping. See the namecoin README for details. Note that the JSON code must be valid JSON (ie. use double quotes, unlike the examples currently shown in the README unfortunately).
Transferring a name
To transfer a name to another person you need to get their namecoin address and do an update passing that address:
$ ./namecoind name_update d/myname '{"map":{"":"1.2.3.4"}}' NGZs7UndoWgpfTstoxryYEW8b1GtDLPwMa
Addresses can be generated with:
$ ./namecoind getnewaddress
N9jzzaptnQ28uiLgWm19WZAqrGqRVVGkFX
Transferring namecoins
You can transfer namecoins to other people by sending coins to their address just like bitcoin:
$ ./namecoind sendtoaddress N9jzzaptnQ28uiLgWm19WZAqrGqRVVGkFX 50
This will send 50 namecoins to N9jzzaptnQ28uiLgWm19WZAqrGqRVVGkFX.
Listing registered names
You can list all registered namecoin names using name_scan:
$ ./namecoind name_scan
{
"name" : "d/bluishcoder",
"value" : "{\"map\":{\"\":\"69.164.206.88\"}}",
"txid" : "....",
"expires_in" : 10874
},
You can also list only the names you've registered using name_list:
$ ./namecoind name_list
{
"name" : "d/bluishcoder",
"value" : "{\"map\":{\"\":\"69.164.206.88\"}}",
"expires_in" : 10874
}
Using namecoin names
Software needs to be modified to use namecoind to lookup the name, or you can run DNS software that connects to namecoin to do lookups. To be able to try out namecoin I modified an HTTP proxy and later tried using DNS software.
HTTP Proxy
I modified the Polipo web proxy to use namecoin for lookups. The modified source is available at https://github.com/doublec/namecoin-polipo. This can be built and run with:
$ git clone https://github.com/doublec/namecoin-polipo
$ cd namecoin-polipo
$ make
$ ./polipo namecoindServer="127.0.0.1:9332" namecoindUsername=rpcuser namecoindPassword=rpcpassword
Changing your browser to point to the proxy on localhost, port 8123, will allow .bit domains to be used. See my forum post about it for more details.
dnsmasq
Another approach I tried was to write a program that generates a 'host file' from namecoind and uses dnsmasq to run a local DNS server that serves domains from this host file, falling back to the standard DNS server. The 'quick and dirty' code to generate the hosts file is in namecoin-hosts.c and uses libcurl and libjansson to build:
$ gcc -o namecoin-hosts namecoin-hosts.c -lcurl -ljansson
I added the following to my dnsmasq.conf:
local=/.bit/
local-ttl=300
addn-hosts=/tmp/hosts.txt
And created a shell script to update /tmp/hosts.txt with the namecoin related data:
while true; do
./namecoin-hosts 127.0.0.1:9332 rpcuser rpcpassword >/tmp/hosts.txt
kill -HUP `cat /var/run/dnsmasq/dnsmasq.pid`
echo `date`
sleep 300
done
Pointing my OS DNS resolver to the dnsmasq IP address and port allowed .bit names to resolve.
Public .bit DNS servers
Details of a public .bit DNS server that doesn't require you to run namecoin are available at namecoin.bitcoin-contact.org. That site also provides details on using namecoin.
More Information
Namecoin seems to be very much an experiment in having an alternative DNS like system. The developer has taken the approach of 'release early' and iterate towards a solution. As such it may fizzle out and go nowhere. Or it may prove a useful test-bed for ideas that make it into a successful DNS alternative.
More details about Namecoin can be obtained from:
- Merge Mining Pool for mining Namecoins and Bitcoins concurrently.
- Vircurex Exchange. Buy and Sell namecoins using bitcoins.
- dot-bit.org. Contains setup information, binaries to download, forums and other pointers.
- Original Namecoin announcement thread
- Dot-BIT Project announcement thread
- Namecoin github repository
- Namecoin subreddit
#namecoinchannel onirc.freenode.net
Are there any other alternatives to DNS around with similar ideas?