Creating a private IPFS Network

Shaikh Danish
2 min readAug 28, 2019

--

The InterPlanetary File System or IPFS is a protocol and peer-to-peer network for storing and sharing hypermedia in a distributed file system somewhat like torrent.

In a default installation of IPFS, it connects you to a global distributed network. But, There are cases where you don’t want your data to be accessible to the global network, In this scenario, private IPFS network is the best choice.

To create the private IPFS network, We follow certain steps which are mentioned below:

Note : We will use ubuntu machines for the sake of example.

  1. You should have at least 2 ubuntu machines which can ping each other.
  2. Initializing Nodes
    1. Install IPFS on both the machines, you can take the help of below link to install IPFS:
    https://docs.ipfs.io/guides/guides/install/
    2. Initialize the nodes on both the machines using the command :
    ipfs init
  3. Creating a private network

For this example, we are using 2 nodes, a Bootstrap node and a client node.

The bootstrap node is an IPFS node that other nodes can connect to in order to find other peers.

1. We will create a swarm key, this key will be referenced by all the nodes in the network(Private network). To create a swarm key, you can use the below command :

echo -e “/key/swarm/psk/1.0.0/\n/base16/\n `tr -dc ‘a-f0–9’ < /dev/urandom | head -c64`” > ~/.ipfs/swarm.key

2. In the default way, the public bootstrap node is used which we don’t want. So, we would remove all the default entries from the config using command :

ipfs bootstrap rm — all

3. Now, add the IP address and Peer identity of Bootstrap node to each of the nodes including the bootstrap node itself. This can be done using the below command:

ipfs bootstrap add /ip4/<ip address of bootnode>/tcp/4001/ipfs/<peer identity hash of bootnode>

4. Start the Network

Start the daemon on both the nodes using below commands:
1. export LIBP2P_FORCE_PNET=1
2. ipfs daemon

5. Now, try uploading the file on one server and try to access it from the other.

To add the file you can use the command:
ipfs add file.txt
This will give you the unique hash of the file added.

You can retrieve the file on the other server on browser as well using:
localhost:8080/ipfs/yourHash.

Congrats!!! You have successfully created the private IPFS network.

This concludes the tutorial.

Thanks,
Shaikh Danish

--

--