2

I'm having trouble getting my CentOS 5.5 EC2 instances (both i386 and x86_64) to properly populate resolv.conf after booting. No matter what I do, I end up with the default EC2 resolv.conf:

; generated by /sbin/dhclient-script
search compute-1.internal
nameserver 172.16.0.23

What I really want to do is set my own search domain and prepend two nameservers. First, I tried adding /etc/dhclient.conf:

prepend domain-name "mydomain.ec2 "
prepend domain-name-server 1.2.3.4
prepend domain-name-server 1.2.3.5

That didn't work. So I also tried placing the dhclient.conf file in /etc/dhcp/ and /etc/dhcp3. Neither worked. So I also tried creating /etc/dhclient-enter-hooks and overriding the _make_resolv_conf()_ method to prevent dhclient-script from overwriting resolv.conf:

make_resolv_conf() {
 ;
}

That had no impact either.

The only solution I have come up with is to add an extra init script that rewrites resolv.conf. That works, but I'd really like to do this the "right" way. What am I doing wrong?

organicveggie
  • 1,061
  • 3
  • 14
  • 27

5 Answers5

3

Try adding:

PEERDNS=no

To your /etc/sysconfig/network-scripts/ifcfg-eth0 (or equivalent)

If that doesn't work, you could use the chattr hack:

chattr +i /etc/resolv.conf
dmourati
  • 24,720
  • 2
  • 40
  • 69
2

Given the age of this question, I assume you found an answer; but for those who find this question looking for help: If this is inside a VPC, you need to go into the VPC console and access dhcp-options-sets (https://console.aws.amazon.com/vpc/home#s=dhcp-options-sets) and create a new dhcp options set. Make a note of the amazon id of the new options set (dopt-XXXXXXXX)

Next, go to "Your VPCs" (https://console.aws.amazon.com/vpc/home#s=vpcs), click "Change DHCP Options Set" near the top, then choose the amazon ID of your new options set.

This might help: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_DHCP_Options.html

ben
  • 191
  • 4
  • I never did get it to work and just kept using my custom init script approach. Unfortunately, it wasn't in a VPC. Now that most of our instances are in VPCs, we're using the technique you outlined. Just a strange problem. – organicveggie Aug 20 '13 at 21:58
0

This should address your issue http://www.linuxquestions.org/questions/linux-networking-3/how-to-avoid-resolv-conf-been-modified-by-dhcp-client-422431/

zedman9991
  • 166
  • 1
  • 7
0

You can also try to add following DNS entries in NIC related network scripts (e.g., /etc/sysconfig/network-scripts/ifcfg-eth0 for eth0)

DNS1=8.8.8.8 
DNS2=8.8.4.4
Abhijeet Kasurde
  • 985
  • 9
  • 20
0

This is a real simple fix. Set /etc/sysconfig/network-scripts to this: PEERDNS="no" DNS1=8.8.8.8 DNS2=8.8.4.4

This will stop the EC2 dns from inserting into the resolv.conf.