#35819·go-ethereum

p2p: allow suppressing IPv4 ENR advertisement while pinning IPv6

Author: suna4Created Sep 28, 2026Updated Sep 28, 2026

Environment

  • Geth v1.17.6, mainnet, Arch Linux (kernel 7.2).
  • Home connection with native IPv6 (TCP/UDP 30303 open) and DS-Lite IPv4. On this connection I cannot expose an inbound IPv4 TCP endpoint.
  • Relevant flags: --port=30303 --nat=extip:<IPv6> (discovery v4 and v5 both enabled by default).

What happens

--nat extip pins only the address family of the given IP. IPv4 is still predicted from discovery endpoint statements, so the ENR advertises the carrier's shared IPv4 next to the pinned IPv6.

Relevant ENR fields, stock v1.17.6 (addresses redacted):

ip    <shared public IPv4>   (predicted)
udp   8281                   (predicted)
tcp   30303
ip6   <IPv6>
udp6  30303

udp 8281 is the external port observed by discovery, so UDP may work through the NAT mapping, but the advertised IPv4 TCP endpoint does not accept inbound connections. Geth's enode.Node selects IPv4 when both addresses have the same locality score, even though that TCP endpoint is not reachable.

--nat extip accepts a single address, so I found no way to pin IPv6 and suppress IPv4 at the same time. --nat extip:0.0.0.0 suppresses IPv4 advertisement, but then leaves no way to pin the IPv6 address through the same option.

Expected

Keep IPv4 outbound connections and IPv4 discovery, pin ip6, and omit ip from the ENR.

Suggestion

A way to control advertisement per address family, keeping today's behaviour by default. For example (not an existing syntax):

--nat extip:0.0.0.0,<IPv6>

meaning "no IPv4 in the ENR, IPv6 pinned". I'm happy to follow whatever syntax you prefer.

To check feasibility I run a small local patch (a few lines in p2p/server_nat.go plus tests) that pins IPv4 to the unspecified address when --nat extip is IPv6 and an environment variable is set. updateEndpoints then drops ip and the record becomes:

Relevant ENR fields, patched (addresses redacted):

ip6   <IPv6>
tcp   30303
udp   30303

Outbound IPv4 peering continues to work with the patch. I can turn this into a PR in the form you prefer.

Related

  • #29495 / #29801: a loopback IPv4 fallback was preferred over an IPv6 extip; #29801 fixed the address preference. Here the predicted IPv4 is public, so it is still advertised and preferred.
  • #23263: IPv6 discovery bootstrap (a separate topic).

(AI-assisted)