How to set a static IP in Ubuntu from the shell

Edit

1
2
<br />
/etc/network/interfaces
<br />
/etc/network/interfaces

and adjust it to your needs (in this example setup I will use the IP address 192.168.0.100):

1
2
# This file describes the network interfaces available on your system<br />
# and how to activate them. For more information, see interfaces(5).
# This file describes the network interfaces available on your system<br />
# and how to activate them. For more information, see interfaces(5).

1
2
3
# The loopback network interface<br />
auto lo<br />
iface lo inet loopback
# The loopback network interface<br />
auto lo<br />
iface lo inet loopback

1
2
3
4
5
# This is a list of hotpluggable network interfaces.<br />
# They will be activated automatically by the hotplug subsystem.<br />
mapping hotplug<br />
script grep<br />
map eth0
# This is a list of hotpluggable network interfaces.<br />
# They will be activated automatically by the hotplug subsystem.<br />
mapping hotplug<br />
script grep<br />
map eth0

1
2
3
4
5
6
7
8
9
<br />
# The primary network interface<br />
auto eth0<br />
iface eth0 inet static<br />
address 192.168.0.100<br />
netmask 255.255.255.0<br />
network 192.168.0.0<br />
broadcast 192.168.0.255<br />
gateway 192.168.0.1
<br />
# The primary network interface<br />
auto eth0<br />
iface eth0 inet static<br />
address 192.168.0.100<br />
netmask 255.255.255.0<br />
network 192.168.0.0<br />
broadcast 192.168.0.255<br />
gateway 192.168.0.1

Then do

1
sudo /etc/init.d/networking restart
sudo /etc/init.d/networking restart

to restart the network.