In mixed IPv4/IPv6 environments, applications often default to IPv6 when both protocol stacks are available. While this is generally desirable for IPv6 adoption, some legacy systems or specific network configurations may require forcing IPv4 as the preferred protocol. Here's how to achieve this on Slackware Linux systems.
The key player in protocol selection is the getaddrinfo()
function from glibc, which applications use for DNS resolution. Its behavior can be modified through:
- The
/etc/gai.conf
configuration file - Application-specific settings
- Kernel-level routing preferences
For Slackware 13.0 (and newer versions), you'll need to modify both system-wide and application-specific settings:
1. System-wide Configuration
Create or modify /etc/gai.conf
with these contents:
# IPv4 precedence over IPv6
precedence ::ffff:0:0/96 100
label ::ffff:0:0/96 4
2. Kernel Network Stack Tweaks
Add these lines to /etc/sysctl.conf
:
# Prefer IPv4 over IPv6
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
net.ipv4.ip_nonlocal_bind = 1
Then apply with: sysctl -p
Firefox Configuration
To force IPv4 in Firefox:
- Navigate to
about:config
- Set these preferences:
network.dns.disableIPv6 = true
network.http.fast-fallback-to-IPv4 = true
Curl and Wget
For command-line tools:
# Force IPv4 with curl
curl -4 http://example.com
# Force IPv4 with wget
wget -4 http://example.com
Verify your settings with these commands:
# Check DNS resolution
getent hosts example.com
# Test connectivity
ping -4 example.com
traceroute -4 example.com
For networks where you control DNS, you can implement filtering at the resolver level using bind or dnsmasq:
# dnsmasq configuration example
filter-aaaa
When working with dual-stack networks in Slackware Linux, applications often default to IPv6 connections even when IPv4 is available. This behavior stems from the getaddrinfo()
library function's default sorting algorithm, which prioritizes IPv6 addresses when both protocol versions are available.
The most effective way to control this behavior is through the /etc/gai.conf
file, which governs address selection policies. While your initial attempt with:
precedence ::ffff:0:0/96 100
works on Debian-based systems, Slackware requires a slightly different approach due to its glibc implementation.
For Slackware 13.0 and similar versions, use this enhanced configuration:
# /etc/gai.conf
# IPv4 precedence over IPv6
label ::1/128 0
label ::/0 1
label 2002::/16 2
label ::/96 3
label ::ffff:0:0/96 4
precedence ::ffff:0:0/96 100
Some applications may need additional configuration:
For Firefox
Add these preferences in about:config
:
network.dns.disableIPv6 → true
network.http.fast-fallback-to-IPv4 → true
network.dns.ipv4OnlyDomains → ipv6.org
For curl/wget
# Force IPv4 with curl
curl -4 http://ipv6.org/
# wget IPv4 preference
echo "prefer-family = IPv4" >> ~/.wgetrc
For systems where IPv6 isn't needed at all:
# Add to /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
# Apply immediately
sysctl -p
Test with these commands:
# Check DNS resolution
getent ahosts ipv6.org | awk '{print $1}' | sort -u
# Verify connection protocol
curl -v --connect-timeout 5 http://ipv6.org/ 2>&1 | grep Connected