How to configure the network on Ubuntu

How to configure the network on Ubuntu

Set IP automatically via dhcp

vi /etc/network/interfaces
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
Restart network
sudo /etc/init.d/networking restart

Set static IP

vi /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.79.130
netmask 255.255.255.0
gateway 192.68.1.1

Restart network
sudo /etc/init.d/networking restart