Configuring custom DNS setting for EC2 Instance
July 26, 2019
July 26, 2019
If you are running AWS Directory Services, the managed Active Directory Service from AWS, you probably have noticed some issues with name resolution. Mainly, when you setup this service, you are provided with DNS addresses of your Active Directory servers. You need these in order for any machine that will authenticate against AD to be able to reach the servers to perform the authentication.
So you went ahead and set these two DNS addresses in your DHCP options set for your VPC and then weird things started to happen. Mainly, you notice it’s not so easy to get to some AWS services that require resolution within AWS. Even if you set a forwarder in the DNS setting, you have this problem. If you edit your machines /etc/resolv.conf file, it will just get reset by DHCP each time that the machine reboots. Luckily, there is a way to overcome this.
With Amazon Linux, you’ll need to edit /etc/dhcp/dhclient.conf. Within that file you can use the supersede directive, to force the machine to have the DNS settings it needs. By default the file usually has the timeout value for dhcp. Simply add a line to the file:
supersede domain-name-servers xxx.xxx.xxx.xxx
If you need to have multiple DNS servers, Managed Directory Service provides one for each availability zone, then you would just add them as comma separated entries with a space after the comma.
supersede domain-name-servers xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx
Then just stop and start the instance and it will come up using the DNS servers of your choosing.
Advanced Data Engineering Platform for Cleansing, Preprocessing and Analytics