How to give a fixed IP address to an Ubuntu Machine

This step by step article explains how to give a fixed (static) IP address to an Ubuntu workstation, essentially converting it from DHCP to a static IP address. We will assume that the Ubuntu machine has only one NIC (network card) installed and its called eth0. If you had more than one and wanted to change the address on a particular one, just change the settings for that section as per below. You will need root previleges to edit the files, we will use sudo to do most commands where you will be asked to provide the root password

1. sudo nano /etc/network/interfaces
This command will bring up the interfaces file, it will have the nic (eth0) which you want to make static mentioned, the section would look like something shown below:
auto eth0
iface eth0 inet dhcp
 

2. edit the section to provide static values for IP, subnet mask, gateway, dns search order and dns name server (in order of prefrence). You can also leave the dns-search line out if you dont have a local domain
 

iface eth0 inet static
address 192.168.0.5
etmask 255.255.255.0
gateway 192.168.0.1
dns-search your_domain.com your_second_domain.com
dns-nameservers 192.168.0.101 192.168.0.102

3. You can restart the workstation to bring the changes in effect or simply restarting the networking by issuing the following command:
sudo /etc/init.d/networking restart

Your Linux Ubuntu workstation should now have a static IP. For further detailed information you can also consult the Ubuntu Network Help page at https://help.ubuntu.com/lts/serverguide/network-configuration.html