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
- Install Kubo:
# Download from https://dist.ipfs.tech/#kubo
# Extract and run the install script
sudo ./install.sh
ipfs --version
- Initialize your node:
ipfs init
Note your PeerID - this is your unique identity in the global swarm.
- 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).
- Create a sample file:
echo "Hello from Decentralized Storage!" > welcome.txt
- Add it to IPFS:
ipfs add welcome.txt
Take note of the string starting with Qm... (the CID).
- Demonstrate Immutability: Change one character in
welcome.txtand 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.
- Retrieve locally:
ipfs cat <YOUR_CID>
- 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.
- Check pins:
ipfs pin ls --type recursive
Your welcome.txt was automatically pinned when you added it.
- 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.
- Publish a CID to your PeerID:
ipfs name publish <YOUR_CID>
- 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
- Why does content-addressing automatically deduplicate data in a global system?
- What are the privacy implications of your data being "globally accessible" by its CID?
- How does IPFS differ from a traditional CDN (Content Delivery Network)?