As of Ubuntu 18.04 the default network stack uses something called Netplan. To see which version of Ubuntu you have, do
cat /etc/issue. If you have an older version see this article.
In order to do a Netplan configuration, follow the instructions below.
First determine your interface name with
Then edit the Netplan configuration file:
cd /etc/netplan/ ls vi 50-cloud-init-yaml
Example Netplan configuration file:
network: ethernets: eth0: dhcp4: no addresses: [192.168.0.20/24] gateway4: 192.168.0.1 nameservers: addresses: [126.96.36.199, 188.8.131.52] version: 2
`sudo netplan try`
Enter to accept changes.