Host Models, Source Address Selection and Mobile IP
How a host with several addresses decides which packets are for it (weak and strong host models), which of its addresses to send from and which of a server's addresses to try first (RFC 6724), how Mobile IP keeps an address while moving, and the attacks that target IP itself.
kvi5hnuCode Sprout team member20 min readOn this page
A laptop with Wi-Fi and Ethernet, a server with a public and a private interface, or any IPv6 host with a link-local, a global and a temporary address: almost every machine has several IP addresses. That raises three questions that IP has to answer for every packet:
- Receiving. A packet arrives on one interface, addressed to an address configured on a different interface. Is it for this host?
- Sending. Which of the host's own addresses goes in the Source Address field?
- Connecting. A name like
www.example.comresolves to both an IPv6 and an IPv4 address. Which should be tried first?
This article answers each, then covers Mobile IP, the old attempt to let a host keep its address while moving between networks, and the attacks that target IP itself.
Weak and strong host models
RFC 1122 describes two ways a multihomed host (one with addresses on more than one network) can treat its addresses:
- Weak host model. An address belongs to the host as a whole. A packet addressed to any of the host's addresses is accepted, no matter which interface it arrives on. When sending, any interface may be used with any source address.
- Strong host model. An address belongs to one interface. A packet is accepted only if it's addressed to an address on the interface where it arrived, and packets are sent only from an interface that owns the source address.
The lab tested this with a host m that has eth0 (192.0.2.20) on one network and eth1 (198.51.100.20) on another. Host a, on the first network, sent a ping to m's second address, delivered through eth0. Forwarding was off on m, so it was acting purely as a host:
net.ipv4.ip_forward = 0
64 bytes from 198.51.100.20: icmp_seq=1 ttl=64 time=0.660 ms
Linux uses the weak host model by default, so the ping was answered. ARP follows the same idea: asked on eth0 for the address of eth1, Linux answers with eth0's MAC address:
Unicast reply from 198.51.100.20 [02:00:00:00:0A:02] 0.537ms
net.ipv4.conf.all.arp_ignore = 0
Linux has no single "strong host" switch, but you can get the receive side of it with a firewall rule that drops packets arriving on eth0 unless they're addressed to eth0's own address (or a broadcast or multicast address):
iifname "eth0" ip daddr != { 192.0.2.20, 192.0.2.255, 224.0.0.0/4, 255.255.255.255 } counter packets 0 bytes 0 drop
1 packets transmitted, 0 received, 100% packet loss, time 0ms
counter packets 1
1 packets transmitted, 1 received, 0% packet loss, time 0ms
The output shows the rule, then the ping to eth1's address failing, the rule's counter at 1 (it dropped that ping), and finally a ping to eth0's own address that still worked. The figure puts the two models side by side.

Which model is better? Neither wins outright:
- The weak model is more forgiving. Traffic still reaches a host when routing is asymmetric or an interface is misconfigured.
- The strong model is safer. A host attached to both a trusted internal network and the Internet won't accept a packet from the Internet side that's addressed to its internal address. That matters for firewalls and for services that bind only to the internal address.
Windows (since Vista) uses the strong host model by default. Linux uses the weak model, with settings to tighten it: arp_ignore=1 makes it answer ARP only for addresses on the receiving interface, arp_announce=2 makes it pick a source address for ARP requests from the outgoing interface, and reverse path filtering (rp_filter) drops packets whose source address wouldn't be routed back out the interface they arrived on. rp_filter=1 (strict) or 2 (loose) is common on distributions, though the kernel default is 0.
Choosing a source address
When an application connects without binding to a specific address, the kernel picks the source. For IPv4 the rule is simple: use the address on the outgoing interface that the route lookup chose, preferring the route's src hint, or else the primary address of the matching subnet (the first one configured). With a second address added on the same subnet, Linux still used the first. The first line lists the interface's addresses (ip -br addr, the brief form), and the src in the route lookup is the chosen source:
eth0@if11 UP 192.0.2.10/24 192.0.2.99/24
203.0.113.10 via 192.0.2.1 dev eth0 src 192.0.2.10 uid 0
IPv6 hosts nearly always have several addresses on one interface, so IPv6 needs real rules. They come from RFC 6724, "Default Address Selection for IPv6", which also covers IPv4 so that dual-stack hosts can compare the two. The source address selection rules compare two candidate addresses at a time, and the first rule that prefers one of them decides:
- Prefer an address that is the destination.
- Prefer an address of the appropriate scope: link-local for a link-local destination, global for a global destination.
- Avoid deprecated addresses, ones whose preferred lifetime has run out (article 32).
- Prefer a Mobile IPv6 home address over a care-of address (see below).
- Prefer an address on the outgoing interface. 5.5. Prefer an address in a prefix advertised by the chosen next-hop router.
- Prefer an address whose label matches the destination's label, from the policy table below.
- Prefer temporary (privacy) addresses over stable ones (article 32).
- Use the address with the longest matching prefix with the destination.
The lab host had three global addresses on one interface: 2001:db8:1::10, a deprecated 2001:db8:1::77, and 2001:db8:3:1::99:
inet6 2001:db8:3:1::99/64 scope global nodad
inet6 2001:db8:1::77/64 scope global nodad deprecated
inet6 2001:db8:1::10/64 scope global nodad
inet6 fe80::ff:fe00:c01/64 scope link proto kernel_ll
ip route get shows the source the kernel would use for each destination, after src. (from :: only means the lookup didn't ask for a particular source.)
2001:db8:1::5 from :: dev eth0 src 2001:db8:1::10
2001:db8:3::10 from :: via 2001:db8:1::1 dev eth0 src 2001:db8:3:1::99
2001:db8:5::1 from :: via 2001:db8:1::1 dev eth0 src 2001:db8:3:1::99
fe80::1 from :: dev eth0 src fe80::ff:fe00:c01
- For
2001:db8:1::5, on the local subnet, rule 3 rules out the deprecated::77, and rule 8 picks::10, which shares the whole /64. - For
2001:db8:3::10, rule 8 picks2001:db8:3:1::99, which shares 63 bits with it, while::10shares only 46. To count them, write out the first group that differs. Against2001:db8:3:1::99, the first 48 bits (2001:0db8:0003) are equal, and the fourth group is0000against0001: in binary0000000000000000against0000000000000001, equal for 15 more bits, so 48 + 15 = 63. Against2001:db8:1::10, the third group is0003(0000000000000011) against0001(0000000000000001), equal for 14 bits, so 32 + 14 = 46. - For
2001:db8:5::1, both candidates share exactly 45 bits with the destination, so even rule 8 ties. The kernel then keeps whichever it met first in its address list, here the most recently added address. When every rule ties, the result depends on implementation details like this. - For the link-local
fe80::1, rule 2 picks the link-local address.
The policy table
Rules 6 for source selection and 5 and 6 for destination selection use a policy table of prefixes, each with a precedence and a label. The default table from RFC 6724:
| Prefix | Precedence | Label | What it is |
|---|---|---|---|
::1/128 | 50 | 0 | Loopback |
::/0 | 40 | 1 | All other IPv6, including global unicast |
::ffff:0:0/96 | 35 | 4 | IPv4 (as IPv4-mapped addresses) |
2002::/16 | 30 | 2 | 6to4 (an old IPv6-over-IPv4 tunnel, article 20) |
2001::/32 | 5 | 5 | Teredo (another old tunnel, article 20) |
fc00::/7 | 3 | 13 | Unique local addresses (ULA), IPv6's private addresses (article 11) |
::/96 | 1 | 3 | Deprecated IPv4-compatible |
fec0::/10 | 1 | 11 | Deprecated site-local |
The RFC's table has one more row, with precedence 1, for the prefix of the 6bone, the IPv6 test network retired in 2006.
Higher precedence means "try first". The label groups addresses that belong together: a source and destination with the same label are preferred, so an IPv4 destination prefers an IPv4 source, and a 6to4 destination a 6to4 source. On Linux, the kernel's copy of the table for source selection is shown by ip addrlabel:
prefix ::1/128 label 0
prefix ::/96 label 3
prefix ::ffff:0.0.0.0/96 label 4
prefix 2001::/32 label 6
prefix 2002::/16 label 2
prefix fec0::/10 label 11
prefix fc00::/7 label 5
prefix ::/0 label 1
Two rows for retired prefixes (the 6bone and an old cryptographic-identifier block) are left out here. The label numbers differ from the RFC's, but only whether two labels are equal matters.
Choosing a destination address
When an application calls getaddrinfo() for a name with several addresses, the C library sorts them with RFC 6724's destination address selection rules, and the application normally tries them in that order:

The destination rules, applied in order to compare two candidates:
- Avoid destinations that are unusable (no route, or known unreachable).
- Prefer a destination whose scope matches that of the source address the host would use for it.
- Avoid destinations whose source address would be deprecated.
- Prefer destinations whose source would be a home address.
- Prefer destinations whose label matches their source's label.
- Prefer higher precedence.
- Prefer native transport over tunnels.
- Prefer a smaller scope (link-local over global).
- Use the longest matching prefix between destination and source (IPv6 only).
- Otherwise, keep the order the DNS returned.
The lab gave two names an IPv6 and an IPv4 address each, then asked Python's socket.getaddrinfo() (which calls the C library) for the order. dual.example.com has a global IPv6 address, and ula.example.com has a unique local one. The host had global IPv6 and IPv4 addresses but no ULA:
eth0@if11 UP 192.0.2.10/24 2001:db8:1::10/64 fe80::ff:fe00:c01/64
dual.example.com: 2001:db8:3::10, then 203.0.113.10
ula.example.com: 203.0.113.11, then fd00:3::11
For dual, everything ties until rule 6, where ::/0 (precedence 40) beats IPv4 (35), so IPv6 goes first. That default is why a dual-stack host uses IPv6 whenever it can. For ula, the host's source would be its global address, whose label (1) doesn't match the ULA's (13), while IPv4 to IPv4 does match. Rule 5 puts IPv4 first.
Adding a ULA to the host makes the labels match:
ula.example.com: fd00:3::11, then 203.0.113.11
Now the ULA comes first. That's not what the RFC 6724 table says: it gives ULAs precedence 3, below IPv4's 35. The reason is that glibc's built-in table still uses the older RFC 3484 precedences, in which IPv4 (10) ranks below all native IPv6 (40). Installing the RFC 6724 table in /etc/gai.conf gives the order the RFC intends:
ula.example.com: 203.0.113.11, then fd00:3::11
Finally, with all IPv6 addresses except the link-local one removed, IPv6 can't be reached with a matching scope (rule 2), and IPv4 goes first:
eth0@if11 UP 192.0.2.10/24 fe80::ff:fe00:c01/64
dual.example.com: 203.0.113.10, then 2001:db8:3::10
Mobile IP
An IP address says both who a host is and where it's attached. When a laptop moves from one network to another, it gets a new address (article 29), and every TCP connection using the old address breaks. Mobile IP tries to separate the two roles. Mobile IPv6 is defined in RFC 6275, and Mobile IPv4 in RFC 5944.
The model
- A mobile node (MN) has a permanent home address (HoA) on its home network.
- A home agent (HA), a router on the home network, keeps track of where the mobile node currently is.
- When the mobile node visits another network, it gets a care-of address (CoA) there, and tells its home agent with a Binding Update message. The home agent answers with a Binding Acknowledgement. The mapping from home address to care-of address is called a binding.
- A correspondent node (CN) is any host the mobile node communicates with.
Bidirectional tunneling
The basic mode needs nothing special from correspondents:
- The correspondent sends packets to the home address, as usual. They reach the home network.
- The home agent intercepts them (with proxy Neighbor Discovery, the IPv6 version of proxy ARP from article 22) and tunnels them to the care-of address, wrapped in an outer IPv6 header.
- The mobile node sends replies back through the same tunnel to the home agent, which forwards them on with the home address as the source.
Applications see only the home address, so connections survive moves. The cost is the detour: every packet travels via the home network, even when the mobile node and correspondent are next to each other on the other side of the world. This is called triangle routing, or dog-legged routing.
Route optimization
To remove the detour, a mobile node can send Binding Updates directly to a correspondent that supports Mobile IPv6. The two then talk directly:
- The mobile node sends from its care-of address, with a Home Address option in a Destination Options header (article 26) that tells the correspondent its home address.
- The correspondent sends to the care-of address, with a type 2 Routing header containing the home address, so the mobile node's stack delivers the packet as if it had been sent to the home address.
Correspondents must not accept a Binding Update from just anyone, or an attacker could redirect someone else's traffic. The return routability procedure tests that the mobile node can receive at both addresses: it sends a Home Test Init (HoTI) through the home agent and a Care-of Test Init (CoTI) directly, and the correspondent replies to each with a token (HoT and CoT). Only a node that receives both tokens can build a valid Binding Update. All of these signaling messages travel in the Mobility header (Next Header 135).
Variations and reality
Several extensions tried to make Mobile IP faster or easier to deploy: Hierarchical Mobile IPv6 (RFC 5380) adds a local mobility anchor so small moves don't need a Binding Update to the distant home agent, Fast Handovers (RFC 5568) prepare the next care-of address in advance, and Proxy Mobile IPv6 (RFC 5213) moves all the signaling into the network, so the mobile host needs no special software at all.
In practice, Mobile IP on end hosts is rarely used. Mobile phone networks give mobility inside the operator's network with their own tunneling protocol (GTP, the GPRS Tunnelling Protocol), and the address stays the same while you move between cells. Across networks, applications cope instead: they reconnect, or use transports like QUIC (article 86), whose connections are identified by connection IDs rather than addresses and can migrate to a new address.
Attacks involving IP
IP itself has no authentication: any host can put any value in any header field. The main attacks against IP:
- Source address spoofing. A host sends packets with a forged source address. That hides the attacker in floods and makes reflection attacks possible, where small requests with the victim's address as the source cause servers to send large replies to the victim (article 48). The defense is ingress filtering at network edges, defined in BCP 38 (RFC 2827; a BCP, "Best Current Practice", is an RFC that records operational advice) and BCP 84 (RFC 3704): a provider drops packets from a customer whose source address isn't in that customer's prefixes. Reverse path filtering (
rp_filter) is the same check on one machine. Many networks still don't filter, which is why spoofing is still possible on parts of the Internet. - Malformed headers. Packets with an impossible header length, a bad option length or a total length that doesn't match have crashed stacks in the past. Modern stacks check every field before using it, which is why the kernel counters for header errors exist.
- Option and extension header abuse. Source routing to bypass filters, Record Route and Timestamp to map a network, or Hop-by-Hop options to push routers onto their slow path (article 26). Most networks drop or ignore such packets.
- Fragment attacks. Overlapping or tiny fragments that hide a TCP header from a firewall, or that crashed reassembly code (the 1997 "teardrop" attack). IPv6 forbids overlapping fragments (RFC 5722) and requires the whole header chain in the first fragment (RFC 7112). Article 46 covers fragmentation.
- Mobile IP binding attacks. Forged Binding Updates that redirect traffic, which return routability and IPsec between mobile node and home agent were designed to stop.
The common lesson is to never trust a field of a received packet, especially its source address. Authentication belongs to higher layers (TLS, article 83) or to IPsec (article 82).
Common questions
My server has a public and a private interface. Can someone on the Internet reach a service bound to the private address?
On Linux, by default, yes, if they can get a packet addressed to the private address to arrive on the public interface. Usually that means they're on the same link as the public interface, or a router upstream routes the private prefix to you. The weak host model accepts it. Protect such services with firewall rules tied to the incoming interface, with rp_filter, or by binding the service so it's reachable only where you intend.
Why does my host use IPv6 for one website and IPv4 for another, when both have IPv6 addresses?
Possible reasons: one name has only a ULA or 6to4 or Teredo address, whose low precedence or mismatched label puts IPv4 first; your host has no global IPv6 address with a route to it; or Happy Eyeballs fell back to IPv4 because the IPv6 connection was slow to start.
How do I make my Linux machine prefer IPv4 over IPv6?
Edit /etc/gai.conf and raise IPv4's precedence above ::/0, for example precedence ::ffff:0:0/96 100. That changes only the order getaddrinfo() returns. Applications that do their own address selection, such as browsers with Happy Eyeballs, may still make their own decisions.
What is a deprecated address, and why does it still exist?
An address whose preferred lifetime has expired but whose valid lifetime hasn't. It still works for existing connections, so they aren't broken, but rule 3 keeps it from being chosen for new ones. That's how IPv6 renumbering and temporary address rotation work without cutting off traffic (article 32).
Is Mobile IPv6 used by smartphones?
Not in general. Phones keep their address while moving inside the mobile operator's network, thanks to the operator's GTP tunnels, and get a new address when they switch to Wi-Fi. Apps reconnect, or use QUIC connection migration. Proxy Mobile IPv6 was used in some carrier designs, but Mobile IPv6 itself on end hosts never caught on.
Does BCP 38 stop all spoofing?
No, only where networks apply it. A spoofed packet is blocked at its first hop if the access network filters. If it doesn't, nothing later on the path can reliably tell a forged source from a real one. Measurements still find that a significant share of networks allow spoofed traffic out.
Summary
- A host with several addresses follows either the weak host model (addresses belong to the host, the Linux default) or the strong host model (addresses belong to interfaces, the Windows default). Linux can be tightened with
arp_ignore,arp_announce,rp_filterand firewall rules. - RFC 6724's source selection rules choose among a host's addresses: same address, scope, not deprecated, home address, outgoing interface, label, temporary, then longest matching prefix.
- Its destination selection rules sort a name's addresses for
getaddrinfo(). With the default table, global IPv6 (precedence 40) beats IPv4 (35), which beats ULAs (3). glibc's built-in table follows older values, and/etc/gai.confchanges it. - Mobile IP gives a mobile node a permanent home address, with a home agent tunneling traffic to its current care-of address. Route optimization with return routability removes the detour. It's rarely used on end hosts today.
- IP fields can't be trusted: spoofing (stopped by BCP 38 ingress filtering), malformed headers, option and fragment tricks all exploit that.
Practice questions
1. A Linux host has eth0 192.0.2.5 and eth1 198.51.100.5, both up. A packet addressed to 198.51.100.5 arrives on eth0. With default settings, is it accepted? What setting change would make the host drop it?
Answer
Yes. Linux follows the weak host model, so any local address is accepted on any interface. The kernel has no direct strong-host switch for this. Strict reverse path filtering (rp_filter=1) drops it if the source address wouldn't be routed out eth0, and a firewall rule matching the incoming interface and destination drops it in all cases.
2. A host has addresses 2001:db8:1::a (preferred) and 2001:db8:1::b (deprecated), and a temporary address 2001:db8:1:0:5c1e::7 (preferred). Which source does it use to reach 2001:db8:9::1, and which rule decides?
Answer
Rule 3 eliminates the deprecated ::b. Between ::a and the temporary address, rules 4 to 6 tie (same interface, same label), and rule 7 prefers the temporary address, provided the host's policy prefers temporary addresses, which is the RFC default. So 2001:db8:1:0:5c1e::7.
3. A name resolves to 2001:db8:3::10 and 203.0.113.10. The host has only a link-local IPv6 address and a global IPv4 address. Which is tried first, and why?
Answer
203.0.113.10. To reach the global IPv6 address the host would have to use its link-local address as the source, and rule 2 prefers destinations whose scope matches the source's scope. IPv4's scope matches, so it wins before precedence is ever compared.
4. In Mobile IPv6 with bidirectional tunneling, what source and destination addresses does the outer header of a packet from the home agent to the mobile node carry? And the inner header?
Answer
Outer: source is the home agent's address, destination is the mobile node's care-of address. Inner: the original packet from the correspondent, with the correspondent as source and the mobile node's home address as destination.
5. Why does return routability send one test through the home agent and one directly to the care-of address?
Answer
It checks that the node sending the Binding Update can receive packets at both addresses it's claiming: the home address (through the home agent) and the care-of address (directly). An attacker who can see traffic at only one of them can't collect both tokens, so it can't redirect someone else's home address to an address of its choosing.
6. An ISP applies BCP 38 on its customer links. Can a customer on 198.51.100.0/24 still launch a reflection attack using a spoofed source of 203.0.113.7?
Answer
No. The ISP drops packets from that customer whose source address isn't inside 198.51.100.0/24, so the spoofed packets never leave the access network. The customer could still spoof other addresses inside its own /24, which is why filtering at the very edge, as close to the hosts as possible, is best.
Review quiz
Test yourself on the Internet Protocol: the IPv4 and IPv6 headers, the checksum, DSCP and ECN, options and extension headers, forwarding and address selection.
Quiz: The Internet Protocol (TCP/IP Part 4)
Previous: IP Forwarding: Routing Tables, Longest Prefix Match and Following a Packet
Next: DHCP Basics: Leases, Address Pools, the Message Format and Options

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.