cloud-init dhcp does not set domain or search in /etc/resolv.conf

teacup91

New Member
Sep 3, 2023
6
1
3
My VM is Debian 12 cloud image. Everything in built-in CI works except the domain and search are not set in /etc/resolv.conf when I set network to DHCP (working if network is static IP). Here is the content
Code:
# This is /run/systemd/resolve/resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 172.16.100.2
search .
Screenshot 2024-06-19 at 6.55.20 PM.png

I tried with normal DVD ISO image and both domain and search are set probably from DHCP server. I'm not too sure if this is related to the Debian 12 cloud image, or cloud-init in Proxmox, but I guess I could reach more people here. Thank you for everyone's commenting.

UPDATE: Upon more research, Debian 12 cloud is using systemd-resolve. However, /etc/systemd/resolved.conf is basically empty. If I set Domains here, it will append search local.domain.com to /etc/resolv.conf so how can I fix this in cloud-init?
Code:
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it under the
#  terms of the GNU Lesser General Public License as published by the Free
#  Software Foundation; either version 2.1 of the License, or (at your option)
#  any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the resolved.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
#
# See resolved.conf(5) for details.

[Resolve]
# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
# Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
# Google:     8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
# Quad9:      9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
#DNS=
#FallbackDNS=
#Domains=
#DNSSEC=no
#DNSOverTLS=no
#MulticastDNS=yes
#LLMNR=yes
#Cache=yes
#CacheFromLocalhost=no
#DNSStubListener=yes
#DNSStubListenerExtra=
#ReadEtcHosts=yes
#ResolveUnicastSingleLabel=no
 
Last edited:
Its possible that this setting is being overwritten by DHCP, have you checked whether you can set this in DHCP?

Here is an example we use in one of the cases, it shows how to extract/view what is being sent via DHCP and then use that for manual adjustments.

root@pve9r1-iscsi-host1:/etc# cat ./dhcp/dhclient-exit-hooks.d/hostname-update
#!/bin/bash
set -x
if [ “${interface}” = “vmbr0” ]; then
case ${reason} in BOUND|RENEW|REBIND|REBOOT)
printenv > /tmp/variables.txt
json_output=$(ip --json address show)
interface_name=$(echo "$json_output" | grep -oP '{.*?}' | grep -P 'master":"vmbr0' | grep -oP '"ifname":"\K[^"]+')
ip link set dev $interface_name mtu $new_interface_mtu
sed -i '/pve/d' /etc/hosts
sed -i '/pve/d' /etc/hostname
echo $new_ip_address $new_host_name >> /etc/hosts
echo $new_host_name >> /etc/hostname
hostnamectl set-hostname $new_host_name
;;
esac
fi

root@pve9r1-iscsi-host1:/etc# cat /tmp/variables.txt
requested_domain_name_servers=1
requested_broadcast_address=1
new_network_number=10.0.0.0
new_ip_address=10.0.0.94
requested_domain_search=1
new_dhcp_message_type=5
pid=850
old_dhcp_lease_time=86400
requested_netbios_name_servers=1
old_network_number=10.0.2.0
old_ip_address=10.0.2.15
old_dhcp_message_type=5
new_routers=10.0.0.1
new_expiry=1763149280
new_subnet_mask=255.255.255.0
interface=vmbr0
requested_ntp_servers=1
requested_time_offset=1
new_domain_name=k.blockbridge.com
old_routers=10.0.2.2
reason=BOUND
old_expiry=1760622375
old_subnet_mask=255.255.255.0
new_interface_mtu=8950
requested_routers=1
new_rfc3442_classless_static_routes=32 169 254 169 254 10 0 0 10 0 10 0 0 1
PATH=/usr/sbin:/sbin:/bin:/usr/sbin:/usr/bin
requested_subnet_mask=1
new_host_name=pve9r1-iscsi-host1
requested_domain_name=1
new_dhcp_server_identifier=10.0.0.10
requested_interface_mtu=1
new_domain_name_servers=172.16.5.1
requested_rfc3442_classless_static_routes=1
new_broadcast_address=10.0.0.255
dad_wait_time=0
new_dhcp_renewal_time=43200
old_dhcp_server_identifier=10.0.2.2
requested_host_name=1
new_dhcp_rebinding_time=75600
PWD=/
old_domain_name_servers=10.0.2.3
requested_netbios_scope=1
old_broadcast_address=10.0.2.255
new_next_server=10.0.0.10
new_dhcp_lease_time=86400

Other than this - check CI log files that are located in /var. Also, mount the CI image (mount /dev/sr0 /mnt/temp) and check the configuration files.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox