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 220.127.116.11 18.104.22.168
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 22.214.171.124 nameserver 126.96.36.199
Step 6.2 Check that the correct ip address has been set:
ifconfig eth0 | grep 'inet addr'
inet addr:192.168.1.98 Bcast:192.168.1.255 Mask:255.255.255.0
Step 6.3 Check that dns lookup works:
Server: 188.8.131.52 Address: 184.108.40.206#53 Non-authoritative answer: Name: techienote.com Address: 220.127.116.11
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 (18.104.22.168) 56(84) bytes of data. 64 bytes from fb.2.7aae.static.theplanet.com (22.214.171.124): icmp_req=1 ttl=50 time=338 ms 64 bytes from fb.2.7aae.static.theplanet.com (126.96.36.199): icmp_req=2 ttl=50 time=339 ms 64 bytes from fb.2.7aae.static.theplanet.com (188.8.131.52): icmp_req=3 ttl=50 time=339 ms