IPFS - ArchWiki

# IPFS

From ArchWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Related articles

Daemons

From the IPFS README.md on GitHub:

  IPFS (the InterPlanetary File System) is a new hypermedia distribution protocol, addressed by content and identities. IPFS enables the creation of completely distributed applications. It aims to make the web faster, safer, and more open.

  IPFS is a distributed file system that seeks to connect all computing devices with the same system of files. In some ways, this is similar to the original aims of the Web, but IPFS is actually more similar to a single BitTorrent swarm exchanging git objects.

## Installation

Install the go-ipfs package or the go-ipfs-gitAUR package.

To start using IPFS you must first issue

    $ ipfs init

as a user. This creates a `~/.ipfs` directory with all the necessary files in it.

Now you can start the IPFS daemon:

    $ ipfs daemon

This starts your node, available via the `ipfs` cli, or the web interface on localhost:5001/webui. Additionally, a local gateway goes up on localhost:8080 (the default port can be changed in `~/.ipfs/config`).

## Using a service to start the daemon

For convenience, you can automate the startup of the IPFS daemon using the Systemd/User service included in go-ipfs. This ensures that the daemon starts when you log in and that it is restarted if it crashes.

You can enable and start the service unit with:

    $ systemctl --user enable --now ipfs.service

If you want the service to always run regardless of the user session status, enable the system-wide service instead:

    # systemctl enable --now ipfs@username.service

## File sharing

To share a file using IPFS you need the daemon to be running.

    $ ipfs add file

returns a hash. If someone shared this file via IPFS before, the hash would match that previous upload, making you the second source of the file.

To retrieve a file via the IPFS hash, use `ipfs cat`:

    $ ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme

You can pipe this into any other application, for example, to watch a video with mpv:

    $ ipfs cat QmWenbjgZnA6UguLtmUYayS6e7UQM7woB15zuEymSRRMoi | mpv -

Or you can download the file:

    $ ipfs get QmWenbjgZnA6UguLtmUYayS6e7UQM7woB15zuEymSRRMoi

There is also an ipgetAUR utility, which acts like wget for IPFS. In addition it includes a bootstrap node, so you will not have to have ipfs daemon running or installed in order to use it. To download a file:

    $ ipget QmWenbjgZnA6UguLtmUYayS6e7UQM7woB15zuEymSRRMoi

You can share both files and folders. Folders should be shared recursively:

    $ ipfs add -r folder

To view all the files and caches in a folder (if hash is a folder):

    $ ipfs ls QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG

Every file shared with network is accessible via the IPFS gateway on `localhost:8080` like this:

    http://localhost:8080/ipfs/QmWenbjgZnA6UguLtmUYayS6e7UQM7woB15zuEymSRRMoi

There are public gateways, allowing users with no IPFS node running to access files on the network. For example, the official website:

    https://ipfs.io/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG

## Simple hosting with name resolution

In IPFS, files shared are never deleted, and with any change of a file its hash changes as well. This makes tasks such as website hosting difficult, as any changes to a webpage, for example to an `index.html`, would result in it having a different hash, and the old webpage would be still accessible from the old hash. It is one of a network's goals to store all the content persistently with full history. IPFS offers a name service you can use to generate persistent caches - IPNS. IPNS allows you to bind any hash to your node's unique ID, generated at initialization. You can view your ID like this:

    $ ipfs id

And to bind any hash to it:

    $ ipfs name publish HASH

This assigns the new hash generated by `ipfs add` after the file change to your node ID, and hence makes the updated version of a folder/file accessible at the same address.

Note that when using IPNS the address has an `ipns` prefix instead of `ipfs`:

     http://localhost:8080/ipns/QmPtMQErTfQMbZTMMpQh65cpk5y7D94WdYJurCeRqvXKmD/

## See also

- IPFS homepage
- IPFS examples
- Awesome IPFS
- IPFS and pacman
- Arch Linux repository on IPFS

Categories:

- Clustered file systems
- Peer-to-peer