Can't get dns to work with cloud-init on debian11
-
I've read this post and also been trying my own research but I just can't get it to work.
This is my network cloud init configuration
network: version: 1 config: - type: physical name: eth0 subnets: - type: static address: 192.0.2.6/28 gateway: 192.0.2.1 - type: nameserver interface: eth0 address: - 9.9.9.9 - 1.1.1.1 search: - example.com - type: physical name: eth1 subnets: - type: static address: 10.10.10.6/24The result is this file data in
/etc/network/interfaces.d/50-cloud-initauto lo iface lo inet loopback dns-nameservers 9.9.9.9 1.1.1.1 dns-search example.com auto eth0 iface eth0 inet static address 192.0.2.6/28 gateway 192.0.2.1 auto eth1 iface eth1 inet static address 10.10.10.6/24how do I get the network in such a way that DNS also works? If I add my nameservers to /etc/resolv.conf everything works.
I'm also a bit confused as why I have eth0 as dhcp on in/etc/network/interfacesbut nothing regardingeth1This cloud-init stuff is driving me bananas!
-
This is a Debian question
You might check you have the resolvconfpackage installed, that's where it will check the DNS in the interfaces file and automatically fill the resolv file
-
@olivierlambert it's not that simple I guess. Because I can't install anything without having DNS during the cloud-init

Everything works fine if I use DHCP but this would result in eth0 being my internal network and default GW being via the internal router and eth1 having my public IP.
I want it the other way round
The second solution would be to use DHCP to get everything installed then nuke the whole cloud-init stuff and configure network manually. Bit of a pain I guess.
How are other people dealing with this whole clod-init on debian? -
Why not passing the content of the resolvconf file via Cloudinit?
-
@olivierlambert sure ... how?
I couldn't find out how to do that. Looking into that option right now but if you have some hints I would appreciate it. -
-
@olivierlambert Thanks, just stumbled over this a few minutes ago and tried it, but doesn't work. According to https://www.digitalocean.com/community/tutorials/an-introduction-to-cloud-config-scripting#write-files-to-the-disk
This currently only works for RHEL-based distributions.
But this led me to
write_filesand this works:write_files: - path: /etc/resolv.conf content: | domain exmple.com search example.com nameserver 192.168.20.1this is the full configuration I use:
#cloud-config hostname: {name} timezone: Europe/Vienna users: - default - name: johndow passwd: **** sudo: ALL=(ALL) NOPASSWD:ALL groups: users, admin, sudo shell: /bin/bash lock_passwd: true ssh_authorized_keys: - ssh-ed25519 AAAA**** write_files: - path: /etc/resolv.conf content: | domain example.com search example.com nameserver 192.168.20.1 package_update: true packages: - sudo - htop - vim - python - tmux package_upgrade: true runcmd: - sudo rebootthe Network configuration looks like this:
version: 2 ethernets: eth0: match: name: eth0 addresses: - 192.168.20.6/28 gateway4: 192.168.20.1 eth1: match: name: eth1 addresses: - 10.10.10.6/24but now it seems I forgot the MTU but this is a different story, thanks for the hint in the right direction.
-
Good news! Keep us posted

-
O olivierlambert moved this topic from Xen Orchestra on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login