This tutorial explains how to set a static IP on an Ubuntu system from the command line.
Step 1:
sudo nano /etc/network/interfaces
Step 2:
If DHCP has configured, you will see
auto lo eth0
iface lo inet loopback
iface eth0 inet dynamic
Step 3:
Change dynamic value to static and keep adding Values shown in Step 4
Step 4:
auto lo eth0
iface lo inet loopback
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
Step 5:
After saving the changes, Restart the Network service or Restart the OS if required
sudo /etc/init.d/networking restart
OR
Sudo shutdown -r 00