Ubuntu – Adding nameserver in resolv.conf


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?

Best Answer

  • 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