Search code examples
expressnetwork-programmingipipv6

What's different in ::1 and ::ffff:127.0.0.1


i'm on using express and making my website.

but calling API on different port, assigned different ip.

both used req.ip

localhost:3000 (Origin) -> ::1 / localhost:8080 (Other server) -> ::ffff:127.0.0.1


Solution

    • ::1 is the IPv6 loopback address
    • ::ffff:127.0.0.1 is the IPv4 loopback address, written as an IPv6 address

    Apparently your software uses IPv6 sockets internally, so both IPv4 and IPv6 are handled with the IPv6 implementation. This is done more and more because it makes it easier to write software that supports both.

    IPv6 addresses are shown using their recommended representation, and IPv4 addresses are shown as IPv4-mapped IPv6 addresses with the corresponding special notation.

    So the difference you are seeing is between an IPv6 connection and an IPv4 connection. Both are valid ways to connect to localhost.