3

I have a situation where i do not give access to a machine, but there may be circumstances where the IP settings need to be changed. I have overcome this by providing a USB stick with a file with both static and DHCP info (renamed as appropriate) and a script that on reboot, checks the USB stick for a file and overwrites /etc/network/interfaces

To here, all good.

But, the file /etc/resolv.conf holds the DNS info (as far as I know) and I'm not sure how this file is structured.

What would be the best way for me to structure a file /etc/resolv.conf that could be overwritten with the above /etc/network/interfaces but with the DNS settings?

As an example, I use static IP and my /etc/resolv.conf looks like this:

    nameserver 192.168.1.254 

I have seen a demo file where this seems to be included in the /etc/network/interfaces file as follows (this is just from a search. not my file):

    iface eth0 inet static
        address 192.168.3.3
        netmask 255.255.255.0
        gateway 192.168.3.1
        dns-search example.com
        dns-nameservers 192.168.3.45 192.168.8.10

Could I put all the info in one file? If so, what then goes in the /etc/resolv.conf file?

To be honest, I'd rather have it all in the one file so it makes the end users life easier to just modify one file.

If it can be done in one file, what would be an example for DHCP (with regards to DHCP settings)

Thank you in advance for any help and suggestions!

Alaa Ali
  • 31,535
omega1
  • 165
  • 3
  • 7

1 Answers1

3

You should not edit /etc/resolv.conf in Ubuntu.

Ubuntu is using the resolvconf program that generates /etc/resolv.conf when DNS information is changed by DHCP clients, NetworkManager or ifup.

Best bet is to add

dns-nameservers 192.168.3.45 192.168.8.10

to the appropriate stanza in your /etc/network/interfaces. After making this change you normally have to ifdown and ifup the interface for the information to be pushed to resolvconf and thus to /etc/resolv.conf, but it is possible to push the info without a downup, as described in the following answer which also provides some background information that may help you.

How do I get resolvconf to regenerate resolv.conf after I change /etc/network/interfaces?

Symin
  • 1,532