Resolve FQDN instead of shortnames

My current local domain is lan.

Context: Newbie in networking. I dynamically create LXC containers in Proxmox. I want to configure the containers with Ansible, but I need an IP address or hostname for that. Proxmox can't tell me what IP addresses the DHCP server assigns to containers without ugly workarounds, but I can choose a hostname.

Suppose I give a container the hostname subdomain.mydomain.com. The following domains resolve:

  • subdomain
  • subdomain.lan

The following domains don't resolve:

  • subdomain.mydomain
  • subdomain.mydomain.com
  • subdomain.mydomain.lan

Since there are different deployment environments, I expect to be able to resolve FQDNs, such as subdomain.mydomain.com, to avoid conflicts with domains starting with the same label, such as app.dev.mydomain.com and app.prod.mydomain.com.

I could rely on one domain level; flatten the DNS structures, and prepend a unique deployment identifier to hostnames, but I want to stay as close as possible to what the production environment looks like, and keep project porting work as close to zero as possible.

I may link to the resources I tried to apply after I slept over my hours long shotgun debugging session. I think, unsure on the details and outcomes, I tried to do the following:

  • Lua cgi script to resolve mac addresses to IP addresses since I know container mac addresses. I didn't use the script because I would've needed to patch several libraries. Probably also not future-proof, I would need to port the script to other distros, such as pfSense, I assume.
  • Develop a python web API for Proxmox to get IP addresses by VM ids using shell commands inside containers, which didn't work well due to different distros and poor performance.
  • Use some sort of script, /etc/hotplug.d/dhcp/00-custom.???, which should've enabled subdomain support, but didn't.
  • Selective DNS forwarding with uci add_list dhcp.@dnsmasq[0].server="/mydomain.com/192.168.0.1"
  • Replace /lan/ with /lan/mydomain.com/.

In OpenWrt 22.03+

Network>DHCP and DNS>Hostnames

after CNAME
https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#cname_rr

Do I understand correctly that you want me to perform the following steps?

  1. Assign MAC address a static IP address.
  2. Set hostname for static IP address in the luci web interface.
  3. Create a CNAME record. What purpose does the CNAME record serve in this context? Help me understand.

If I interpreted the steps correctly, then I believe they don't solve my problem: Make the exact hostname DHCP clients ask for resolvable. Preferably with a domain suffix whitelist to prevent DNS hijacking. When a client asks for the hostname subdomain.mydomain.com, the exact hostname must be resolvable in the network—not just subdomain.

A static IP solution is unacceptable because environments must be available on demand, not merely whenever I'm at home able to configure OpenWrt.

Add hostnames in OpenWrt

e.g.
Hostaname
mydomain.lan

IP address
<\YOUR IP ADDRESS>

after mydomain.lan

Or if there are ports, do it like this mydomain.lan:8080 (manually enter the port)

I greatly appreciate your help, but I don't understand how this solves my problem. What you suggest is to set hostnames in OpenWrt manually, which I want to avoid for the reasons mentioned in my preceding posts.