17.5. Operating IPv4 and IPv6 Together
A dual-stack host answers the same questions twice, once per family, and the two answers are configured separately: an interface can take IPv4 from DHCP and IPv6 from router advertisements, or either family from static configuration, or one family disabled entirely. This section works those combinations on the same practice link, ending with one profile that carries both families and their routes together.
17.5.1. Static Addressing, DHCP, SLAAC, and Router Advertisements
How a host gets an IPv6 address is decided by the router, in the
advertisement's flags. The A (Autonomous) flag on a prefix tells hosts
to generate their own addresses from it - SLAAC, what Section 17.1.2
showed. The M (Managed) flag instead tells hosts to ask a DHCPv6
server for addresses; the O flag asks for options only. router1's
radvd configuration advertises the prefix with A on and no M, so the
lab hosts use SLAAC; running radvd and DHCPv6 servers is
Chapter 22's material. The one rule to carry away:
static, SLAAC, and DHCPv6 are three ways to fill the same kernel state,
and the captures in this chapter come from SLAAC and static only.
Figure 17.2 shows what one advertisement produces on the host.
Figure 17.2. A conceptual view of one router advertisement: it drives the host's SLAAC address, its temporary privacy address, the default route, and the per-link DNS registration. The flags in the RA decide whether SLAAC or DHCPv6 provides the addresses.
Clear the two wired profiles from Section 17.3 first, so eth1 starts
the exercise unowned. In a root shell:
# nmcli connection delete lab-static lab-dhcp
Connection 'lab-static' (015f3c66-2b5b-4287-885a-40f46e3b4609) successfully deleted.
Connection 'lab-dhcp' (1aeab7fc-fe1c-496d-abc5-2f50cf1a664a) successfully deleted.
The IPv6-only profile is the mirror of Section 17.3.2's: IPv4 is
disabled - not auto, not manual - and IPv6 is auto, meaning
NetworkManager configures the link for SLAAC and accepts the router's
information:
# nmcli connection add type ethernet ifname eth1 con-name lab-v6auto ipv4.method disabled ipv6.method auto ipv6.ip6-privacy 2 ipv6.route-metric 500 ipv6.never-default no
Connection 'lab-v6auto' (2f8ab3d7-3a18-40c3-93dc-dfe2172bd9ab) successfully added.
# nmcli connection up lab-v6auto
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)
ipv6.ip6-privacy 2 turns on temporary addresses - the next subsection
but one dissects them. Activation is silent as usual; the interesting
output is the address list, as john:
$ ip -6 addr show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
altname enp0s6
altname ens6
altname enx5254000b5bb6
inet6 2001:db8:17:1:5a7a:9a9b:8938:2973/64 scope global temporary dynamic
valid_lft 86398sec preferred_lft 14398sec
inet6 2001:db8:17:1:8917:6675:7148:aee1/64 scope global dynamic mngtmpaddr noprefixroute
valid_lft 86398sec preferred_lft 14398sec
inet6 fe80::b759:bc72:67ab:41d2/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Compare this with Section 17.1.2's SLAAC output: the global address
there was the EUI-64 form derived from the MAC
(…:5054:ff:fe0b:5bb6), because the kernel generated it. Here
NetworkManager owns the link, and it generates the stable address -
the mngtmpaddr one - from an opaque interface identifier instead of
the MAC, so the address no longer reveals the hardware address and
survives hardware replacement. It is still stable across reconnects.
mngtmpaddr marks it as the anchor for the temporary address above it.
noprefixroute means the kernel creates no automatic /64 route for the
address: NetworkManager sets that flag on the addresses it manages and
installs the subnet route itself, under the profile's metric -
Section 17.7.1's routing table shows that route with metric 500. The
kernel's per-link switch for the whole mechanism reads back exactly
what the profile asked for:
$ cat /proc/sys/net/ipv6/conf/eth1/use_tempaddr
2
0 disables temporary addresses, 1 creates them but prefers the
stable one, 2 - the value set here by ipv6.ip6-privacy - prefers the
temporary one for outgoing connections. Without the profile setting,
the kernel default is 0; the equivalent persistent sysctl
(net.ipv6.conf.eth1.use_tempaddr=2 in /etc/sysctl.d/) is covered in
Chapter 7.
The route the advertisement provided, now under the profile's metric:
$ ip -6 route show default
default via fe80::5054:ff:fee7:63fb dev eth1 proto ra metric 500 pref medium
Everything else is as in Section 17.1.2 - link-local gateway, proto ra,
expiring with the router lifetime - with metric 500 from
ipv6.route-metric ranking it behind the primary link. Prove the
family works end to end, with the IPv6 form of the familiar ping:
$ ping -6 -c 3 2001:db8:17:1::2
PING 2001:db8:17:1::2 (2001:db8:17:1::2) 56 data bytes
64 bytes from 2001:db8:17:1::2: icmp_seq=1 ttl=64 time=0.740 ms
64 bytes from 2001:db8:17:1::2: icmp_seq=2 ttl=64 time=0.390 ms
64 bytes from 2001:db8:17:1::2: icmp_seq=3 ttl=64 time=0.424 ms
--- 2001:db8:17:1::2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2056ms
rtt min/avg/max/mdev = 0.390/0.518/0.740/0.157 ms
Static addressing closes the loop on the same tools: ipv6.method
manual with ipv6.addresses takes the place of the advertisement, and
Section 17.5.4's dual profile demonstrates it. One further mechanism
deserves its paragraph here because it silently changes who processes
advertisements: when systemd-networkd owns a link, IPv6AcceptRA= -
enabled by default - runs networkd's own userspace RA client, and the
kernel's own processing (the accept_ra sysctl of Section 17.1.2) is
disabled for that link, because networkd needs every field of the
advertisement for its per-link DNS registration. A machine can
therefore show accept_ra 0 on a link and still learn its prefix
correctly through networkd; checking the effective owner first
(Section 17.2) prevents misreading that sysctl as a fault.
17.5.2. Link-Local Addresses, Scope, and IPv6 Connectivity
Every IPv6 interface has a fe80::/10 address whether or not anything
else is configured. These addresses are scoped to the link: they are
valid only on the interface that carries them, and using one always
requires naming that interface - the zone identifier, written after a
percent sign. The all-nodes multicast group makes a quick reachability
probe possible with no addressing knowledge at all:
$ ping -6 -c 2 -I eth1 ff02::1
ping: Warning: IPv6 link-local address on ICMP datagram socket may require ifname or scope-id => use: address%<ifname|scope-id>
ping: Warning: source address might be selected on device other than: eth1
PING ff02::1 (ff02::1) from :: eth1: 56 data bytes
64 bytes from fe80::b759:bc72:67ab:41d2%eth1: icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from fe80::5054:ff:fee7:63fb%eth1: icmp_seq=1 ttl=64 time=0.481 ms
64 bytes from fe80::b759:bc72:67ab:41d2%eth1: icmp_seq=2 ttl=64 time=0.034 ms
--- ff02::1 ping statistics ---
2 packets transmitted, 2 received, +1 duplicates, 0% packet loss, time 1019ms
rtt min/avg/max/mdev = 0.034/0.191/0.481/0.205 ms
The two leading warnings are the zone rule in action: ping reminds
the operator that link-local work needs the interface name - supplied
here by -I eth1 - and that without it the kernel might pick a source
address from another interface. The echo list is the segment's
population: fe80::b759:… is netlab1's own link-local address (its
reply arrives as a duplicate, because the host hears its own
multicast back), and fe80::5054:ff:fee7:63fb - the same address that
serves as the IPv6 default gateway in the two preceding captures - is
router1's. For routers only, ff02::2 plays the same role.
The zone rule is not a ping quirk; it applies everywhere a link-local
address appears. ping -6 fe80::5054:ff:fee7:63fb%eth1, ssh
user@fe80::…%eth1, and the gateway fe80::…%eth1 form accepted by
ifupdown and NetworkManager all name the interface, because the same
fe80:: prefix exists on every link simultaneously. Global addresses
need no zone, which is the practical difference between the two
scopes - and why the RA-derived default route in Section 17.5.1 works
unchanged even if the site renumbers its global prefix: the gateway is
link-local and never renumbers.
A failure pattern follows from the scope rule. A connection to a
fe80:: address that omits the zone fails immediately with "invalid
argument" or reaches the wrong link's neighbor; a ping to a global
address that fails while the ff02::1 probe answers means the problem
is in the global addressing or routing, not the link; and a link-local
probe that answers nobody means the link itself - carrier, driver,
firewall - long before any global configuration is worth checking.
17.5.3. Address Lifetimes, Privacy Addresses, and Source Selection
The lifetimes printed with every dynamic address are the clock behind
IPv6 addressing. valid_lft is how long the address may receive
traffic; preferred_lft is how long new connections may use it.
Section 17.5.1's stable and temporary addresses both showed valid_lft
86398sec preferred_lft 14398sec - about a day and four hours,
refreshed by every arriving advertisement. When preferred_lft reaches
zero the address becomes deprecated: established connections continue,
new ones prefer another address. When valid_lft reaches zero the
address disappears. A router that stops advertising takes the host's
global address with it, on schedule - the contrast with
valid_lft forever on the static addresses of Section 17.5.4 is
visible in that subsection's capture.
The two-address arrangement serves privacy. A stable address built from
the MAC - or even from an opaque but never-changing identifier - allows
the same host to be tracked across networks and time. RFC 4941
temporary addresses rotate: the kernel generates a new one before the
current one's preferred lifetime ends, prefers it for outgoing
connections, and lets the old one lapse. Incoming connections still
reach the stable address, so servers and long-lived listeners are
unaffected. The cost is administrative: outbound connection sources
change over time, which breaks anything that identifies a host by its
address. The use_tempaddr switch from Section 17.5.1 - or the
per-profile ipv6.ip6-privacy, or networkd's IPv6PrivacyExtensions=
- makes that an explicit choice per link rather than a surprise.
When several addresses are candidates for a new connection, the
kernel's default address selection (RFC 6724) decides, and two of its
rules cover most questions in practice: prefer the same scope as the
destination - a global destination gets a global source, a link-local
destination a link-local source - and prefer, among global candidates,
a preferred temporary address over a deprecated one. The destination
side of the same rule set orders address families: when a name resolves
to both IPv6 and IPv4, connections try IPv6 first and fall back to IPv4
only if that fails - visible in Section 17.7.2's getent ahosts
capture, which lists the AAAA answers before the A ones. Disabling
that preference per host or per command (ping -4) is the standard way
to prove which family is actually broken during an outage.
17.5.4. Persistent Routes and Multiple Address Families
One profile can carry both families - and that is the shape most
dual-stack servers want: a single file, a single activation, one
consistent pair of addresses. The lab's dual profile replaces
lab-v6auto on the same link, in a root shell:
# nmcli connection add type ethernet ifname eth1 con-name lab-dual ipv4.method manual ipv4.addresses 192.168.217.20/24 ipv4.dns 192.168.217.2 ipv4.dns-search lab.example ipv4.never-default yes ipv4.route-metric 500 ipv6.method manual ipv6.addresses 2001:db8:17:1::20/64 ipv6.gateway 2001:db8:17:1::2 ipv6.dns 2001:db8:17:1::2 ipv6.dns-search lab.example ipv6.route-metric 500 ipv6.never-default no
Connection 'lab-dual' (1a6bbff1-c788-4b3c-812c-07c7421aa5d9) successfully added.
The two halves are independent: ipv4.method manual with no
ipv4.gateway, ipv6.method manual with a gateway and
never-default no. The IPv6 gateway here is a global address because
the lab's router has one; Section 17.5.2's link-local form works
identically and is what router advertisements provide. Activate:
# nmcli connection up lab-dual
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
The kernel's view, with both static families present and
valid_lft forever on both:
$ ip -br addr show eth1
eth1 UP 192.168.217.20/24 2001:db8:17:1::20/64 fe80::dc1f:7a0a:65cc:6d0d/64
Static configuration replaced the SLAAC address; the link-local address changed with the profile because NetworkManager derives it from an opaque identifier rather than the MAC - the identifier stays constant while a given profile activates on the link, so switching profiles changes it. Both families answer, each with its own ping - the two-family version of the routine reachability check:
$ ping -c 2 -W 1 192.168.217.2
PING 192.168.217.2 (192.168.217.2) 56(84) bytes of data.
64 bytes from 192.168.217.2: icmp_seq=1 ttl=64 time=0.549 ms
64 bytes from 192.168.217.2: icmp_seq=2 ttl=64 time=0.331 ms
--- 192.168.217.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1031ms
rtt min/avg/max/mdev = 0.331/0.440/0.549/0.109 ms
$ ping -6 -c 2 -W 1 2001:db8:17:1::2
PING 2001:db8:17:1::2 (2001:db8:17:1::2) 56 data bytes
64 bytes from 2001:db8:17:1::2: icmp_seq=1 ttl=64 time=0.480 ms
64 bytes from 2001:db8:17:1::2: icmp_seq=2 ttl=64 time=0.394 ms
--- 2001:db8:17:1::2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1019ms
rtt min/avg/max/mdev = 0.394/0.437/0.480/0.043 ms
Per-family routes live in the same profile. The + prefix appends to a
list property, so this modify adds one route per family without
disturbing the addresses:
# nmcli connection modify lab-dual +ipv4.routes "198.51.100.0/24 192.168.217.2" +ipv6.routes "2001:db8:17:99::/64 2001:db8:17:1::2"
The command is silent; re-activation applies it:
# nmcli connection up lab-dual
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
Each family verifies with its own table query - ip route show PREFIX
filters to the prefix, which beats grepping full tables:
$ ip route show 198.51.100.0/24
198.51.100.0/24 via 192.168.217.2 dev eth1 proto static metric 500
$ ip -6 route show 2001:db8:17:99::/64
2001:db8:17:99::/64 via 2001:db8:17:1::2 dev eth1 proto static metric 500 pref medium
proto static marks both as administrator-supplied, and the metrics
come from the profile's route-metric properties. The forwarding
decisions, one per family, complete the check:
$ ip route get 198.51.100.10
198.51.100.10 via 192.168.217.2 dev eth1 src 192.168.217.20 uid 1001
cache
$ ip -6 route get 2001:db8:17:99::1
2001:db8:17:99::1 from :: via 2001:db8:17:1::2 dev eth1 proto static src 2001:db8:17:1::20 metric 500 pref medium
The IPv6 form answers one extra question the IPv4 form does not: from
:: is the unspecified source the kernel filled in for the lookup, and
the chosen src is the static address - the family's source-selection
result for that destination. The same dual pattern exists in the other
backends: Gateway= or a [Route] section per route in a .network
file, and a gateway line per family in an ifupdown stanza - the files
themselves were introduced in Sections 17.3.3 and 17.3.4. Policy
routing, multiple uplinks with per-table rules, and bonds carrying
these same profiles forward are Chapter 19's
subject.