When you check your local IP address and see ::1
, you're encountering the IPv6 loopback address. This is the equivalent of 127.0.0.1
in IPv4, representing your local machine. The double colon (::) is IPv6 shorthand for consecutive segments of zeros.
Here's how you might see this in different programming contexts:
# Python example
import socket
print(socket.gethostbyname('localhost')) # Might return ::1
// Node.js example
const dns = require('dns');
dns.lookup('localhost', (err, address) => {
console.log(address); // Could output ::1
});
Modern operating systems prioritize IPv6 by default. Your machine will:
- Attempt IPv6 resolution first
- Fall back to IPv4 if IPv6 isn't available
- Return ::1 when resolving 'localhost'
When developing network applications, explicitly specify the IP version if needed:
# Force IPv4 in Python
socket.getaddrinfo('localhost', 80, family=socket.AF_INET)
// Java example
InetAddress ipv4Loopback = InetAddress.getByName("127.0.0.1");
InetAddress ipv6Loopback = InetAddress.getByName("::1");
Some applications might need explicit configuration for IPv6 loopback:
# /etc/hosts entry (Unix-like systems)
::1 localhost
127.0.0.1 localhost
Use these commands to check your loopback configuration:
ping ::1
ping6 ::1
ifconfig lo # Linux/Mac
ipconfig # Windows
When you check your local IP address and see ::1
, this is actually the IPv6 loopback address - the equivalent of 127.0.0.1
in IPv4. It's the shortened representation of the full IPv6 loopback address 0000:0000:0000:0000:0000:0000:0000:0001
.
Modern operating systems prioritize IPv6 over IPv4 when both are available. Here are common scenarios where you might encounter ::1:
# Python example showing both IPv4 and IPv6 localhost
import socket
# IPv4 connection
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 8080))
# IPv6 connection
s6 = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s6.connect(('::1', 8080))
When developing web applications, you can test using ::1 just like 127.0.0.1:
// Node.js server listening on both IPv4 and IPv6
const http = require('http');
const server = http.createServer((req, res) => {
res.end('Hello from localhost!');
});
server.listen(3000, '::', () => {
console.log('Server running on both IPv4 and IPv6');
});
Some applications need explicit configuration to handle ::1 properly. For example, in MySQL:
# In my.cnf or my.ini
[mysqld]
bind-address = ::1 # Listen on IPv6 localhost
# Or for both IPv4 and IPv6:
bind-address = *
When debugging network issues, you can test IPv6 connectivity:
# Ping ::1 to test IPv6 stack (works on Windows, Linux, macOS)
ping ::1
# On Linux/macOS, you might need:
ping6 ::1
Just like 127.0.0.1, ::1 is only accessible from your local machine. However, some security tools might treat IPv4 and IPv6 localhost differently:
# Example iptables rule allowing IPv6 localhost
ip6tables -A INPUT -s ::1 -j ACCEPT