The InterPlanetary File System (IPFS) is a peer-to-peer protocol that changes how we address data: from Location Addressing (where the server is) to Content Addressing (what the data is).

Learning Objectives

  • Understand content-addressed storage vs. location-addressed storage.
  • Interact with a peer-to-peer distributed file system.
  • Explore immutable data and mutable pointers.

Prerequisites

  • Linux or macOS environment.
  • IPFS CLI (Kubo) installed.

Step 1: Initialization

  1. Install Kubo:
# Download from https://dist.ipfs.tech/#kubo
# Extract and run the install script
sudo ./install.sh
ipfs --version
  1. Initialize your node:
ipfs init

Note your PeerID - this is your unique identity in the global swarm.

  1. Start the daemon: In a separate terminal window, start the connection to the global network.
ipfs daemon

Step 2: Content Addressing

In traditional storage, you access myserver.com/image.jpg. In IPFS, you access data by its hash (CID).

  1. Create a sample file:
echo "Hello from Decentralized Storage!" > welcome.txt
  1. Add it to IPFS:
ipfs add welcome.txt

Take note of the string starting with Qm... (the CID).

  1. Demonstrate Immutability: Change one character in welcome.txt and add it again.
echo "Hello from Decentralized Storage." > welcome.txt
ipfs add welcome.txt

Analysis: Notice how the CID is completely different. In IPFS, if the content changes, the address changes.


Step 3: Global Retrieval

Because IPFS is peer-to-peer, once you add a file and your daemon is running, other nodes can request it from you.

  1. Retrieve locally:
ipfs cat <YOUR_CID>
  1. Retrieve via Gateway: Open your browser and go to https://ipfs.io/ipfs/<YOUR_CID>. It might take a minute for the global network to "find" your local node.

Step 4: Pinning & Garbage Collection

IPFS nodes don't keep data forever unless it is "pinned". Unpinned data is subject to deletion when the cache is full.

  1. Check pins:
ipfs pin ls --type recursive

Your welcome.txt was automatically pinned when you added it.

  1. Unpin and Clean:
ipfs pin rm <YOUR_CID>
ipfs repo gc

The data is now removed from your local storage.


Step 5: Mutable Pointers (IPNS)

Since CIDs change every time a file is updated, how do we share a link to a "website" that changes? We use IPNS.

  1. Publish a CID to your PeerID:
ipfs name publish <YOUR_CID>
  1. Access via IPNS: https://ipfs.io/ipns/<YOUR_PEER_ID> Now, even if you update the file and get a new CID, you can re-publish it to the same PeerID, and the link remains the same.

Lab Reflection

  1. Why does content-addressing automatically deduplicate data in a global system?
  2. What are the privacy implications of your data being "globally accessible" by its CID?
  3. How does IPFS differ from a traditional CDN (Content Delivery Network)?