Ubuntu Cloud Init: Setting DNS not working

Vengance

Renowned Member
May 21, 2016
271
12
83
34
Hi,
I'm using the official ubuntu 22.04 cloud image which I'm customizing with cloud-init.
All settings work, except setting the nameserver.


It always sticks to the default nameserver.
Has anyone else run into a similar issue?


I've also tried installing resolvconf, but still same issue.

/etc/resolv.conf
Code:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 127.0.0.53

Code:
root@asdfasdfasdf:~# resolvectl status
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: foreign

Link 2 (eth0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
 
I'm using the built in Cloud Init integration.
Yea, I checked the log but nothing unusual.

Also checked the ISO, it has the DNS server listed just fine, it just doesn't get applied to the network configuration.
Code:
root@pve2:~# qm cloudinit dump 113 network
version: 1
config:
    - type: physical
      name: eth0
      mac_address: '62:43:a0:b9:3f:75'
      subnets:
      - type: ipv6_slaac
    - type: nameserver
      address:
      - '2a03:7900:2:0:31:3:104:161'
      search:
      - 'demo.de'

Code:
root@pve2:~# qm config 113
agent: 1
boot: c
bootdisk: scsi0
ciuser: root
ide2: local-lvm:vm-113-cloudinit,media=cdrom,size=4M
ipconfig0: ip6=auto
memory: 2048
meta: creation-qemu=6.2.0,ctime=1656540802
name: asfasfsaasas
nameserver: 2a03:7900:2:0:31:3:104:161
net0: virtio=62:43:A0:B9:3F:75,bridge=vmbr0
scsi0: local-lvm:vm-113-disk-0,size=2252M
scsihw: virtio-scsi-pci
serial0: socket
smbios1: uuid=9b6ccc10-c53d-4c1d-b7a9-e9d07af5e2f0
sshkeys: ssh-rsa....
vga: serial0
vmgenid: b50cca61-7fe6-45ec-a811-5f26aaf41b72
 
As bbgeek17 noted, please check the cloud-init log. It should contain any errors encountered during boot.
 
I already checked the log but I cant find anything that would explain why the nameserver won't get set.

It's working just fine on my Debian based systems, just Ubuntu doesn't want to apply the nameserver.


Code:
2022-06-30 11:13:44,496 - stages.py[INFO]: Applying network configuration from ds bringup=False: {'version': 1, 'config': [{'type': 'physical', 'name': 'eth0', 'mac_address': '06:70:c5:13:04:1e', 'subnets': [{'type': 'ipv6_slaac'}]}, {'type': 'nameserver', 'address': ['2a03:7900:2:0:31:3:104:161'], 'search': ['domain.de']}]}


Code:
root@cloudinit:~# resolvectl
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (eth0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported


Code:
root@cloudinit:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 127.0.0.53
 
Last edited:
Oh, it seems you don't use resolvectl. I'd suggest installing the package resolvconf.
This was necessary in the past as well sometimes.
 
Oh, it seems you don't use resolvectl. I'd suggest installing the package resolvconf.
This was necessary in the past as well sometimes.


I was working on the wrong VM, I just installed resolvconf on this system as well but still the same issue

Code:
root@cloudinit:~# service resolvconf status
● resolvconf.service - Nameserver information manager
     Loaded: loaded (/lib/systemd/system/resolvconf.service; enabled; vendor preset: enabled)
     Active: active (exited) since Thu 2022-06-30 11:22:20 UTC; 2min 24s ago
       Docs: man:resolvconf(8)
    Process: 346 ExecStart=/sbin/resolvconf --enable-updates (code=exited, status=0/SUCCESS)
   Main PID: 346 (code=exited, status=0/SUCCESS)
        CPU: 2ms

Notice: journal has been rotated since unit was started, output may be incomplete.
 
Try running cloud-init clean and then reboot.
Perhaps the settings were already set and cloud-init discarded it because there was no change.
 
Try running cloud-init clean and then reboot.
Perhaps the settings were already set and cloud-init discarded it because there was no change.
I just did exactly that, didn't work either.


So cloud-init gets the correct nameserver
Code:
# cat /var/log/cloud-init.log  | grep "2a03:7900:2:0:31:3:104:161"
2022-06-30 11:28:09,142 - stages.py[INFO]: Applying network configuration from ds bringup=False: {'version': 1, 'config': [{'type': 'physical', 'name': 'eth0', 'mac_address': '06:70:c5:13:04:1e', 'subnets': [{'type': 'ipv6_slaac'}]}, {'type': 'nameserver', 'address': ['2a03:7900:2:0:31:3:104:161'], 'search': ['domain.de']}]}
2022-06-30 11:28:13,604 - stages.py[DEBUG]: applying net config names for {'version': 1, 'config': [{'type': 'physical', 'name': 'eth0', 'mac_address': '06:70:c5:13:04:1e', 'subnets': [{'type': 'ipv6_slaac'}]}, {'type': 'nameserver', 'address': ['2a03:7900:2:0:31:3:104:161'], 'search': ['domain.de']}]}

I seems like it just doesn't get applied for some reason
Code:
root@cloudinit:~# resolvectl
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: foreign

Link 2 (eth0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
 
The /var/log/cloud-init.log clearly shows that DNS portion of the network is not applied when IP is set to dhcp. Setting IP to static address applies the dns settings.
I suspect this is not a PVE "problem" and rather a "feature" of cloud-init. If you invest time in finding out why - please share with community. You may need to reach out to cloud-init/ubuntu dev lists.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Hmm are you sure about that?I'm using the same configuration on Debian Cloud images, specifying the DNS works just fine there, even with SLAAC
 
Code:
qm importdisk 100 /mnt/pve/bbnas/template/iso/kinetic-server-cloudimg-amd64-disk-kvm.img blockbridge --format raw

root@pve7demo1:~# qm config 100
agent: 1
boot: c
bootdisk: scsi0
cipassword: **********
ide2: blockbridge:vm-100-cloudinit,media=cdrom
ipconfig0: ip=172.16.101.204/24,gw=172.16.101.1
memory: 512
meta: creation-qemu=6.2.0,ctime=1656597989
name: vm100
nameserver: 8.8.8.8
net0: virtio=22:50:7D:7F:C1:D2,bridge=vmbr0,firewall=1
onboot: 0
searchdomain: blockbridge.com
serial0: socket
smbios1: uuid=ef032b40-cc8b-4a83-a905-80284ddce485
sockets: 1
vga: serial0
virtio0: blockbridge:vm-100-disk-0,size=2252M
vmgenid: 1c304310-b1ae-45ac-9e87-5f911f0364b4

qm start 100

 ssh ubuntu@172.16.101.204 resolvectl status
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (eth0)
    Current Scopes: DNS
         Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 8.8.8.8
       DNS Servers: 8.8.8.8
        DNS Domain: blockbridge.com
        
ssh ubuntu@172.16.101.204  cat /etc/debian_version
bookworm/sid



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
I’ll have to check with Ubuntu 22.10, I’m using the 22.04 image

But that still doesn’t make sense to me, especially as this works on Debian
 
The difference is the renderer used by cloud-init. For Debian the `eni` renderer is used, while for Ubuntu the `netplan` one is used.
Maybe it creates a netplan config that can't handle the nameserver.
You should be able to check the netplan config in /etc/netplan/50-... or so.
It wouldn't be the first config that requires some special handling for netplan, which in theory wouldn't be difficult when cloud-init's network config v2 is used, as that is basically a subset of netplan, but we're still on v1 for legacy support reasons.
Maybe we could evaluate this in the future for PVE 8.
 
  • Like
Reactions: bbgeek17
The Netplan config doesn't seem to contain any settings related to the nameserver.
I just hopped into the cloud-init irc, someone also told me this might be an issue with v1-> netplan.

So the only way to fix this is to migrate to the network config v2?


Code:
root@cloudinit:~# cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        eth0:
            dhcp6: true
            match:
                macaddress: 06:70:c5:13:04:1e
            set-name: eth0
 
Are there any specific plans to migrate to v2?
Any maybe even a rough timeframe?

I’ve also seen a different network related issue on the Debian cloud image, but I’ll create a separate thread for that.
Im afraid it might also be related to v1

Edit:
I'm also wondering why I cant find any similar threads to this, I mean I cant be the first one that wants to set a custom nameserver for a ubuntu cloud image, right?
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!