CentOS 7.x cloud-init or dhclient based DNS configuration

From Notes_Wiki

Home > CentOS > CentOS 7.x > System Administration > CentOS 7.x cloud-init or dhclient based DNS configuration

If we configure DNS using DNS1=4.2.2.2 in /etc/sysconfig/network-scripts/ifcfg-eth0 on CentOS 7 AWS lightsail cloud instances. Then on reboot the DNS in /etc/resolv.conf is still VPC DNS and not custom DNS as cloud-init calls dhclient and dhclient puts DHCP based DNS in the file. To prevent cloud-init and dhclient from changing custom DNS, use following steps:

  1. Edit /etc/dhcp/dhclient.conf and use
    supersede domain-name-servers 4.2.2.2, 8.8.8.8;
  2. to replace DNS with custom DNS. If you do not want to replace DHCP based DNS but prepend some other DNS with higher priority then use below instead:
    prepend domain-name-servers 4.2.2.2, 8.8.8.8;
  3. Reboot instance and do "cat /etc/resolv.conf" to validate

Refer:


Using cloud-init to update DNS

As per https://cloudinit.readthedocs.io/en/latest/topics/examples.html#configure-an-instances-resolv-conf we should be able to add below to /etc/cloud/cloud.cfg:

   manage_resolv_conf: true
   
   resolv_conf:
   nameservers: ['8.8.4.4', '8.8.8.8']
   searchdomains:
    - rekallsoftware.com
   domain: rekallsoftware.com
   options:
    rotate: true
    timeout: 1

but this has not worked by simply editing cloud.cfg and appending above configuration. Perhaps more steps are required.


Home > CentOS > CentOS 7.x > System Administration > CentOS 7.x cloud-init or dhclient based DNS configuration