【问题标题】:Using cloud-init to change resolv.conf使用 cloud-init 更改 resolv.conf
【发布时间】:2018-07-22 00:36:23
【问题描述】:

我希望我的 openstack 设置能够正常工作,以便在我启动新实例时,应将 8.8.8.8 添加到 dns-nameservers。

这是我的旧 /etc/resolv.conf(在 openstack 中生成的新 VM 中)-

nameserver 10.0.0.2
search openstacklocal

这就是我想要的新的 resolv.conf -

nameserver 8.8.8.8
nameserver 10.0.0.2
search openstacklocal

我遵循this 教程,并且 我已经添加了必要的信息。将 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

这些更改在 openstack 主机的 /etc/cloud/cloud.cfg 文件中进行。 但是,这些变化似乎没有得到体现。

有什么建议吗?

【问题讨论】:

  • 您是否在文件的第一行包含#cloud-config 标头?
  • 是的,先生。我做到了。
  • systemctl restart cloud-init了吗?

标签: openstack nameservers cloud-init


【解决方案1】:

它不会起作用,因为 cloud-init 网络配置在启动过程中发生得太早。

查看 cloud-init 阶段:https://cloudinit.readthedocs.io/en/latest/topics/boot.html

网络配置在“本地”阶段完成,但来自 Openstack 的用户数据仅在网络启动后的“配置”阶段下载。在这个阶段,网络配置被忽略了。

相反,您需要编辑网络文件,然后通过使用 runcmd 将命令传递给 cloud-init 来启动接口。

【讨论】:

    【解决方案2】:

    Cloud-init 会覆盖 /etc/sysconfig/network 文件以及 resolv.conf 的条目。要禁用此功能,您可以通过创建包含 -

    的文件 /etc/cloud/cloud.cfg.d/custom-network-rule.cfg 来为 cloud-init 配置创建自定义规则
    network: {config: disabled}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2018-09-24
      • 2020-07-06
      • 2014-08-16
      • 2019-09-06
      相关资源
      最近更新 更多