{"id":190,"date":"2026-11-22T07:33:00","date_gmt":"2026-11-22T06:33:00","guid":{"rendered":"https:\/\/www.whatismyipaddressinquire.com\/blog\/?p=190"},"modified":"2026-11-15T09:33:38","modified_gmt":"2026-11-15T08:33:38","slug":"ipv4-mapped-addresses-in-server-logs","status":"publish","type":"post","link":"https:\/\/www.whatismyipaddressinquire.com\/blog\/ipv4-mapped-addresses-in-server-logs\/","title":{"rendered":"IPv4-Mapped Addresses in Server Logs"},"content":{"rendered":"<p><strong>TL;DR \/ Summary:<\/strong> When an application listens on both address families, an IPv4 client can show up in logs as an address with an ::ffff: prefix. The visitor is still IPv4. Normalise that form before counting, blocking, or storing the address, or your analytics will treat one machine as two.<\/p>\n<h2>The ::ffff: prefix without a lecture<\/h2>\n<p>IPv6 has a reserved range for representing IPv4 addresses. An address like ::ffff:203.0.113.42 is the IPv4 address 203.0.113.42 written in IPv6 notation. The last four groups are the same four bytes, just displayed in a longer format.<\/p>\n<p>Applications see this form when a socket accepts both protocols on one endpoint. The connection is genuinely IPv4 at the wire level, but the library reports the peer using its internal IPv6-capable structure, so the log line inherits the mapped form.<\/p>\n<p>Nothing is misconfigured. The prefix is a faithful description of how the program represents the address internally, and it becomes a problem only when something downstream assumes all addresses in that field are IPv4 dotted quads.<\/p>\n<h2>Why a dual-stack listener reports it<\/h2>\n<p>A server that binds to the IPv6 wildcard address on many operating systems also accepts IPv4 connections by default. That behaviour is convenient for deployment and confusing for logs, because one listening socket now receives two address families.<\/p>\n<p>Language runtimes differ in how they surface the peer. Some return the mapped string as-is; some convert it to a plain IPv4 string; some return a structure with a family flag. Two services in the same stack can therefore log the same visitor differently.<\/p>\n<p>If you bind explicitly to an IPv4 address, the prefix disappears, but you also stop accepting IPv6 clients. For most public services that is the wrong trade, so the prefix is better handled at the parsing layer.<\/p>\n<h2>Parsing logs that mix both forms<\/h2>\n<p>The first step is recognition. Any address beginning with ::ffff: and ending in four decimal octets is a mapped IPv4 address. Strip the prefix and you have the address your allowlists and geolocation data already understand.<\/p>\n<p>Do the conversion once, at ingestion, and store a family column alongside the value. That column makes it possible to count IPv6-only visitors separately from mapped ones without re-parsing years of logs later.<\/p>\n<p>Be careful with case. IPv6 hexadecimal digits are case-insensitive, and some libraries emit uppercase. Normalise to lowercase before comparing strings, or a blocklist entry written one way will miss a connection logged the other way.<\/p>\n<p>Proxy headers add one more wrinkle. A forwarded-for chain can contain a mapped address in one position and a plain one in the next, so split the chain first and normalise each entry instead of treating the whole string as a single address.<\/p>\n<h3>Grouping counts without losing uniqueness<\/h3>\n<p>If you group by the raw string, the same machine appears twice: once as 203.0.113.42 and once as ::ffff:203.0.113.42. Rate limits split in half, unique visitor counts inflate, and a fraud rule that triggers on repeat attempts may never fire.<\/p>\n<p>Normalise the key used for grouping and keep the original text in a separate column for audit. That way the analytics are correct and the raw record still shows exactly what the application reported.<\/p>\n<h2>Regex and database columns that trip on the colon<\/h2>\n<p>An IPv4 pattern anchored to dots will fail on the mapped form, and a naive split on colons will produce garbage because IPv6 uses colons as its separator. Match the mapped pattern explicitly before falling back to a general IPv6 parser.<\/p>\n<p>Storage is the other half. A thirty-nine character text column holds any address but compares slowly and invites inconsistent formatting. A sixteen-byte binary column holds both families natively, and most databases provide conversion functions that accept either notation.<\/p>\n<ul>\n<li><strong>Text column:<\/strong> simple, but normalise on write and index carefully<\/li>\n<li><strong>Binary column:<\/strong> correct for both families, needs conversion on read<\/li>\n<li><strong>Two columns:<\/strong> family plus address, explicit and easy to query<\/li>\n<\/ul>\n<p>Whatever you choose, write the conversion into the ingestion path rather than into each report. Reports drift; ingestion code has tests.<\/p>\n<blockquote><p>The log is a record of what happened. The column is a decision about how you will ask questions later.<\/p><\/blockquote>\n<h2>When to normalise and when to leave it alone<\/h2>\n<p>Normalise when the address feeds a decision: allowlists, rate limits, abuse scoring, geographic reporting. Those systems need one representation per machine.<\/p>\n<p>Leave the raw form when the address feeds a forensic record. If you are investigating a specific connection, the exact string the socket reported is evidence, and rewriting it loses a detail someone may need later.<\/p>\n<p>Some security tooling now expects the mapped form and will reject a plain IPv4 address as coming from the wrong family. Check the consumer before a global rewrite; a normalisation that breaks a firewall rule is worse than the inconsistency it fixed.<\/p>\n<p>A quick check from outside the network, such as <a href=\"https:\/\/www.whatismyipaddressinquire.com\/\">What Is My IP Address Inquire<\/a>, also helps confirm which family your own connection actually uses, independent of what a particular log claims.<\/p>\n<h2>A normalization rule worth writing down<\/h2>\n<p>Store the family, store the canonical form, and store the original string. Convert mapped addresses to dotted quad at ingestion, lowercase all hexadecimal, and reject anything that does not parse rather than storing a guess.<\/p>\n<p>Add one test case per family to the ingestion suite: a plain IPv4 address, a mapped IPv4 address, a compressed IPv6 address, and an expanded one that should compress to the same value. Four cases catch most of the drift.<\/p>\n<p>Then document the rule in the schema comment. Six months from now the prefix will look like a bug to someone who has never seen it, and one sentence will save that person an afternoon.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR \/ Summary: When an application listens on both address families, an IPv4 client can show up in logs as an address with an ::ffff: prefix. The visitor is still IPv4. Normalise that form before counting, blocking, or storing the address, or your analytics will treat one machine as two. The ::ffff: prefix without a&hellip;&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":32,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[4],"tags":[],"class_list":["post-190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-networking-concepts"],"_links":{"self":[{"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/posts\/190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":1,"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/posts\/190\/revisions\/191"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/media\/32"}],"wp:attachment":[{"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whatismyipaddressinquire.com\/blog\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}