First, discover which is the gateway you have to refer to by calling:
$ ip route show
This will show you something like this:
default via ip.gateway.address.something dev eth0
Now, edit
sudo nano /etc/network/interfaces with the following:
auto lo eth0
iface lo inet loopback
iface eth0 inet static
address xxx.xxx.xxx.xxx(enter your ip here)
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx(enter gateway ip here,usually the address of the router)
dns-nameservers 8.8.8.8
Finally, restart the network interface as follows:
systemctl restart ifup@eth0
and check that everything is fine by calling
ifconfig
Finally, ping google.com :)