How to setup static IP in Ubuntu Server 12.04?

Solution 1:

This has two independent questions:

resolv.conf entries getting reset after a reboot

The way /etc/resolv.conf working has been changed in Ubuntu 12.04. This is because of implementation of foundations-p-dns-resolving as described here https://blueprints.launchpad.net/ubuntu/+spec/foundations-p-dns-resolving to overcome some limitations of static resolv.conf.

Here you can get more details: http://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/

You can override the new feature by removing the symbolic link /etc/resolv.conf and create a file named /etc/resolv.conf there. But before doing that refer the link I given above and see why it is strongly discouraged.

IP Address Vs Network and Gateway Conflict (Setting up a static IP) Also, As pgschk pointed out, your IP address is not matching gateway and network entries. But that is not causing the /etc/resolv.conf to go to original state, but the reason I mentioned above.

Solution 2:

Your gateway address is in a different subnet than your local IP address:

address 192.168.1.150 gateway 192.168.2.1

Also, the network address was specified in the .2 subnet also:

network 192.168.2.0

Do you use the 192.168.1/24 or the 192.168.2/24 subnet?

Edit: About your resolv.conf: This file is mainly updated by different packages (depending on your setup). Try specifying the nameservers in your /etc/network/interfaces file:

dns-nameservers 8.8.8.8 8.8.4.4

Solution 3:

You can try this option :

  • Remove the /etc/resolv.conf and then creat a new resolv.conf.

  • sudo nano /etc/resolv.conf after that add the flag:

  • sudo chattr +i /etc/resolv.conf - with this +i flag, even root can't touch this file. But if you want to change the nameserver, change the flag to be:

  • sudo chattr -i /etc/resolv.conf then add your new nameserver.

Then try to reboot and see what happens :).

I hope this solves your problem.