ipfs/kubo · error

address does not contain tcp or udp protocol

Error message

address does not contain tcp or udp protocol

What it means

When setting up an `ipfs p2p` listener/forward, kubo derives the local port from the listen or target multiaddr by looking up the TCP then the UDP protocol value. If the multiaddr contains neither /tcp/ nor /udp/, no port can be determined and this error is returned.

Source

Thrown at core/commands/p2p.go:398

		}),
	},
}

// checkPort checks whether target multiaddr contains tcp or udp protocol
// and whether the port is equal to 0
func checkPort(target ma.Multiaddr) error {
	// get tcp or udp port from multiaddr
	getPort := func() (string, error) {
		sport, _ := target.ValueForProtocol(ma.P_TCP)
		if sport != "" {
			return sport, nil
		}

		sport, _ = target.ValueForProtocol(ma.P_UDP)
		if sport != "" {
			return sport, nil
		}
		return "", errors.New("address does not contain tcp or udp protocol")
	}

	sport, err := getPort()
	if err != nil {
		return err
	}

	port, err := strconv.Atoi(sport)
	if err != nil {
		return err
	}

	if port == 0 {
		return errors.New("port can not be 0")
	}

	return nil
}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Include a tcp or udp transport with a nonzero port in the multiaddr, e.g. `/ip4/127.0.0.1/tcp/8080` or `/ip4/127.0.0.1/udp/8080/quic-v1`.
  2. Check for typos that removed the `/tcp/<n>` or `/udp/<n>` component.
  3. If you meant a unix socket or non-tcp/udp transport, that target type is unsupported by this command; use a tcp/udp endpoint instead.

Example fix

// before
ipfs p2p forward /p2p/x/1.0.0 /ip4/127.0.0.1 <target>
// after
ipfs p2p forward /p2p/x/1.0.0 /ip4/127.0.0.1/tcp/8080 <target>
Defensive patterns

Strategy: validation

Validate before calling

m, err := multiaddr.NewMultiaddr(addr)
if err != nil {
    return err
}
tcpPort, _ := m.ValueForProtocol(multiaddr.P_TCP)
udpPort, _ := m.ValueForProtocol(multiaddr.P_UDP)
if tcpPort == "" && udpPort == "" {
    return errors.New("multiaddr needs a /tcp/ or /udp/ component")
}

Prevention

When it happens

Trigger: Passing a listen or target multiaddr without a tcp/udp transport, e.g. `/ip4/127.0.0.1` alone, a `/unix/` path, or a quic/webtransport-only address to a p2p command that requires a host-side tcp/udp port.

Common situations: Typos dropping the `/tcp/<port>` component; using a Unix socket address; assuming QUIC addresses work for local forwarding when the command expects a TCP/UDP port to bind or connect.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/2aaad6c27500e32a. Report an issue: GitHub.