Ubuntu: Interface IP Addressing

Interface addressing includes how to change the ip address of an interface, the default gateway and also the DNS address. You can do temporary or permanent changes. To temporarily change the ip address of an interface, use the following command

sudo ifconfig eth0 A.B.C.D netmask X.X.X.X

A.B.C.D: the new ip address
X.X.X.X: the netmask of the ip address

The example above will change the ip address and the netmask of the eth0 interface. Change eth0 from the command above to other interface based on your need. Verify the changes by using the command "sudo ifconfig eth0" If you change the ip address of an interface, chances are that you also want to configure the default gateway. To do that, use the command

sudo route add default default gw X.X.X.X eth0

X.X.X.X: the ip address of the default gateway

Verify that configuration by using the command "route". The output should display a route to your default gateway.

Next, to make a permanent changes there is a file that has to be edited. The network configuration is kept in "/etc/network/interfaces", open the file and you will see what is inside the file that would look something like this.

There are two interfaces in the example above, l0 and eth0. Now, from the example above, eth0 has been configured to use dhcp. If you want to edit an interface to use dhcp configuration, follow the configuration

auto eth0
iface eth0 inet dhcp

That are the what should be entried in the "etc/network/interfaces" file. After that, you can use the command "sudo ifup eth0" to refresh and initiate the DHCP process. But, if we want to configure the ip address and default gateway statically, edit at the appropriate interface part and add these lines

auto eth0
iface eth0 inet static

Change the ip addressing to suit your requirement.