Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/kickstart-templates/includes/post-network.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,24 @@ find /etc/NetworkManager -name '*.nmconnection' -print0 | while IFS= read -r -d
sed -i 's/method=.*/method=auto/g' "${file}"
fi
done

# IPv6 only feature. An IPv6 VM will use DHCPv6 to get an IP address. To identify itself to a DHCP
# server it uses something called DHCP Unique Identifier (DUID), and based on that the DHCP server
# will issue a lease for that DUID and MAC address. When the system boots into anaconda to install
# the OS with kickstart files, the DUID is automatically generated. After the system boots into the
# OS a new DUID may be generated, causing DHCP to identify the VM as a new system, thus allocating
# a new IP address. In order to avoid this, the DUID generated during the installation is saved and
# configured in NetworkManager to use it when the system boots into the OS.
# The DUID is unique per host, and is extracted from the DHCP6 options of the active connections
# from NetworkManager.
DUID=$(nmcli con show --active | \
awk '{print $1}' | \
grep -v NAME | \
xargs nmcli --fields DHCP6.OPTION con show | \
grep dhcp6_client_id | \
awk '{print $4}' | \
uniq)
Copy link
Contributor

@ggiguash ggiguash Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think converting it to a for-loop would be more straightforward?

Also, the uniq is a bit confusing - may the process return more than one DUID? If yes, we need to handle it in the code. If not, a break in the for-loop could do the job.

Copy link
Contributor Author

@pacevedom pacevedom Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the for loop would be more confusing, after all its iterating over all connections to determine which one is using DHCPv6 and take the id from there. This one liner does it in one shot. There is usually not more than 1 or 2 NICs in a single test, so most times this would be a single-iteration loop.
About the uniq: there is only one DUID per host, but if there is more than one NIC connected to ipv6 the command might return it multiple times. We know it must be the same because its system wide, hence the uniq to remove duplicates.

if [ -n "$DUID" ]; then
mkdir -p /etc/NetworkManager/conf.d/
echo -e "[connection]\nipv6.dhcp-duid=$DUID" > /etc/NetworkManager/conf.d/dhcp-client.conf
fi