GAURAV GARG
GAURAV GARG

Reputation: 91

Using cloud-init to change resolv.conf

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?

Upvotes: 9

Views: 22262

Answers (2)

newbie17
newbie17

Reputation: 197

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}

Upvotes: 0

nicolasochem
nicolasochem

Reputation: 467

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.

Upvotes: 2

Related Questions