Private network in IPFS

Welcome again developers,


In this article we will see how to setup a private  IPFS network in an Ubuntu machine/System. we will go step by step in this article if you did not saw our Intro to IPFS  and  public IPFS network  we recommend  to see this first.
In this we setup a private IPFS network.

Note :
           * for this we need two ubuntu system connected to a same network (LAN/WiFi).
           * select one system as a bootstrap node and another as client node.
           *follow step 1 and step 2 in both the system as it is.
step 1. Install go


 * download go zip file from there official website https://golang.org/dl/ 













* Create a new folder, then copy the downloaded file into this folder.


















 * open terminal in current directory ("the directory which we created 'work folder' ")


* type "  sudo tar -C /usr/local -xzf go1.12.7.linux-amd64.tar.gz  " : this command will extract the file into the /usr/local folder, Note: in our case we have go1.12.7.linux-amd64.tar.gz file if you have any different version then use that file name instead of go1.12.7.linux-amd64.tar.gz.


* type  "  export PATH=$PATH:/usr/local/go/bin  " : the export command marks an environment variable to be exported with any newly forked child processes, in this line $PATH variable will be updated with new value /usr/local/go/bin/ .


* type "  source $HOME/.profile  " : source command will bring the given file into the shell script , in this .profile will be loaded in current shell script .


* type " go version  " :  to check the go version.






step 2 : Install IPFS


* open terminal in current directory " work folder ".


* type " sudo apt-get update ".




* go to official website of IPFS by clicking here then right click on download button and copy the address .


* in terminal type "  wget  paste_the_copied_URL  " : this will download a zip file in current directory.



* type " ls " to see the downloaded file.


* type " tar xvfz downloaded_file_name " : this will unzip file.








* type " sudo  mv  go-ipfs/ipfs  /usr/local/bin/ipfs " : this command will move the ipfs file from current directory to /usr/local/bin/ipfs.


* clean unnecessary files and folders : type : " sudo rm -rf go-ipfs " .


* type : " ipfs version  " : for checking the ipfs version installed .



* type : " ipfs init " :  we need to initialize the ipfs file, it required once at the time of installation after this we not need to run this command again. This command will return a peer ID which is a unique identification of each peer.






step 3 : creating Swarm.key

Note : follow this commands only in bootstrap node.

*  to make our network private we need to use a key, peers need this key for joining the network.

* we will generate key from our bootstrap node then copy the generated key to all client system.

* to generate a key we will use a key generator.

* type " sudo apt-get install git " : this will install git in your system.

* type " go get -u github.com/kubuxu/go-ipfs-swarm-key-gen/ipfs-swarm-key-gen "
"

* type  "  ~/go/bin/ipfs-swarm-key-gen > ~/.ipfs/swarm.key " : this will create a swarm key to the ipfs folder.




* copy the generated swarm.key from .ipfs folder into the pendrive and paste into the client system in .ipfs folder.



step 4 : setting up nodes.

Note : follow this commands on both bootstrap node as well as in client node.

* type " sudo config show  " : with this we can check the current connected  nodes.



* type " ipfs bootstrap rm --all " : this will remove all existing nodes.


* type : " ipfs config show " : now check bootstrap node .


* now we need to set IP and peer ID of bootstrap node to all nodes ( bootstrap + clients )

*  (only for bootstrap node )  IN bootstrap node first get the IP by typing " hostname -I " and peer ID by ' ipfs config show | grep "PeerID"    '


* now put your IP and peerID in this command " ipfs bootstrap add /ip4/your_IP/tcp/4001/ipfs/PeerID_of_bootstrap_node " the run.


* now for all client node we not need to find IP and peerID just run same command with same value of bootstrap node.   command : " ipfs bootstrap add /ip4/bootstrap_node_IP/tcp/4001/ipfs/PeerID_of_bootstrap_node ".

step 5 : establishing network and deploying file to it.

* now we successfully added the swarm.key and sets the bootstrap node IP to all nodes.

*(On both, bootstrap node and in client node ) for starting a private network we need to type : " export LIBP2P_FORCE_PNET=1 ": it will forcibly makes the network private

* (On both, bootstrap node and in client node ) now start the daemon : type : " ipfs daemon " after this leave this terminal as it is.



* (On both, bootstrap node and in client node ) open new terminal .

* now we add a file from one node and then access it from another node, choose a node for creating/deploying file and another for accessing.

*create a folder( "project" ) then create a new text file ("first.txt") in the folder save the text file with some content ( "hello world").









* type : " ifps swarm peers " : this command will show connected peer


* type : " ls "  check your file in your current folder.


* type " ipfs add filename.extensionName " eg . " ipfs add first.txt " :

this will add file to the ipfs network and return the hash value for accessing this file data.


a*  copy the returned hash value and type : " ipfs cat paste_hash " : this will output the content of file .

   * now paste this same command in another node for accessing the content  " ipfs cat paste_hash "




b* publish your file over the network : type : " ipfs name publish paste_hash" : this will publish your file over the network and return a string like this "ipfs/your_hash_value" then copy this value.




c* open your browser and type " localhost:8080/paste_value_here" eg : 'localhost:8080/ipfs/hashValue'
 
* copy same URL in another node for accessing this content



We successfully establish a private network.

--------------------------------------------------------------------------------------------------------------------------

Thanks for reading this article in future posts we are going to play with ipfs commands.



Comments

Popular posts from this blog

Intro to IPFS

How to setup a IPFS network in Ubuntu