What is this random open port?

Every time I initialize the ipfs daemon I see a random port opened in my swarm addresses using my external ip.

Swarm announcing /ip4/191.180.124.121/tcp/37710

What is that for?

Thank you!

The default port for making connections should be 4001, so I’m guessing something changed it from the default to 37710.

What does ipfs config show give for the “Addresses” section?

"Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Announce": [],
    "Gateway": "/ip4/127.0.0.1/tcp/8080",
    "NoAnnounce": [],
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001"
    ]
  },

My config is bellow:

  "Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Announce": [],
    "Gateway": "/ip4/127.0.0.1/tcp/8080",
    "NoAnnounce": [],
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001"
    ]
  },

Every time I start the ipfs daemon I get a random port.

Now for example, I had started the daemon again an get port 20298

Swarm announcing /ip4/191.180.XXX.XXX/tcp/20298

This is the output when I start the daemon.

Initializing daemon...
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.0.7/tcp/4001
Swarm listening on /ip6/2804:14c:138:9124:10a0:ea1c:b4e5:883/tcp/4001
Swarm listening on /ip6/2804:14c:138:9124:9d69:7dbe:a603:8c05/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmXKPVNkWsLmTMXQtxtmiUj37vv61nceiGzPPq4tdC351k
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.0.7/tcp/4001
Swarm announcing /ip6/2804:14c:138:9124:10a0:ea1c:b4e5:883/tcp/4001
Swarm announcing /ip6/2804:14c:138:9124:9d69:7dbe:a603:8c05/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

Doesn’t even list my external ip address.

I think this should be related I’m behind a NAT.

Could someone confirm that?

If I don’t get the port 4001 open for the world anyone can find my node right?

Is that any workaround?

Thank you!

NAT traversal would make sense. I tried finding some more details on how IPFS uses it and if there are any configuration options, but I wasn’t finding much.

My understanding is that if you have UPnP enabled you shouldn’t need to manually open any ports. If not, then you’ll probably need to open 4001 in your firewall.

Maybe the 4001 port already in use.

if 4001 already in use, ipfs will select a random port to dial