I’ve been interested in decentralising the web for quite a while now, ever since it became apparent that the tech giants of the world wield too much power over our personal data. Recently I went down the rabbit hole of hosting my own email, rss reader, Nextcloud, and more, but the problem of making sure all your applications are reliable hasn’t become any easier.
I read about IPFS a while back but it wasn’t until Cloudflare announced their own IPFS gateway that I wondered - what if I hosted my blog with IPFS? More specifically, what if I hosted the blog that I’d been thinking about starting up again for a while with IPFS?
So firstly, what is IPFS? In a nutshell, IPFS is a distributed fileshare. You make your local files available on IPFS through the act of “pinning” them to your machine, and you give other people the hash of your content. They can then retrieve that content from your machine over the network without needing to know where the files actually reside.
In this post I’m going to walk you through hosting content on IPFS.
Firstly, install IPFS. Then start your daemon:
In another tab, find a directory you want to make available, and run:
ipfs add -r ./directory
You’ll receive the hash that maps to your content. To actually make it available on the IPFS network, you need to pin it:
ipfs pin add -r /ipfs/HASH
Or, by visiting it in a browser through one of the available IPFS gateway:
Your content is now available to everyone on IPFS, and they can get it from your machine.
That’s all very well and good, but those URL’s are a bit of handful. Wouldn’t it be nice if you could give someone a friendly URL that points towards your content? Well, you can.
You need to have a domain name, and have the ability to add new entries to your DNS records. To make your content available under a domain, for example, nathan.kellenicki.com, add a new txt record to your parent DNS record:
_dnslink.nathan txt dnslink=/ipfs/HASH ttl=120
You want to set your ttl to a low enough number that visitors will be able to see updates quickly rather than seeing cached content.
At this point, you can request your content over IPFS again:
ipfs get /ipns/nathan.kellenicki.com
That’s quite a lot better already, but really you want to make it so people can just type your domain name into your browser. To do this, you need to pick an IPFS gateway that you want to serve your content. In this example, I’m going to choose Cloudflare’s. It’ll differ between gateways, so check the documentation for that gateway.
For CloudFlare, you just need to add another DNS entry:
nathan.kellenicki.com cname www.cloudflare-ipfs.com ttl=120
Once it has propagated, you should be able to access your content by:
Which incidentally, will bring you to this blog! We’ve come full circle!
Eventually you’ll want to update your content. To do this, you’ll need to add and pin your directory again, which’ll give you a new hash. Then you just need to update your txt record with the new hash and wait for the change to propagate (Remember how we made the ttl really low?).
Following the above will make your content available from your machine, and as long as your content remains popular, it’ll remain on the IPFS network as other nodes will cache it. However if it isn’t popular, your content will leave caches after 24 hours. At that point if your machine is off, your content will no longer be accessible. There needs to be at least one node that has the content pinned for that content to remain accessible.
In practice, this means you either keep your machine online, or you get other IPFS nodes to pin your content too.
Perhaps you find a friend or a free IPFS node out there happy enough to pin it, or you pay a service such as Eternum to pin it to their node. Either way, you need to find someone to keep a copy pinned, or keep your machine online.
For this blog, it’s just an experiment, and we’ll see how it goes. However in general, IPFS is a really exciting technology that should make it easy to distribute your content in a decentralised fashion. I feel at this point there needs to be a larger network of nodes offering pinning services for it to take off, otherwise it’ll be really hard to make your content available 24/7. Hopefully adoption gets to that point.