Using cloud-init to change resolv.conf
Asked Answered
V

2

7

I want my setup of openstack to work such that when I boot a new instance, 8.8.8.8 should be added to dns-nameservers.

This is my old /etc/resolv.conf (in the new VM which was spawned in openstack)-

nameserver 10.0.0.2
search openstacklocal

And this is the new resolv.conf that I want -

nameserver 8.8.8.8
nameserver 10.0.0.2
search openstacklocal

I followed this tutorial, and I have added the necessary info. of resolv conf to my config file(/etc/cloud/cloud.cfg) of cloud-init -

manage_resolv_conf: true

resolv_conf:
  nameservers: ['8.8.4.4', '8.8.8.8']
  searchdomains:
    - foo.example.com
    - bar.example.com
  domain: example.com
  options:
    rotate: true
    timeout: 1

These changes are made in /etc/cloud/cloud.cfg file of the openstack host. However, the changes don't seem to get reflected.

Any suggestions?

Valera answered 11/2, 2018 at 20:52 Comment(2)
Did you include the #cloud-config header in the first line of the file?Triennial
Did you systemctl restart cloud-init?Pinta
I
2

It will not work because cloud-init networking configuration occurs too early in the boot process.

See cloud-init stages: https://cloudinit.readthedocs.io/en/latest/topics/boot.html

Network configuration is done in the "Local" stage, but the user-data from Openstack is only downloaded at the "Config" stage after network is up. At this stage, the network configuration is ignored.

Instead, you need to edit networking files then bring interfaces up by passing commands to cloud-init with runcmd.

Ivelisseivens answered 26/9, 2018 at 20:37 Comment(0)
D
0

Cloud-init overwrites the entry of /etc/sysconfig/network file as well as resolv.conf . To disable this you can create a custom rule for cloud-init config by creating a file /etc/cloud/cloud.cfg.d/custom-network-rule.cfg which contains -

network: {config: disabled}
Diplosis answered 12/5, 2020 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.