XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Can't get dns to work with cloud-init on debian11

    Scheduled Pinned Locked Moved Advanced features
    8 Posts 2 Posters 1.3k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ditzy-oliveD Offline
      ditzy-olive
      last edited by

      I've read this post and also been trying my own research but I just can't get it to work.

      https://xcp-ng.org/forum/topic/6777/cloud-init-network-config-not-applying-to-debian-11-6?_=1692953942818

      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/24
      

      The result is this file data in /etc/network/interfaces.d/50-cloud-init

      auto 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/24
      

      how 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/interfaces but nothing regarding eth1

      This cloud-init stuff is driving me bananas!

      1 Reply Last reply Reply Quote 0
      • olivierlambertO Offline
        olivierlambert Vates 🪐 Co-Founder CEO
        last edited by olivierlambert

        This is a Debian question 🙂 You might check you have the resolvconf package installed, that's where it will check the DNS in the interfaces file and automatically fill the resolv file 🙂

        ditzy-oliveD 1 Reply Last reply Reply Quote 0
        • ditzy-oliveD Offline
          ditzy-olive @olivierlambert
          last edited by

          @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?

          1 Reply Last reply Reply Quote 0
          • olivierlambertO Offline
            olivierlambert Vates 🪐 Co-Founder CEO
            last edited by

            Why not passing the content of the resolvconf file via Cloudinit?

            ditzy-oliveD 1 Reply Last reply Reply Quote 0
            • ditzy-oliveD Offline
              ditzy-olive @olivierlambert
              last edited by

              @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.

              1 Reply Last reply Reply Quote 0
              • olivierlambertO Offline
                olivierlambert Vates 🪐 Co-Founder CEO
                last edited by

                https://cloudinit.readthedocs.io/en/18.5/topics/examples.html#configure-an-instances-resolv-conf

                ditzy-oliveD 1 Reply Last reply Reply Quote 0
                • ditzy-oliveD Offline
                  ditzy-olive @olivierlambert
                  last edited by

                  @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_files and this works:

                  write_files:
                    - path: /etc/resolv.conf
                      content: |
                        domain exmple.com
                        search example.com
                        nameserver 192.168.20.1
                  

                  this 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 reboot
                  

                  the 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/24
                  

                  but now it seems I forgot the MTU but this is a different story, thanks for the hint in the right direction.

                  1 Reply Last reply Reply Quote 1
                  • olivierlambertO Offline
                    olivierlambert Vates 🪐 Co-Founder CEO
                    last edited by

                    Good news! Keep us posted 🙂

                    1 Reply Last reply Reply Quote 0
                    • olivierlambertO olivierlambert moved this topic from Xen Orchestra on
                    • First post
                      Last post