How do I get a public IP address?

With IPFS JS when I run this:

const ipfsNode = await IPFS.create();
const addresses = await ipfsNode.swarm.localAddrs();
console.log(addresses);

I get this:

Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/PeeridFooBar
Swarm listening on /ip4/192.168.0.113/tcp/4002/p2p/PeeridFooBar
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/PeeridFooBar

But all of these are local/LAN addresses. How do I get a public ID so that from another node I can connect to this node over the internet like so: jsipfs swarm connect PUBLIC ADDRESS HERE?

Hi

I think you don’t need the public ip, the private ip should be enough, the part that really matters is the peer id

Hello @int

You can configure your public IP via libp2p config. Via js-ipfs, you can check this [example](https://github.com/ipfs/js-ipfs/tree/master/examples/custom-libp2p) on how to provide a custom config to libp2p. The goal here is to add your public IP to the announce` addresses of libp2p, so that other nodes know how to reach your node’s public address. After this, you setup nginx to forward from the public IP to the internal private IP of your node.

2 Likes