# How to set up my own bootstrap nodes to enable discovery and connection between nodes with public IP and nodes on a local network?

**URL:** <https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910>\
**Category:** Help\
**Tags:** dht\
**Created:** [September 6, 2023, 6:04am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910 "2023-09-06T06:04:58Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 6, 2023, 6:04am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/1 "2023-09-06T06:04:58Z")

</div>

My private IPFS setup:  
All nodes mentioned below are using the dht package I forked from the official project. The current address for the dht package in my project is `https://github.com/pabcxyz/go-libp2p-kad-dht`, and I only modified the value of the `DefaultPrefix` from “/ipfs” to “/signipfs”.

1. Node A - I removed all the default bootstrap nodes and set Node A as the bootstrap node. It has a public IP. The code used for the bootstrap node is `https://github.com/BenDerPan/simple-bootstrap-node`.
2. Nodes B and C - I removed all the default bootstrap nodes and added Node A as the bootstrap node. They have public IP.
3. Nodes D and E - I removed all the default bootstrap nodes and added Node A as the bootstrap node. These nodes are on a local network.

Observation: By running nodes 2 and 3, I have confirmed that nodes 2 and 3 can discover and connect to each other. The two nodes in node 2 can discover and connect successfully, as well as the two nodes in node 3. However, when the nodes in node 2 try to connect to the nodes in node 3 or vice versa, the following error occurs: `QmThEh1WhwspRaKuwc6AwH2hJPbEyk6BiX4veMAGV8mQfw,err:failed to dial: failed to dial QmThEh1WhwspRaKuwc6AwH2hJPbEyk6BiX4veMAGV8mQfw: all dials failed

- [/ip4/172.16.1.121/tcp/4004] dial backoff
- [/ip4/127.0.0.1/tcp/4004] dial tcp4 127.0.0.1:4004: connect: connection refused`. However, if I don't modify the value of `DefaultPrefix` and use the default bootstrap nodes, node 2 can discover and connect to the nodes in node 3, and vice versa.

Question 1: How can I set up my own bootstrap nodes so that the nodes in node 2 and node 3 can discover and connect to each other successfully?

---

<div class="post-metadata">

**Author:** ![guissou](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/guissou/32/7915_2.png) [@guissou](https://discuss.ipfs.tech/u/guissou)\
**Post date:** [September 6, 2023, 7:18am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/2 "2023-09-06T07:18:42Z")

</div>

It seems to be a connectivity problem rather than a problem with the `protocol.ID` / `DefaultPrefix`.

In your setup, nodes 3 should always be able to reach nodes 2. However, nodes 2 can have a hard time to establish a connection to nodes 3, because nodes 3 are on a local network and are probably behind a NAT. [libp2p NAT hole punching doesn’t have a success rate of 100%](https://github.com/plprobelab/network-measurements/blob/master/results/rfm15-nat-hole-punching.md), which may be a reason why the dials failed.

It is possible that dials succeed more in the “public IPFS DHT” because there are nodes running the [libp2p relay protocol](https://github.com/libp2p/specs/tree/master/relay) facilitating connections to nodes behind a NAT.

So your problem probably doesn’t come from the DHT implementation, but rather from the DHT network which doesn’t include Relay nodes.

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 6, 2023, 7:44am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/3 "2023-09-06T07:44:52Z")

</div>

Thank you for your quick response. What should I do to achieve the ‘public IPFS DHT’ effect? Is there any similar code available? I’ve noticed that there are many people with similar questions, but there are few solutions. Could you please provide the code or solution for the bootstrap nodes in ‘public IPFS DHT’?

---

<div class="post-metadata">

**Author:** ![guissou](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/guissou/32/7915_2.png) [@guissou](https://discuss.ipfs.tech/u/guissou)\
**Post date:** [September 6, 2023, 8:09am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/4 "2023-09-06T08:09:24Z")

</div>

I suggest that your nodes 2 should be [libp2p Relays](https://docs.libp2p.io/concepts/nat/circuit-relay/), in order to allow communication to nodes 3.

However, I am not sure on how to make sure that `circuitv2` (relay protocol) is enabled. The best place to get this question answer is [https://discuss.libp2p.io/](https://discuss.libp2p.io/)

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 6, 2023, 8:28am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/5 "2023-09-06T08:28:02Z")

</div>

Can I handle the relay processing within Node A, the bootstrap node, for a solution similar to ‘public IPFS DHT’?Instead of Node B or Node C.

---

<div class="post-metadata">

**Author:** ![guissou](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/guissou/32/7915_2.png) [@guissou](https://discuss.ipfs.tech/u/guissou)\
**Post date:** [September 6, 2023, 8:35am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/6 "2023-09-06T08:35:13Z")

</div>

Yes, you could. However, if you plan on running a large network, you probably don’t want to rely on a single relay. To share the load all nodes with a public address can act as relays (so A, B and C in your example).

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 6, 2023, 8:39am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/7 "2023-09-06T08:39:37Z")

</div>

Thank you for your response. Next, I will attempt to fix my bootstrap node code.

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 6, 2023, 9:36am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/8 "2023-09-06T09:36:09Z")

</div>

I’m sorry for taking up more of your time. Currently, I’m working on implementing relay functionality in my bootstrap node. However, in my bootstrap node program, I can only obtain their peer.ID. How can I proceed?

---

<div class="post-metadata">

**Author:** ![guissou](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/guissou/32/7915_2.png) [@guissou](https://discuss.ipfs.tech/u/guissou)\
**Post date:** [September 6, 2023, 9:44am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/9 "2023-09-06T09:44:25Z")

</div>

I am not familiar with configuring relays in libp2p, however you can ask for help at [https://discuss.libp2p.io/](https://discuss.libp2p.io/)

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 7, 2023, 10:01am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/10 "2023-09-07T10:01:24Z")

</div>

I posted a thread on [discuss.libp2p.io](https://discuss.libp2p.io), but it has been in the ’ pending’ status for a while. Sorry to bother you again, is there any method to determine if a node is behind NAT?

---

<div class="post-metadata">

**Author:** ![guissou](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/guissou/32/7915_2.png) [@guissou](https://discuss.ipfs.tech/u/guissou)\
**Post date:** [September 7, 2023, 3:03pm UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/11 "2023-09-07T15:03:49Z")

</div>

The [AutoNAT](https://docs.libp2p.io/concepts/nat/autonat/) protocol helps your node discover whether it is behind a NAT.

---

<div class="post-metadata">

**Author:** ![ldhios](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/ldhios/32/7956_2.png) [@ldhios](https://discuss.ipfs.tech/u/ldhios)\
**Post date:** [September 14, 2023, 9:53am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/12 "2023-09-14T09:53:17Z")

</div>

hi ，I have the same problem. Do you have a final solution

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 15, 2023, 8:09am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/13 "2023-09-15T08:09:09Z")

</div>

sorry, there is currently no solution available.

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 15, 2023, 8:13am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/14 "2023-09-15T08:13:49Z")

</div>

Are you also trying to do the same thing as me?

---

<div class="post-metadata">

**Author:** ![ldhios](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/ldhios/32/7956_2.png) [@ldhios](https://discuss.ipfs.tech/u/ldhios)\
**Post date:** [September 15, 2023, 8:14am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/15 "2023-09-15T08:14:28Z")

</div>

yes,are your in china?

---

<div class="post-metadata">

**Author:** ![ldhios](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/ldhios/32/7956_2.png) [@ldhios](https://discuss.ipfs.tech/u/ldhios)\
**Post date:** [September 15, 2023, 8:16am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/16 "2023-09-15T08:16:37Z")

</div>

> <https://github.com/ipfs/kubo/issues/7067>
>
> \#### Version information:
> \`\`\`
> ipfs version --all
> go-ipfs version: 0.4.23-6ce9…a35
> Repo version: 7
> System version: amd64/darwin
> Golang version: go1.13.8
> \`\`\`
> 
> config file. Enabled AutoNAT. Also enabled quic.
> \`\`\`
> {
> "Identity": {
> "PeerID": "QmatWUFpQZo1ZUb7tvhQom8tA8QutiPby9uaeuWf7qbRcx",
> "PrivKey": "XXX"
> },
> "Datastore": {
> "StorageMax": "10GB",
> "StorageGCWatermark": 90,
> "GCPeriod": "1h",
> "Spec": {
> "mounts": \[
> {
> "child": {
> "path": "blocks",
> "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
> "sync": true,
> "type": "flatfs"
> },
> "mountpoint": "/blocks",
> "prefix": "flatfs.datastore",
> "type": "measure"
> },
> {
> "child": {
> "compression": "none",
> "path": "datastore",
> "type": "levelds"
> },
> "mountpoint": "/",
> "prefix": "leveldb.datastore",
> "type": "measure"
> }
> \],
> "type": "mount"
> },
> "HashOnRead": false,
> "BloomFilterSize": 0
> },
> "Addresses": {
> "Swarm": \[
> "/ip4/0.0.0.0/tcp/4001",
> "/ip6/::/tcp/4001"
> \],
> "Announce": \[\],
> "NoAnnounce": \[\],
> "API": "/ip4/127.0.0.1/tcp/5001",
> "Gateway": "/ip4/127.0.0.1/tcp/8080"
> },
> "Mounts": {
> "IPFS": "/ipfs",
> "IPNS": "/ipns",
> "FuseAllowOther": false
> },
> "Discovery": {
> "MDNS": {
> "Enabled": true,
> "Interval": 10
> }
> },
> "Routing": {
> "Type": "dht"
> },
> "Ipns": {
> "RepublishPeriod": "",
> "RecordLifetime": "",
> "ResolveCacheSize": 128
> },
> "Bootstrap": \[
> "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
> "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
> "/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
> "/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
> "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
> "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
> "/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
> "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
> "/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
> "/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
> "/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
> "/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
> "/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd"
> \],
> "Gateway": {
> "HTTPHeaders": {
> "Access-Control-Allow-Headers": \[
> "X-Requested-With",
> "Range",
> "User-Agent"
> \],
> "Access-Control-Allow-Methods": \[
> "GET"
> \],
> "Access-Control-Allow-Origin": \[
> "\*"
> \]
> },
> "RootRedirect": "",
> "Writable": false,
> "PathPrefixes": \[\],
> "APICommands": \[\],
> "NoFetch": false
> },
> "API": {
> "HTTPHeaders": {}
> },
> "Swarm": {
> "AddrFilters": null,
> "DisableBandwidthMetrics": false,
> "DisableNatPortMap": false,
> "DisableRelay": false,
> "EnableRelayHop": false,
> "EnableAutoRelay": false,
> "EnableAutoNATService": true,
> "ConnMgr": {
> "Type": "basic",
> "LowWater": 600,
> "HighWater": 900,
> "GracePeriod": "20s"
> }
> },
> "Pubsub": {
> "Router": "",
> "DisableSigning": false,
> "StrictSignatureVerification": false
> },
> "Reprovider": {
> "Interval": "12h",
> "Strategy": "all"
> },
> "Experimental": {
> "FilestoreEnabled": false,
> "UrlstoreEnabled": false,
> "ShardingEnabled": false,
> "Libp2pStreamMounting": false,
> "P2pHttpProxy": false,
> "QUIC": true,
> "PreferTLS": false
> }
> }
> 
> \`\`\`
> 
> \#### Description:
> 
> According to bug 6251, AutoNAT should work when using a swarm key. However, I don't see this happening.
> 
> \`\`\`
> LIBP2P\_FORCE\_PNET=1 ipfs daemon                                                            
> Initializing daemon...                                                                                                                         
> go-ipfs version: 0.4.23-6ce9a35                                                                                                                
> Repo version: 7                                                                                                                                
> System version: amd64/darwin                                                                                                                   
> Golang version: go1.13.8                                                                                                                       
> Swarm is limited to private network of peers with the swarm key                                                                                
> Swarm key fingerprint: d4574a64137198e7c6c8366f77e37e46                                                                                        
> Swarm listening on /ip4/127.0.0.1/tcp/4001                                                                                                     
> Swarm listening on /ip4/192.168.0.98/tcp/4001                                                                                                  
> Swarm listening on /ip6/::1/tcp/4001                                                                                                           
> Swarm listening on /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001                                                                                     
> Swarm listening on /ip6/fd01::39c2:943c:4774:db16/tcp/4001                                                                                     
> Swarm listening on /p2p-circuit                                                                                                                
> Swarm announcing /ip4/127.0.0.1/tcp/4001
> Swarm announcing /ip4/192.168.0.98/tcp/4001
> Swarm announcing /ip6/::1/tcp/4001
> Swarm announcing /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
> Swarm announcing /ip6/fd01::39c2:943c:4774:db16/tcp/4001
> API server listening on /ip4/127.0.0.1/tcp/5001
> WebUI: http://127.0.0.1:5001/webui
> Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
> Daemon is ready
> \`\`\`
> 
> Whereas when I don't use swarm key, I see the NAT traversal happening.
> 
> \`\`\`
> ipfs daemon         
> Initializing daemon...
> go-ipfs version: 0.4.23-6ce9a35
> Repo version: 7
> System version: amd64/darwin
> Golang version: go1.13.8
> Swarm listening on /ip4/127.0.0.1/tcp/4001
> Swarm listening on /ip4/192.168.0.98/tcp/4001
> Swarm listening on /ip6/::1/tcp/4001
> Swarm listening on /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
> Swarm listening on /ip6/fd01::39c2:943c:4774:db16/tcp/4001
> Swarm listening on /p2p-circuit
> Swarm announcing /ip4/106.51.29.204/tcp/21683 =\> The public IP announced
> Swarm announcing /ip4/127.0.0.1/tcp/4001
> Swarm announcing /ip4/192.168.0.98/tcp/4001
> Swarm announcing /ip6/::1/tcp/4001
> Swarm announcing /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
> Swarm announcing /ip6/fd01::39c2:943c:4774:db16/tcp/4001
> API server listening on /ip4/127.0.0.1/tcp/5001
> WebUI: http://127.0.0.1:5001/webui
> Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
> Daemon is ready
> \`\`\`
> 
> Please try to include:
> \* What you were doing when you experienced the bug.
> \* Any error messages you saw, \*where\* you saw them, and what you believe may have caused them (if you have any ideas).
> \* When possible, steps to reliably produce the bug.
> \--\>
> I was using an older version to get this feature working for p2p file sharing. I tried updating to the latest public release and still doesn't work. Let me know if you need any other information.

This problem indicates that tcp also supports nat over private networks

---

<div class="post-metadata">

**Author:** ![ldhios](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/ldhios/32/7956_2.png) [@ldhios](https://discuss.ipfs.tech/u/ldhios)\
**Post date:** [September 15, 2023, 8:21am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/17 "2023-09-15T08:21:57Z")

</div>

In this problem, some people also say that it is related to the number of boot nodes, and the number of three boot nodes is required

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discuss.ipfs.tech/u/andy)\
**Post date:** [September 16, 2023, 2:16am UTC](https://discuss.ipfs.tech/t/how-to-set-up-my-own-bootstrap-nodes-to-enable-discovery-and-connection-between-nodes-with-public-ip-and-nodes-on-a-local-network/16910/18 "2023-09-16T02:16:46Z")

</div>

Yes, you can contact me through WeChat,ID is:361663126
