How to setup an IPFS Private network on GCloud and Local

Indie Dev
4 min readNov 15, 2021

Recently, I did some researches about the decentralize storage. I figured out some cool stuff about this. Therefore, I decided to setup an IPFS private network to share files between my group members.

De-cen-tra-lize ! (Image from Canva.com)

What is IPFS?

A peer-to-peer hypermedia protocol designed to preserve and grow humanity’s knowledge by making the web upgradeable, resilient, and more open.
From https://ipfs.io/

Some properties:

  • Peer to peer, decentralized and distributed file system
  • CDN
  • Fault tolerant with zero downtime
  • Content Address (Not Location Address)
  • Cencorship resistant

Step by step to setup IPFS Private network on GCloud VM

We will use this VM as a bootstrap node to start the private network. Generating swarm keys will be happened in this VM. And we will copy it into another machines.

Swarm key allows us to make sure only network peers which are shared this private key , can be communicate together.

So how to create a swarm key? Follow the next part of article.

First we need to setup a new VM Instance with Gcloud Console. The basic configuration for a VM is ok.

Scroll down and Click Create after filling necessary information

Waiting 1–2 minutes, the VM will be created. Then we will SSH to it.

Follow these step to setup on Gcloud VM — We can leave the “Add Peers” step laters

Now we will run it.

Tada …

Now we need to setup a firewall rule to public 4001 port to the world. Then other peers can connect to this one.

Click here to go to the Firewall setup
  • Fill your firewall rule name
  • Select “Targets” as “Specified target tags”
  • Create your Target Tags “allow-4001” (or something else that you like) — we will use this tag to tag our VM
  • Source IP/V4 Ranges “0.0.0.0/0” (be careful with this one — use this for a demo is fine)
  • Select “Specified protocols and ports” (tcp: 4001)

Click “Create” to create your rule

Tada — here is our result

Update your VM with this tag

Ok so far so good now.

Setup IPFS on your local — your first peer

  • The same script above, but we will copy the swarm key from the VM to our “~/.ipfs/swarm.key”
  • Back to the VM, we will get the public IP of the VM. We will use this to add to our local Node
Go to your VM, you will see this.
  • SSH to VM, execute the below command to get the PeerId of the Node on VM.
IPFS_PATH=~/.ipfs ipfs config show | grep "PeerID"
-> "PeerID": "YOUR NODE PEER ID here"
  • On your local, execute below commands to add the VM peer
IPFS_PATH=~/.ipfs ipfs bootstrap add /ip4/<public IP of VM>/tcp/4001/ipfs/<VM NodePeer identity>
  • Run daemon

Update VM’s peer by using the Local Peer Id

  • Use the same process to get the Local Peer Id and add to the VM Node

Ready to Go

I am going to wrap everything up. The below picture is my last Saturday!

I hope that this article will help you guys a little bit and get the concept how to setup the private network.

Sorry for any bad expressions and not clear idea.

Thanks for your reading.

--

--