Published in


How to add site to IPFS and IPNS

IPFS allows to place p2p content inside web applications and simple web pages. Also you can hosting whole static site in peer to peer(p2p) IPFS network. So other people, who owns IPFS nodes can share your site and be a peer of your content and distribute HTML, CSS, JS and Images from their nodes. After that — if you node stops, the site will live, while someone with an IPFS node will keep a site on his node.

How to get started with your first site in IPFS network:

  1. Run your own IPFS node
  2. Add content to IPFS by simple commands
  3. Use the result content hash(output of command) to get files by link:<your hash here>
  4. You can place this link right in img tag by example: <img src=”<your hash here>”/>
    Or you can publish sites to IPNS and viewable at the link:
Картинки по запросу ipfs

Now let’s describe these 4 points in details:

1. Download and run IPFS node:
let’s take a linux amd64 distribution for example:

cd ~/

Then install it following the instructions here:
In my example:

tar xvfz go-ipfs_v0.4.14_linux-amd64.tar.gz
cd go-ipfs

Now you can init and run the node:

ipfs init
ipfs daemon > ipfs.log &

2. Add content to IPFS node:

Let’s create your IPFS site directory:

cd ~/
mkdir my-site; cd my-site

Now, for example you can download some cat image:

wget -O cat.jpeg

And create index.html and style.css with this content:

Finally add the whole site directory to your node:

cd ../
ipfs add -r my-site/

You should see something like this:

added QmQiuSt4dKVFvi1zkYbrBWgX8CpasLmzux6dWrdfoDq1Qc my-site/cat.jpegadded QmQtJm6VcLdyMa6RqWESPgXsqmiaJ48RXrLFXojPPtHkni my-site/index.htmladded QmZL2UBTwnhcLv66fARL9UV8W8a9ZA4iwTLcaUCsB1u1yW my-site/style.cssadded QmNUhKfcGJyQJnZu3AKn8NoiomDwDCRBicgqPt1YRqJBCz my-site

3. Visit your site by IPFS hash

The hash on the last line is the root of your site, you can visit it by opening<your hash here>. So the example site is at

You can get any file by link which you add to IPFS.

4. Publish to IPNS

Despite the fact that you can get a link to the site — when you make changes to it — the link will still point to the previous version of the site. This is because the IPFS is using git-like system for files hashes(hash point to specific version of the file like commit hash). So using this IPFS link you will not be able to get new version of the site.

That’s why we need IPNS — to bind your directory or file to your node peerID. After that — we can get the newest version of site at any time, when using the IPNS link.

Now we want to publish current version of site to IPNS:

ipfs name publish QmNUhKfcGJyQJnZu3AKn8NoiomDwDCRBicgqPt1YRqJBCz

You should see something like this:

Published to QmYmmfn68vkcFDeZz1NTZyEXTixjjUnUS6UaPdMSsUBWxs: /ipfs/QmNUhKfcGJyQJnZu3AKn8NoiomDwDCRBicgqPt1YRqJBCz

That will return your peerID (QmYmmfn68vkcFDeZz1NTZyEXTixjjUnUS6UaPdMSsUBWxs) and the hash you are publishing to peerID. You can confirm by running

ipfs name resolve <peerID>

After that — you can visit published version of site by link:<peerID>

In my example:

In future, when you need to change site content — you can do it, then add new site version to ipfs and publish it again:

ipfs add -r my-site/
ipfs name publish <new site hash>

New site hash will become attached to your peerId, and when user visit the IPNS link — he will get newest version of site.

But this IPNS link is still too long, and not human-friendly. And that’s why I added bonus point:

5. Bind IPNS to domain

To do that — you need to buy a domain, and then change the domain DNS settings.

You can bind IPNS to domain by adding a DNS TXT record of the form

“dnslink=/ipfs/<peerID>”, so you can have paths like /ipns/
For example, I added my-site to the DNS, and now is available through the url


Please don’t worry if your or my content is loading too slow. An advantage of IPFS is that the more popular the content, the faster it loads. Because more peers shares you content and the client get more sources and your content become faster.

To improve loading speed of your content — ask friends to share your content, i’m using this steps to do so:

cd ~/ && mkdir ipfs-files # Create folder to download ipfs content
cd ipfs-files
ipfs get /ipns/
ipfs add ./

If you add my example site and other IPFS sites to your ipfs node — you will help me and all InterPlanetary File System(IPFS) community!


To create multiple sites on your IPFS node — you can generate several named peerId. For example to add new dog site:

ipfs key gen --type=rsa --size=2048 dog-site
ipfs add ./my-dog-site
ipfs name publish --key=dog-site <hash of dog folder>

Follow me on twitter:

Also, Read



Coinmonks ( is a non-profit Crypto Educational Publication. Follow us on Twitter @coinmonks and Our other project —, Email  —

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store