There are two types of IPFS networks: public and private. All files in the public IPFS network are accessible to everyone. Since most business applications, especially enterprise solutions, require full control over their data, making their networks publicly available is not an option. This is where IPFS privacy features could help close the network for certain entities.
In this IPFS tutorial, we will go through the process of creating a private IPFS network.
IPFS: A protocol and network designed to create a content-addressable, peer-to-peer method of storing and sharing hypermedia in a distributed file system. Read more
Private IPFS: Allows IPFS to only connect to other peers who have a shared secret key. With IPFS private networks, each node specifies which other nodes it will connect to. Nodes in that network don’t respond to communications from nodes outside that network. Read more
By default, IPFS use the following ports:
IPFS
4001 – Communication with other nodes
5001 – API server
8080 – Gateway server
-
First we have to create 3 virtual machines, so for this we can use 3 different machines or DIgitalocean.
-
In my case I am using Digitalocean, so for this go to https://www.digitalocean.com/ and register your self.
-
Once registered new project will be created automatically.
-
Now for creating virtual machines we have to click on create and select droplet.
-
In this tutorial we are using Ubuntu machine with version 22.10 x64.
-
Choose type and CPU as per need.
-
For authentication click on password and create a new password.
-
Now we need three nodes node-00 which will be our bootstrap node, node-01 and node-02. So click on + icon to increase the number of droplets and name it accordingly as per your preference.
-
Click on create droplet.
-
All the droplet will be created.
-
Now we have to access VM via CMD (command line) so for this, click on node-00 and statistics about node 00 will be displayed, make sure node-00 is turn on and it’s running if in your case it is off then toggle the button to turn on. Now click on console.
-
In the same way open console for all the nodes.
-
Now perform the following steps.
-
Download the Linux binary from (https://dist.ipfs.tech/#kubo).
wget https://dist.ipfs.tech/kubo/v0.16.0/kubo_v0.16.0_linux-amd64.tar.gz
-
Unzip the file:
tar -xvzf kubo_v0.16.0_linux-amd64.tar.gz
-
Move into the
kubo
folder and run the install script:cd kubo
sudo bash install.sh
-
Test that IPFS has installed correctly:
ipfs --version
-
Now type:
nano /usr/lib/systemd/system/ipfsd.service
-
Now paste following code inside ipfsd.service:
[Unit] Description=ipfs daemon [Service] ExecStart=/usr/local/bin/ipfs daemon Restart=always User=root Group=root [Install] WantedBy=multi-user.target
-
Now press
ctrl+x
to exit -
Once done initialize IPFS in all node by:
ipfs init
-
Remove bootstrap from all nodes:
ipfs bootstrap rm --all
-
Now change IPFS configuration as follows:
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080 ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 ipfs config show
-
Force to private network:
export LIBP2P_FORCE_PNET=1
-
Restart IPFS daemon:
systemctl restart ipfsd
-
Check status:
systemctl status ipfsd
-
Perform step 14 to 26 in all three node.
-
Done, now check id of bootstrap node (node-00):
ipfs id
-
Copy id of path of bootstrap node (node-00) followed by IP address. In my case id is,
/ip4/164.92.65.166/udp/4001/quic/p2p/12D3KooWCkbu1irMu5651hvDEMQuwK6kLfiJCqpRTnD2az7DjtSz
-
Now execute below command in other nodes:
ipfs bootstrap add /ip4/ipaddress/udp/4001/quic/p2p/peerid
-
Now run following script in bootstrap node (node-00) to see list of all peers:
ipfs swarm peers
-
Now our IPFS private network has created, for test let’s add a txt file from node-01 and will try to access it inside node-02 and node-00.
-
For creating file run following script in node-01:
echo "IPFS P2P NETWORL (node-01)" > info.txt
-
Add info.txt in IPFS network by using following command:
ipfs add info.txt
-
Copy the generated hash for accessing file in node-02 uploaded from node-01.
-
Now in node-02 run the following command:
ipfs cat QmeHE2NBWN4N33uW1Ncsc5TDqy4kuK1YuEwMpXcZq37SHr
-
We can successfully see the contents of file which was uploaded from node-01.
-
Same way can see the content in node-00 also.