Io timeout when trying to connect to another host

I’m trying to use the chat-with-rendezvous example https://github.com/libp2p/go-libp2p/tree/master/examples/chat-with-rendezvous, however, when I try to connect to a host from another network, I get i/o timeout error.

As advised by others, I used NatPortMap and added ModeServer to DHT option

host, err := libp2p.New(
		libp2p.Identity(prvKey),
		libp2p.ListenAddrs([]multiaddr.Multiaddr(config.ListenAddresses)...),
		libp2p.NATPortMap(),
	)
kademliaDHT, err := dht.New(
		ctx,
		host,
		dht.Mode(dht.ModeServer))
peerChan, err := routingDiscovery.FindPeers(
		ctx,
		config.RendezvousString,
		discovery.Limit(100),
	)

The logs show that the search for nodes sees the ip the node needs, but the connection fails - timeout error

How can this be fixed?

Probably a NAT/router error. Is the up address you see a public ip?

You may be able to use the hole punching stuff.

If you share your code and setup we might be able to help more.