Hosting websites on IPFS with IPNS

Yaniv Goldobin
2 min readOct 21, 2016

--

I’ve recently been developing a platform for hosting versioned websites on IPFS called Dispersion, and I’d like to talk about the key to making it all possible: IPNS.

If you’re new to IPFS then definitely check it out, but for the purposes of this article it’s most important to understand that whenever you add a file to IPFS (think globally shared file system), its reference in the system is an immutable content-addressed hash. This is necessary for security purposes in distributed systems…if i’m to download a file from a collection of anonymous peers in the network, then i can guarantee that none of them have added anything malicious to the file that i’m requesting by checking if the hash of the file they’re sending me matches up with the original hash I’m requesting. If they’ve altered the file they’re hosting even a little bit, the hash they host will be different and I can reject that content.

The problem that this poses for Dispersion is that we wanted a way to map a standard domain name, like jimboFlex.com to a website (which is really just a folder of files). If you have no plans to change the content of the website then you could just redirect your DNS to your IPFS bucket with your files (some link like https://ipfs.io/ipfs/QmPXPNF8mxUafxPJRT3EFmHAQHmTDzU58aN9PGZyD5sszV). But then anytime I add new content to my website and post it, i’d have to rehash it and go back into my DNS records and redirect to my updated hash link. This is a prohibitive pain if you want to host websites on IPFS and still be able to iterate on them.

Enter IPNS

IPNS is a way to add a small amount of mutability to the permanent immutability that is ipfs. It allows you to store a reference to an ipfs hash and update what that reference points to simply by executing a publish command.

$ ipfs name publish <that hash>

This means that all I have to do is point my jimboFlex.com DNS to an IPNS link, and anytime I change my website content I just rehash it and publish it. No need to go into my DNS. No need to rehost my website on AWS. This allows for some seriously awesome functionality in terms of iterating on websites and redeploying them in seconds!

By the way, did I mention it’s all free?

--

--