Bobcares

wesupport

CLIENT AREACall Us 1-800-383-5193
Bobcares

wesupport

Call Us 1-800-383-5193
Bobcares

wesupport

Call Us 1-800-383-5193

Need help?

Our experts have had an average response time of 11.7 minutes in August 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Assign Static DNS Server to the EC2 Instance – How to do it

by | Jul 24, 2021

Wondering how to Assign Static DNS Server to the EC2 Instance? We can help you.

Before we change the Amazon EC2 instance, we need to create a backup using an Amazon Machine Image (AMI) or an Amazon Elastic Block Store snapshot.

Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.

Today, let us see how to configure an Amazon EC2 instance with static DNS server entries that persist during reboot.

 

Assign Static DNS Server to the EC2 Instance

By default, an Amazon EC2 instance requests a DNS server address at startup using the Dynamic Host Configuration Protocol (DHCP).

The DHCP response returns DNS server addresses to the local /etc/resolv.conf file.

However, we may lose the manual modification in the resolv.conf file with custom DNS server addresses when we restart the instance.

 

How to Assign Static DNS Server?

Moving ahead, let us see how our Support Techs assign this to different Linux Distributions.

  • Amazon Linux, Amazon Linux 2

Our Support Techs recommend one of the following options to configure the Amazon EC2 instance.

For either option to work, we should set the PEERDNS parameter value in the ifcfg-eth0 file to yes.

Option 1:

1. Initially, we need to edit or create the /etc/dhcp/dhclient.conf file.

2. Then we add the supersede command to the file to override the domain-name-servers.

For example,

supersede domain-name-servers xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx;

Here, we replace xxx.xxx.xxx.xxx with the IP address of the DNS server or servers that we want the instance to use.

Once done, the resolv.conf file will contain only the DNS servers that we specify in the dhclient file.

3. After that, we set the PEERDNS parameter to yes in the per-interface configuration files.

4. Finally, we reboot the EC2 instance.

Option 2:

1. Initially, we override the DNS server values in the /etc/dhcp/dhclient.conf file.

To do so, we specify the custom DNS servers in the per-interface configuration files.

For example,

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
PERSISTENT_DHCLIENT=yes
RES_OPTIONS="timeout:2 attempts:5"
DHCP_ARP_CHECK=no
MTU="9001"
DNS1=8.8.8.8
DNS2=8.8.4.4

2. Then we set the PEERDNS parameter to yes in the per-interface configuration files.

  • Ubuntu 16.04

1. Likewise, here we edit or create the /etc/dhcp/dhclient.conf file.

2. Then we add the supersede command to the file to override the domain-name-servers.

For example,

supersede domain-name-servers xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx;

Once done, the resolv.conf file updates at instance reboot to contain only the DNS servers that we specify in the dhclient file.

3. Later we reboot the instance.

  • Ubuntu 18.04

By default on Ubuntu 18.04, the netplan.io package handles the network interface configuration, and the systemd-resolved service handles DNS queries using a stub resolver.

The supersede statement in /etc/dhcp/dhclient.conf will not work if either of the following is true for the /etc/resolv.conf file:

  • The file is not a symlink on your instance.
  • The file is a symlink pointing to a different file, such as /run/systemd/resolve/resolv.conf.

To override the DNS server values, our Support Techs recommend the steps below:

1. Netplan typically stores configuration files in the /etc/netplan directory.

Here, we create the file, /etc/netplan/99-custom-dns.yaml, and then populate it with the following lines:

network:
version: 2
ethernets:
eth0: 
nameservers:
addresses: [1.2.3.4, 5.6.7.8]
dhcp4-overrides:
use-dns: false

Once done, we’ll still see the stub resolver IP in /etc/resolv.conf. We can expect this.

2. After that, we reboot the instance.

3. Then, to confirm that the system picks up the intended DNS server IP addresses correctly, we run:

systemd-resolve --status
  • RHEL 7.5

By default, the NetworkManager service manages the resolv.conf file. It will then populate the file with the DNS servers DHCP provides.

We need to stop NetworkManager from managing the resolv.conf file for it to ignore the DNS servers.

Option 1:

1. Initially, we edit or create the /etc/dhcp/dhclient.conf file.

2. Then we add the supersede command to the file to override the domain-name-servers.

For example,

supersede domain-name-servers xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx;

Once done, the resolv.conf file updates at instance reboot to contain only the DNS servers that we specify in the dhclient file.

3. After that, we set the PEERDNS parameter to yes in the per-interface configuration files.

4. Later, we reboot the instance.

Option 2:

1. Here, we create the /etc/NetworkManager/conf.d/disable-resolve.conf-managing.conf file with the following:

[main]
dns=none

2. After that, we reboot the instance, and then populate the /etc/resolv.conf file manually.

[Need help with assigning? We’d be happy to assist]

 

Conclusion

In short, we saw how our Support Techs assign Static DNS Server to the EC2 Instance.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *