To assign static ip in Ubuntu from terminal, follow this procedure:
# First open the interfaces file by using any editer of your choice, like below
$ sudo vi /etc/network/interfaces
# Now add the following lines in above file with your desired ip values
autho eth0 // Here we are creating etho
iface eth0 inet static
address 192.168.1.45 // Here choose your ip address
gateway 192.168.1.1 // Here assign your gateway ip address
netmask 255.255.255.0 // Here assign your net mask address
broadcast 192.168.1.255 // And finally here assign the broadcast address.
# Save the file and restart the network
$ /etc/init.d/networking restart
That’s it, now will be having the static ip assigned with the terminal.