Ubuntu – How to setup static IP in Ubuntu Server 12.04

configurationnetworkingserver

sudo apt-get update 
sudo apt-get upgrade
  1. ifconfig

  2. sudo nano /etc/network/interfaces

    auto eth0
    iface eth0 inet static
    address 192.168.1.150
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.1.255
    gateway 192.168.2.1
    safe
    
  3. sudo nano /etc/resolv.conf

    Do not edit this file by hand --your changes will be overwritten
    # I add this 
    nameserver 8.8.8.8
    nameserver 8.8.4.4
    
  4. sudo apt-get remove dhcp-client

  5. sudo /etc/init.d/networking restart

    *Running /etc/init.d/networking restart is deprecated because it may 
    not enable again some interfaces
    *Reconfiguring network interfaces...
    ssh stop/waiting
    ssh start/running,process 1438
    

Where is the mistake? I'm not lazy. I Googled it for 3 days but without results. I tried everything.

After reboot the /etc/resolv.conf file is flashing to the original state.

Best Answer

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.

Related Question