跳到主要内容
IPOK

数据研究

How do I configure a Linux server to enable dual-stack networking and verify its IPv6 connectivity?

2026-07-03 · ipok.io

To configure a Linux server for dual-stack networking, ensure IPv6 is enabled in the kernel (default on most modern systems). Then, configure your network interface for IPv6 using either Stateless Address Autoconfiguration (SLAAC), DHCPv6, or static assignment via tools like netplan, NetworkManager, or direct ip commands. For example, enable SLAAC by setting net.ipv6.conf.all.autoconf=1 in sysctl.conf. Verify IPv6 address assignment with ip -6 addr show and confirm end-to-end connectivity by pinging an external IPv6 address, such as ping6 ipv6.google.com or ping6 2001:4860:4860::8888, to confirm successful dual-stack operation.

Enabling IPv6 in the Linux Kernel

Modern Linux distributions typically have IPv6 support compiled into the kernel and enabled by default. You can verify if IPv6 modules are loaded and active:

lsmod | grep ipv6
sysctl net.ipv6.conf.all.disable_ipv6

If net.ipv6.conf.all.disable_ipv6 returns 0, IPv6 is enabled. If it returns 1, you can enable it temporarily:

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0

For persistent enablement, ensure these lines are not present or are commented out in /etc/sysctl.conf or /etc/sysctl.d/*.conf:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
After editing, apply changes with sudo sysctl -p. For more details on kernel parameters, consult the Linux kernel documentation.

Configuring Dual-Stack Network Interfaces

The method for configuring network interfaces depends on your Linux distribution and preferred network management tool. Common tools include Netplan (Ubuntu/Debian), NetworkManager (RHEL/CentOS/Fedora, desktop environments), and direct ip commands.

Method 1: Stateless Address Autoconfiguration (SLAAC)

SLAAC allows hosts to automatically configure IPv6 addresses and default routes without a stateful server, relying on Router Advertisements (RAs) from a local router. This is defined in RFC 4862.

  1. ·

    Enable Autoconfiguration (if not already):
    bash sudo sysctl -w net.ipv6.conf.eth0.autoconf=1 # Replace eth0 with your interface sudo sysctl -w net.ipv6.conf.eth0.accept_ra=2 # Accept RAs for routing and addressing
    For persistence, add these to /etc/sysctl.conf.

  2. ·

    Netplan (Ubuntu/Debian example - /etc/netplan/01-netcfg.yaml):
    yaml network: version: 2 renderer: networkd ethernets: eth0: dhcp4: true dhcp6: false # Can be true for stateful DHCPv6, but SLAAC is stateless accept-ra: true # Enable SLAAC
    Apply with sudo netplan apply.

  3. ·

    NetworkManager (RHEL/CentOS/Fedora example):
    bash nmcli connection modify eth0 ipv6.method auto nmcli connection up eth0

Method 2: DHCPv6 (Stateful/Stateless)

DHCPv6 provides more centralized control over IPv6 address assignment and other network parameters (like DNS servers).

  1. ·

    Netplan (Ubuntu/Debian example - /etc/netplan/01-netcfg.yaml):
    yaml network: version: 2 renderer: networkd ethernets: eth0: dhcp4: true dhcp6: true # Enable DHCPv6 accept-ra: true # Still accept RAs for default route if DHCPv6 doesn't provide it
    Apply with sudo netplan apply.

  2. ·

    NetworkManager (RHEL/CentOS/Fedora example):
    bash nmcli connection modify eth0 ipv6.method dhcp nmcli connection up eth0

Method 3: Static IPv6 Configuration

For servers requiring fixed IPv6 addresses, static configuration is essential.

  1. ·

    Netplan (Ubuntu/Debian example - /etc/netplan/01-netcfg.yaml):
    yaml network: version: 2 renderer: networkd ethernets: eth0: dhcp4: true addresses: - 2001:db8:1::10/64 # Static IPv6 address with prefix routes: - to: default via: 2001:db8:1::1 # Default IPv6 gateway nameservers: addresses: [2001:4860:4860::8888, 2001:4860:4860::8844] # IPv6 DNS servers
    Apply with sudo netplan apply.

  2. ·

    NetworkManager (RHEL/CentOS/Fedora example):
    bash nmcli connection modify eth0 ipv6.method manual nmcli connection modify eth0 ipv6.addresses "2001:db8:1::10/64" nmcli connection modify eth0 ipv6.gateway "2001:db8:1::1" nmcli connection modify eth0 ipv6.dns "2001:4860:4860::8888,2001:4860:4860::8844" nmcli connection up eth0

  3. ·

    Direct ip Command (Temporary):
    bash sudo ip -6 addr add 2001:db8:1::10/64 dev eth0 sudo ip -6 route add default via 2001:db8:1::1 dev eth0
    These changes are lost on reboot.

Verifying IPv6 Connectivity

After configuration, verify that IPv6 addresses are assigned and connectivity is established.

  1. ·

    Check Assigned IPv6 Addresses:
    bash ip -6 addr show eth0 # Or just 'ip -6 addr show' for all interfaces
    Look for a global unicast address (e.g., starting with 2000::/3).

  2. ·

    Check IPv6 Routing Table:
    bash ip -6 route show
    Ensure a default IPv6 route (default via ...) is present.

  3. ·

    Test Reachability with ping6:
    bash ping6 -c 4 ipv6.google.com ping6 -c 4 2001:4860:4860::8888 # Google's IPv6 DNS server
    Successful pings indicate basic end-to-end connectivity.

  4. ·

    Trace Path with traceroute6:
    bash traceroute6 ipv6.google.com
    This helps identify where connectivity might be failing along the path.

  5. ·

    Application-Level Testing with curl:
    bash curl -6 https://ipv6.google.com
    This verifies that applications can use IPv6.

  6. ·

    Check Listening IPv6 Sockets:
    bash ss -6 -tuln # List TCP/UDP listening sockets for IPv6
    This confirms if services are listening on IPv6 addresses.

IPv4 vs. IPv6 Connectivity Tools Comparison

Feature/Tool IPv4 Equivalent IPv6 Equivalent Description
Address Display ip addr show ip -6 addr show Displays network interface addresses.
Ping Utility ping <ipv4_address> ping6 <ipv6_address> Tests host reachability and latency.
Traceroute traceroute <ipv4> traceroute6 <ipv6> Traces the route packets take to a network host.
DNS Lookup dig A example.com dig AAAA example.com Queries DNS for A (IPv4) or AAAA (IPv6) records.
Socket Status ss -4 -tuln ss -6 -tuln Lists listening TCP/UDP sockets specifically for IPv4 or IPv6.

Troubleshooting Common Issues

  • ·Firewall: Ensure your firewall (e.g., ufw, firewalld, iptables) allows ICMPv6 traffic (essential for neighbor discovery and ping) and any application-specific IPv6 ports.
    • ·sudo ufw allow from any to any port 80 proto tcp ipv6
    • ·sudo firewall-cmd --zone=public --add-service=http --permanent --query-ipv6
  • ·Router Advertisements (RAs): If using SLAAC, verify your router is sending RAs. Use tcpdump -i eth0 icmp6 to capture them.
  • ·DNS Resolution: Ensure your /etc/resolv.conf contains IPv6 DNS servers or that your DHCPv6/SLAAC configuration provides them. Test with dig AAAA ipv6.google.com.
  • ·Kernel Parameters: Double-check sysctl settings for disable_ipv6, autoconf, and accept_ra for the specific interface.
  • ·Link-Local Addresses: All IPv6 interfaces will have a link-local address (starts with fe80::). This is normal and used for local network communication, but does not provide global connectivity.

Dual-stack networking allows a seamless transition to IPv6 while maintaining compatibility with IPv4, crucial for modern network environments. For more general information on dual-stack networking, refer to Wikipedia's Dual-stack article.

阅读延伸:您可以继续查阅有关 How can I configure my router and servers to support dual-stack IPv4 and IPv6 connectivity? 的最新技术实践指南。