In this lesson, you will learn how to orchestrate the lifecycle of IPv4 and IPv6 addresses on modern Linux interfaces, moving beyond simple static configuration into dynamic address management.
Managing addresses today requires understanding that an interface can hold multiple addresses simultaneously, each with its own state and preferred status. When we talk about "address management," we are looking at how the kernel tracks these addresses through the netlink interface and how we define their lifecycles.
Managing Address Lifecycles
In modern networking, particularly with IPv6, addresses are rarely just "static." They go through states: tentative, preferred, deprecated, and invalid. Using the ip command suite, you can manage these states to ensure your services don't bind to stale IPs.
For instance, when adding an address, you can explicitly define the lifespan of the assignment. This is vital for temporary IPv6 addresses (Privacy Extensions) or automated failover scenarios where an address must expire automatically if not refreshed.
# Add an IPv6 address that automatically becomes deprecated after 3600 seconds
ip -6 addr add 2001:db8::1/64 dev eth0 preferred_lft 3600 valid_lft 7200
The Concept of Secondary Addresses
Unlike older operating systems that often struggled with multi-homing, the Linux kernel manages address lists on interfaces seamlessly. Every interface can host a virtually unlimited number of IPv4 and IPv6 addresses.
When you add an address to an interface, you are interacting with the inet (IPv4) and inet6 (IPv6) protocols within the kernel stack. If you need to perform "address scoping," you can use the scope parameter. For example, setting an address to link scope restricts that IP to the local segment, preventing it from being routed by the kernel stack to the wider network.
Managing Address Flags
You can also toggle address flags to suit your deployment. If you are handling complex routing for microservices, you might use the noprefixroute flag. This tells the kernel not to automatically install a route in the main routing table for that specific address, giving you full manual control over how traffic flows through your network namespace.
Key Takeaway: Managing modern address lifecycles involves using preferred_lft and valid_lft to automate address expiration and leveraging interface flags to exert granular control over how the kernel handles routing for each assigned IP.