Configure Static IP Ubuntu 12.10, 12.04


For more updated information see How to Configure Network on Ubuntu

This guide is for Ubuntu 12.10 and 12.04 to configure static ip.

Step 1 Open a terminal by pressing CTRL + ALT + T and run following commands to configure static IP for eth0 interface

sudo vi /etc/network/interfaces

Step 2 Add following line to the file. Note here I am configuring eth0 ip as 192.168.1.98 and dns nameserver as google’s open dns server.

auto eth0
iface eth0 inet static
        address 192.168.1.98
        netmask 255.255.255.0
        gateway 192.168.1.1
        network 192.168.1.0
        broadcast 192.168.1.255
        dns-nameservers 8.8.8.8 8.8.2.2

Step 3 The file resolv.conf should no longer be edited manually. It is updated by the resolvconf script. To prevent resolvconf to still generate our resolv.conf file with our old dhcp settings we have to delete these two files. Run following commands

sudo rm /run/resolvconf/interface/eth0.dhclient
sudo rm /run/resolvconf/interface/original.resolvconf

Step 4 Uninstall the dhcp client otherwise it will overwrite our changes on the next renew cycle

sudo apt-get remove isc-dhcp-client

Step 5 Restart the network using following command

sudo nohup sh -c "ifdown eth0 && ifup eth0"

The result can be check with the cat command:

sudo cat nohup.out

It should look something like this:

ssh stop/waiting
ssh start/running, process 3981

Step 6 Cross verify the configuration
Step 6.1 The resolv.conf should now only contain the dns settings that we provided for our interface (eth0) check with:

sudo cat /etc/resolv.conf

The result should look like this:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.2.2

Step 6.2 Check that the correct ip address has been set:

ifconfig eth0 | grep 'inet addr'

Result:

inet addr:192.168.1.98 Bcast:192.168.1.255 Mask:255.255.255.0

Step 6.3 Check that dns lookup works:

nslookup techienote.com

Result:

Server:         8.8.8.8
Address:        8.8.8.8#53
 
Non-authoritative answer:
Name:   techienote.com
Address: 174.122.2.251

Note that address in the reply might have changed after this was written.

Step 6.4 And if we have gotten this far we have most likely set our gateway and other network parameters correctly and should also be able to reach the internet:

ping techienote.com

Result:

PING techienote.com (174.122.2.251) 56(84) bytes of data.
64 bytes from fb.2.7aae.static.theplanet.com (174.122.2.251): icmp_req=1 ttl=50 time=338 ms
64 bytes from fb.2.7aae.static.theplanet.com (174.122.2.251): icmp_req=2 ttl=50 time=339 ms
64 bytes from fb.2.7aae.static.theplanet.com (174.122.2.251): icmp_req=3 ttl=50 time=339 ms

Done

Subscribe / Share

Article by Vidyadhar

My name is Vidyadhar Sarmalkar & I work as a consultant and have done RHCE & CCNA.
Vidyadhar tagged this post with: , , , , , , , , , , , , , , , , , , , , , , , , , , , Read 270 articles by

3 Comments

  1. Thank you very much for this detailed description! It helped me a lot.

  2. Bruno says:

    It works here, Thank you!

    But, if do we want to recover the connection via dhclient? What should i do after eth0.dhclient and original.resolvconf’s deletion ? Dhclient eth0 doesn’t work anymore.

    Could you help me?

    Thank you!!!

Leave a Reply

rss twitter facbook

Categories

Archives