DNSReflection Server

// Encode IPs in domain names, get them back in DNS responses

2DNS is a versatile DNS reflection server that allows you to encode IP addresses in domain names and have them reflected back in DNS responses. Perfect for networking applications, diagnostics, and DNS-based service discovery.

2DNS Global Network
// scroll to explore

// Features

const features = [
"Powerful DNS reflection capabilities"
];

[01]

IPv4 & IPv6 Support

/*
Full support for both IPv4 and IPv6 addresses with multiple encoding formats.
*/
[02]

Multiple Encoding Formats

/*
Direct reflection, Base32 encoding, and special formats for IPv6 including zero-group compression.
*/
[03]

Dual-Stack Support

/*
Encode both IPv4 and IPv6 addresses in a single domain for dual-stack environments.
*/
[04]

High Compatibility

/*
Runs on multiple ports and network types for maximum compatibility across different environments.
*/

function How It Works() {

return "Simple DNS reflection in action";

step.Encode IP in Domain()

/**
* Format your IP address according to one of the supported encoding formats and append it to the 2dns.dev domain.
*/

step.Send DNS Query()

/**
* Use standard DNS tools like dig or nslookup to query the encoded domain name against our DNS server.
*/

step.Server Processes Query()

/**
* Our server parses the domain name, extracts the encoded IP address, and prepares the appropriate DNS response.
*/

step.Receive IP in Response()

/**
* The DNS response contains the extracted IP address as an A record (for IPv4) or AAAA record (for IPv6).
*/
process.exit(0);
}
编码详解

Base32 Encoding Explained

How 2DNS encodes IP addresses using Base32

Understanding Base32 Encoding

Base32 encoding is a method of representing binary data using a set of 32 ASCII characters (A-Z and 2-7). In 2DNS, we use Base32 to encode IP addresses in a format that's safe for DNS domain names, replacing the standard padding character '=' with '8'.

IPv4
Base32 Encoding for IPv4

An IPv4 address consists of 4 bytes (32 bits). When encoded in Base32, it produces an 8-character string. This compact representation is perfect for embedding in domain names.

📦

转换示例:1.2.3.4 → AEBAGBA8

🔄编码流程

1.IP地址转字节:[1, 2, 3, 4]
2.Base32编码:"AEBAGBAA"
3.替换填充符:"AEBAGBA8"

IPv6
Base32 Encoding for IPv6

An IPv6 address consists of 16 bytes (128 bits). When encoded in Base32, it produces a 32-character string, which is longer but still manageable in domain names.

🌐

转换示例

2001:0db8:85a3::8a2e:0370:7334
EAAQ3OEFUMAAAAAARIXAG4DTGQ888888

🔄编码流程

1.
IPv6地址转字节:[32, 1, 13, 184, 133, 163, 0, 0, 0, 0, 138, 46, 3, 112, 115, 52]
2.
Base32编码:"EAAQ3OEFUMAAAAAARIXAG4DTGQ======"
3.
替换填充符:"EAAQ3OEFUMAAAAAARIXAG4DTGQ888888"

Dual Stack Encoding

For environments that support both IPv4 and IPv6, 2DNS allows encoding both addresses in a single domain name. The first 8 characters represent the IPv4 address, and the remaining 32 characters represent the IPv6 address.

🔗

双栈编码示例

IPv4: 1.2.3.4 + IPv6: 2001:0db8:85a3::8a2e:0370:7334

🔄编码流程

1.IPv4转字节:[1, 2, 3, 4]
2.IPv4编码:"AEBAGBA8"
3.
IPv6转字节:[32, 1, 13, 184, 133, 163, 0, 0, 0, 0, 138, 46, 3, 112, 115, 52]
4.
IPv6编码:"EAAQ3OEFUMAAAAAARIXAG4DTGQ888888"
5.
🎯 组合结果:"AEBAGBA8EAAQ3OEFUMAAAAAARIXAG4DTGQ888888"

📊查询结果

A 记录返回:1.2.3.4
AAAA 记录返回:2001:0db8:85a3::8a2e:0370:7334

Implementation Examples

Python

import base64
import ipaddress

def ipv4_to_base32(ip_str):
    """Convert an IPv4 address to Base32 encoding."""
    # Parse the IP address
    ip = ipaddress.IPv4Address(ip_str)
    # Convert to bytes
    ip_bytes = ip.packed
    # Encode to Base32
    encoded = base64.b32encode(ip_bytes).decode('ascii')
    # Replace padding with '8'
    return encoded.rstrip('=').ljust(len(encoded), '8')

def ipv6_to_base32(ip_str):
    """Convert an IPv6 address to Base32 encoding."""
    # Parse the IP address
    ip = ipaddress.IPv6Address(ip_str)
    # Convert to bytes
    ip_bytes = ip.packed
    # Encode to Base32
    encoded = base64.b32encode(ip_bytes).decode('ascii')
    # Replace padding with '8'
    return encoded.rstrip('=').ljust(len(encoded), '8')

def dual_stack_to_base32(ipv4_str, ipv6_str):
    """Create a dual-stack Base32 encoding."""
    return ipv4_to_base32(ipv4_str) + ipv6_to_base32(ipv6_str)

# Examples
ipv4 = "1.2.3.4"
ipv6 = "2001:0db8:85a3::8a2e:370:7334"

print(f"IPv4 Base32: {ipv4_to_base32(ipv4)}")
print(f"IPv6 Base32: {ipv6_to_base32(ipv6)}")
print(f"Dual Stack Base32: {dual_stack_to_base32(ipv4, ipv6)}")
实时演示

Try DNS Reflection

See how 2DNS works with your IP addresses

Enter an IP address and select a format to generate a DNS query command.

DNS 查询生成器
输入IP地址并选择格式来生成DNS查询命令
Examples
查看不同格式的DNS查询示例
1

Direct IPv4

dig

dig 1.2.3.4.2dns.dev A

host

host -t A 1.2.3.4.2dns.dev

DNS over HTTPS

Using Cloudflare DOH to query 1.2.3.4.2dns.dev

Returns 1.2.3.4 as an A record