In the following guide, we will cover all the necessary steps to set up an IPFS node, enable a local HTTP gateway, add it to Media Network and then serve its content to end-users through it.
Installing IPFS node
Installing IPFS through the command-line is handy if you plan on building applications and services on top of an IPFS node. This method is also useful if you're setting up a node without a user interface, usually the case with remote servers or virtual machines. Using IPFS through the command-line allows you to do everything that IPFS Desktop can do, but at a more granular level since you can specify which commands to run.
IPFS requires 512MiB of memory and can run an IPFS node on a Raspberry Pi. However, how much disk space your IPFS installation takes up depends on how much data you're sharing. A base installation takes up about 12MB of disk space, and the default maximum disk storage is set to 10GB.
The IPFS team manages the dist.ipfs.io website to help users quickly find the latest version of every IPFS package. As soon as a new release of an IPFS package comes out, it is automatically shown on
dist.ipfs.io, so you can be sure you're getting the latest software. These steps detail how to download and install Go-IPFS 0.8.0 from
dist.ipfs.io using the command-line.
Install system tools
- Download the Linux binary
- Unzip the file
- Move into the go-ipfs folder and run the install script
- Check that IPFS installed
Initialize the repository
ipfs stores all its settings and internal data in a directory called the repository. Before using IPFS for the first time, you’ll need to initialize the repository with the
ipfs init command:
If you are running on a server in a data center, you should initialize IPFS with the
server profile. Doing so will prevent IPFS from creating a lot of data center-internal traffic trying to discover local nodes:
If you're running it on your personal computer you can initalize it with:
The hash after
peer identity: is your node’s ID and will be different from the one shown in the above output. Other nodes on the network use it to find and connect to you. You can run
ipfs id at any time to get it again if you need it.
Now, try running the command suggested to you in the output of
ipfs init. The one that looks like
ipfs cat /ipfs/<HASH>/readme.
You should see something like this:
Take your node online
Once you're ready to join your node to the public network, run the ipfs daemon in another terminal and wait for all three lines below to appear to know that your node is ready:
Make a note of the TCP ports you receive. If they are different, use yours in the commands below.
Now, switch back to your original terminal. If you’re connected to the network, you should be able to see the IPFS addresses of your peers when you run:
Adding files to IPFS
You can add any type of content to IPFS. In this case we will put some text content into a
.txt file called
mytextfile.txt and put the text
IPFS TEST - VERSION 1 in it.
You can read the file's contents using the cat command:
Save the hash that IPFS returned. This is the content's cryptographic hash. If the file's content changes, the hash will change, but if the file's content remains the same, the hash will always be the same.
Downloading files from IPFS
You can now try to download the file you've just uploaded to IPFS
How IPFS identifies files
IPFS tracks content based on its cryptographic hash. This hash uniquely identifies exactly that content. As long as the content stays the same, the hash stays the same, but if the content changes at all you will get a different hash. If you have two different files that contain identical content, IPFS will track that content with one hash. The filenames are different, but the content is the same, so the hash of the content will be identical.
Make your gateway public
By default, your IPFS HTTP gateway is not exposed to the world. It only works locally. Let's allow anyone in with this command to enable it on port 8080:
Please restart the IPFS daemon in order to changes to apply.
Accessing your HTTP Gateway
Check with curl command if IPFS HTTP gateway is accessible by trying to download the previously added
If everything works smoothly, you should get this:
You can now try to access
mytextfile.txt from a browser, replacing the IP with your own external one. It should look something like this:
Congrats! If your gateway is reachable, we're now ready to add it to Media Network.