How I moved my homepage to IPFS

November 28, 2020

I just moved my homepage over to IPFS! The Inter Planetary File System has been around a while, but I didn’t hear about it until recently. Hosting your static home page on ipfs is not so difficult, but the guides can be a bit confusing. So here is a short summary of what I did.

ipfs

Adding the site

I installed the ipfs cli following the instructions. First I needed to launch the ipfs daemon with

ipfs daemon &

Then I published the directory which contained all the files of my website. I am using a site generated by hakyll.

ipfs add -Hr _site

The -H option includes hidden files like my Brave rewards verification token at .well-known/brave-rewards-verification.txt. When the files are pinned the corresponding hash is displayed for each file and their relative path. A hash like QmQBz9LVEGLaeUfQ2nfYgV6tErijruSmCDKeLPRso7qDM8 is the result a one way function such that input data corresponds to a unique hash. The space of possible files is of course much greater than the space of hashes, but the chances of two files having the same hash is so small it might never happen in this universe. Older hashes like md5 do have known collision though so they should not be used.

The last hash is then a reference to the entire directory and it can be accessed on https://ipfs.io/ipfs/<hash>. This is not so easy to remember though and the hash will change every time the site is updated.

Connecting to DNS and the old internet

I want my site to be accessible via sorby.xyz so that people won’t need to remember the hash. To do this I use DNSLink which is a sort of gateway from the regular old internet to the ipfs internet. It just requires adding two entries to my DNS record. One A or ALIAS record which points to a ipfs gateway like gateway.ipfs.io and a TXT record which tells ipfs which hash the adress should point to. The TXT record looks like this dnslink=/ipfs/QmQBz9LVEGLaeUfQ2nfYgV6tErijruSmCDKeLPRso7qDM8. Then every time I update my homepage I just need to update this hash in the TXT record.