AWS Cloud-Config未设置dns-nameservers

时间:2018-11-19 15:01:31

标签: amazon-web-services amazon-ec2 cloud cloud-init

这是我的实例上的cloud.cfg(配置从中启动实例的ami时,我曾对其进行了手动篡改)

root@ip-10-17-0-121:~# cat /etc/cloud/cloud.cfg | grep -i resol -C 3

# Network configuration for ami
manage_resolv_conf: true

resolv_conf:
  nameservers: ['10.11.4.1']

但是,鉴于以下情况,永远不会考虑到这一点:

# cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.17.0.2
search eu-west-1.compute.internal

我尝试过创建或不创建以下文件

# cat /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}

1 个答案:

答案 0 :(得分:0)

我设法使我的实例按如下方式获取我的自定义dns-nameserver

- name: pre_tasks --> Add my custom dns-nameserver
  lineinfile:
   path: /etc/dhcp/dhclient.conf
   regexp: '^#prepend domain-name-servers'
   line: 'prepend domain-name-servers 10.11.4.1;'
  become: yes

但是现在我收到以下警告:

pkara@ip-10-17-0-35:~$ sudo -i
sudo: unable to resolve host ip-10-17-0-35

直到/除非我解决这个问题,否则我不接受我的回答;

edit_1 :将其添加到我设置为用户数据的cloud-config.yml并没有太大帮助:

hostname: localhost
manage_etc_hosts: true

edit_2 :将其添加到我的cloud-config.cfg中有助于解决上述unable to resolve host问题

bootcmd:
  - echo "127.0.0.1 $(hostname)" >> /etc/hosts