Allocate custom IPv6 address using Netplan

hqs Posted on 26 days ago 64 Views


A custom IPv6 address can be allocated from a larger subnet like /64 using netplan on Ubuntu20.04 or later

Suppose your current IPv6 address is 2001:dbb:1:2:3:4:5:6/64.

Edit netplan config file /etc/netplan/50-cloud-init.yaml.

Modify the addresses field:

addresses:
- "1.1.1.1/32" # This is your IPv4 address, do not change
- "2001:dbb:1:2:3:4:5:6/64" # This is your current IPv6 address
- "2001:dbb:1:2::/64" # This is the new IPv6 address you want to assign, choose based on personal preference

Next, disable DHCPv6 and enable automatic reception of IPv6 router advertisements(if it's on). IPv6 does not require setting a default route.

dhcp6: no # Change from yes to no
accept-ra: true # This line is newly added

No other changes are needed. After saving and restarting, your network interface will be configured with both 2001:dbb:1:2::/64 and 2001:dbb:1:2:3:4:5:6/64 IPv6 addresses simultaneously.

If you are certain that the old IPv6 address is no longer in use, you can remove it from the addresses field.

Unlike IPv4, in IPv6, addresses like 2001:dbb:1:2:: with the host part all zeros are also valid. Consecutive zeros can be replaced with a double colon to compress the address length, but the double colon can only appear once. It is also not recommended to use addresses with the host part all zeros; in such cases, you can append a non-zero value at the end, such as 2001:dbb:1:2::1. Users can choose based on their needs.

This author has not provided a description.
Last updated on 2024-10-25