Adding nameserver in resolv.conf

9,191

Solution 1

You can add new settings in /etc/network/interfaces

It will look like this:

  iface eth0 inet static
    address x.x.x.x
    netmask x.x.x.x
    gateway x.x.x.x
    dns-nameservers x.x.x.x

Read more from the official documentation

Solution 2

On a plain Ubuntu Desktop installation using DHCP you can open the connection editor and change the Method setting on the IPv4 Settings tab to Automatic (DHCP) addresses only. Then add the desired nameserver address in the Additional DNS servers field.

Then edit /etc/NetworkManager/NetworkManager.conf and comment out the line dns=dnsmasq.

Share:
9,191

Related videos on Youtube

chadwicke619
Author by

chadwicke619

Updated on September 18, 2022

Comments

  • chadwicke619
    chadwicke619 over 1 year

    Im using Ubuntu server edition. In that it's configured to use ip address provided by DHCP. Now, I want to edit the resolv.conf file so that it points to the nameservers that I want to define. Obviously editing the resolv.conf file directly will not work as the changes will get overwritten. I also tried a different approch to edit /etc/resolvconf/resolv.conf.d/head and adding nameserver entries there that worked for me but it is said that it is not recommended. So I want to know how can I add nameserver entries if my machine is configured to use DHCP. I believe I will have to edit /etc/network/interfaces I tried a lot of tricks but nothing seems to work. Also is this possible to add nameserver if using DHCP?

  • Atari911
    Atari911 almost 11 years
    Just to clarify, the key here is the: iface eth0 inet static
  • chadwicke619
    chadwicke619 over 10 years
    Thanks for the reply all. @Atari911: mine configuration is not static its like auto lo iface lo inet loopback dns-nameservers x.x.x.x. To use the dns server I will have to configure static ip address???
  • jdthood
    jdthood over 10 years
    @Tarun: If your interface is configured dynamically, i.e., via DHCP, then normally you don't have to enter any nameserver information manually because that information is received via DHCP. If your circumstances are exceptional then please describe those circumstances in your question. If you are using NetworkManager then you should enter nameserver information into the connection editor (e.g., in the Edit Connections | Edit... | IPv4 Settings | Additional DNS servers field) and not include any dns-nameservers options in /etc/network/interfaces.
  • chadwicke619
    chadwicke619 over 10 years
    Ya. Mine is configured to use DHCP. But how can I edit it to use the nameserver because I'm using cli mode I dont have a gnome on it.