简体   繁体   English

使用 cloud-init 更改 resolv.conf

[英]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.我希望我的 openstack 设置能够工作,这样当我启动一个新实例时,应该将 8.8.8.8 添加到 dns-nameservers。

This is my old /etc/resolv.conf (in the new VM which was spawned in openstack)-这是我的旧 /etc/resolv.conf(在 openstack 中生成的新 VM 中)-

nameserver 10.0.0.2
search openstacklocal

And this is the new resolv.conf that I want -这是我想要的新 resolv.conf -

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 -将 conf 解析到我的 cloud-init 配置文件(/etc/cloud/cloud.cfg) -

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.这些更改在 openstack 主机的 /etc/cloud/cloud.cfg 文件中进行。 However, the changes don't seem to get reflected.然而,这些变化似乎没有得到反映。

Any suggestions?有什么建议吗?

It will not work because cloud-init networking configuration occurs too early in the boot process.它不会工作,因为 cloud-init 网络配置在启动过程中发生得太早。

See cloud-init stages: https://cloudinit.readthedocs.io/en/latest/topics/boot.html查看云初始化阶段: 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.网络配置在“本地”阶段完成,但来自 Openstack 的用户数据仅在网络启动后的“配置”阶段下载。 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 .相反,您需要编辑网络文件,然后通过使用runcmd将命令传递给 cloud-init 来启动接口。

Cloud-init overwrites the entry of /etc/sysconfig/network file as well as resolv.conf . Cloud-init 会覆盖 /etc/sysconfig/network 文件以及 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 -要禁用此功能,您可以通过创建文件 /etc/cloud/cloud.cfg.d/custom-network-rule.cfg 来为 cloud-init 配置创建自定义规则,其中包含 -

network: {config: disabled}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM