Skip to content

Commit

Permalink
Fix DNS resolution in initramfs (#367)
Browse files Browse the repository at this point in the history
Add DNS servers to /etc/resolv.conf after interfaces are setup via configure_networking:
* create /etc/resolv.conf from network infos of all configured interfaces
* include libnss_dns.so + libnss_files.so in initramfs
* copy libs into initrd required for DNS resolution
  • Loading branch information
abrychcy authored Feb 16, 2024
1 parent ea7a8e1 commit bebb037
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/initramfs-tools/hooks/clevis.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ bash_bin=$(find_binary "bash")
copy_exec "${curl_bin}" || die 2 "Unable to copy ${curl_bin} to initrd image"
copy_exec "${awk_bin}" || die 2 "Unable to copy ${awk_bin} to initrd image"
copy_exec "${bash_bin}" || die 2 "Unable to copy ${bash_bin} to initrd image"

# Copy latest versions of shared objects needed for DNS resolution
for so in $(ldconfig -p | sed -nr 's/^\s*libnss_files\.so\.[0-9]+\s.*=>\s*//p'); do
copy_exec "${so}"
done
for so in $(ldconfig -p | sed -nr 's/^\s*libnss_dns\.so\.[0-9]+\s.*=>\s*//p'); do
copy_exec "${so}"
done
17 changes: 17 additions & 0 deletions src/initramfs-tools/scripts/local-top/clevis.in
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ do_configure_networking() {
echo "clevis: Warning: multiple network interfaces available but no ip= parameter provided."
fi
configure_networking

# Add DNS servers from configure_networking to /etc/resolv.conf
if [ ! -e /etc/resolv.conf ]; then
touch /etc/resolv.conf
for intf in /run/net-*.conf; do
. "${intf}"
if [ ! -z "${IPV4DNS0}" ] && [ "${IPV4DNS0}" != "0.0.0.0" ]; then
echo nameserver "${IPV4DNS0}" >> /etc/resolv.conf
fi
if [ ! -z "${IPV4DNS1}" ] && [ "${IPV4DNS1}" != "0.0.0.0" ]; then
echo nameserver "${IPV4DNS1}" >> /etc/resolv.conf
fi
if [ ! -z "${IPV6DNS0}" ]; then
echo nameserver "${IPV6DNS0}" >> /etc/resolv.conf
fi
done
fi
fi
}

Expand Down

0 comments on commit bebb037

Please sign in to comment.