how to prevent dhcp modify /etc/resolv.conf

Asked by LI Daobing


if I use following lines in /etc/network/interfaces:

auto eth0
iface eth0 inet dhcp

after each time I run "/etc/init.d/networking restart", /etc/resolv.conf is updated, which is not what I wanted, I want to use opendns instead of the dns provide by dhcp, which is bug-full.

please help me implement it, thanks.

Question information

English Edit question
Ubuntu ifupdown Edit question
No assignee Edit question
Solved by:
LI Daobing
Last query:
Last reply:
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) said :

What is your dhcp server? Could you tell the dhcp server to give out the opendns server IPs rather than the broken ones?

Revision history for this message
Best LI Daobing (lidaobing) said :

I have found the answer on just now:

Using OpenDNS with DHCP

If you assign your computer's IP with DHCP, it probably overwrites your /etc/resolv.conf. Here's how to fix that:

   1. Run: sudo gedit /etc/dhcp3/dhclient.conf
   2. Change the prepend line to read:

      prepend domain-name-servers,;

      This will prepend the OpenDNS addresses to the top of the list. (You can also use "supersede", which will just use them.) You don't have to worry about the DHCP client overwriting settings on each reboot or lease cycle, and your ISP nameservers will still be used as backup.
   3. Run: sudo /etc/init.d/networking restart
   4. Using Ubuntu? Check "Networking" to see if the changes applied correctly.
      Go to "System –> Administration –> Networking" and click the DNS tab.